Howto add a postgreSQL datasource to a arquillian wildfly embedded container?
bookwood Jul 24, 2017 4:43 PMWhen I use the default ExampleDS all my test works fine. Now I want to change the embedded h2 database to a PostgreSQL datasource and got a
DeploymentException: Cannot deploy: test.war
Error. When the Wildfly Server with a defined PostgreSQL datasource runs in Eclipse, I got the following in the console:
19:16:49,732 INFO [org.jboss.weld.deployer] (MSC service thread 1-4) WFLYWELD0003: Processing weld deployment test.war
19:16:49,761 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 15) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "test.war")]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jboss.datasources.PostgresDS"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.persistenceunit.\"test.war#TestLoricaDS\" is missing [jboss.naming.context.java.jboss.datasources.PostgresDS]",
"jboss.persistenceunit.\"test.war#TestLoricaDS\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jboss.datasources.PostgresDS]"
]
}
Is there a preferred way to add an other database to the arquillian wildfly embedded container? The documentation is incomplete in this case. I found only unanswered questions of my problem or workarounds that not work.
Here is my test class:
package de.ifasec.model; import javax.inject.Inject; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(Arquillian.class) public class TalkTest { @Deployment public static Archive<?> createDeployment() { // WebArchive war = ShrinkWrap.create(WebArchive.class) // .addClass(Talk.class) // .addAsResource("META-INF/persistence.xml", "persistence.xml") // .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); // or jar packaging... JavaArchive jar = ShrinkWrap.create(JavaArchive.class) .addPackage(Talk.class.getPackage()) //.addAsManifestResource("META-INF/persistence.xml", "persistence.xml") .addAsManifestResource("persistence-test.xml", "persistence.xml") .addAsManifestResource("wildfly-ds.xml") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); return jar; } @PersistenceContext(unitName="TestLoricaDS") EntityManager em; @Inject private Talk talk; @Test public void should_be_deployed() { Assert.assertNotNull(talk); } }
and my persistence-test.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="TestLoricaDS" transaction-type="JTA"> <description>Forge Persistence Unit</description> <provider>org.hibernate.ejb.HibernatePersistence</provider> <!-- The commented tag works (the internal database --> <!-- <jta-data-source>java:/jboss/datasources/ExampleDS</jta-data-source> --> <jta-data-source>java:jboss/datasources/PostgresDS</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="hibernate.transaction.flush_before_completion" value="true"/> </properties> </persistence-unit> </persistence>
and my wildfly-ds.xml
<?xml version="1.0" encoding="UTF-8"?> <datasources xmlns="http://www.jboss.org/ironjacamar/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd"> <datasource enabled="true" jndi-name="java:/jdbc/PostgresTestDS" pool-name="PostgresDS"> <connection-url>jdbc:postgresql://10.20.1.4:2345/test</connection-url> <driver>postgres</driver> <pool> <min-pool-size>4</min-pool-size> <initial-pool-size>4</initial-pool-size> <max-pool-size>64</max-pool-size> </pool> <security> <user-name>test</user-name> <password>test</password> </security> </datasource> </datasources>
and my arquillian.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> <container default="true" qualifier="arquillian-wildfly-embedded"> <configuration> <property name="chameleonTarget">${chameleon.target}</property> <!-- <property name="serverConfig">standalone-psql.xml</property> --> <!-- The upper serverConfig produces --> <!-- LifecycleException: --> <!-- Could not invoke start on: org.wildfly.core.embedded.EmbeddedManagedProcessImpl@40238dd0 --> <property name="outputToConsole">true</property> </configuration> </container> <extension qualifier="persistence"> <property name="defaultDataSource">java:jboss/datasources/PostgresDS</property> </extension> </arquillian>
The maven pom
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>de.ifasec</groupId> <artifactId>jpa-test</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>war</packaging> <build> <finalName>jpaTest</finalName> </build> <properties> <failOnMissingWebXml>false</failOnMissingWebXml> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <version.arquillian_universe>1.1.13.0</version.arquillian_universe> <version.junit>4.12</version.junit> </properties> <profiles> <profile> <id>arquillian-wildfly-embedded</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.14.1</version> <configuration> <systemPropertyVariables> <arquillian.launch>arquillian-wildfly-embedded</arquillian.launch> <chameleon.target>wildfly:10.1.0.Final:EMBEDDED</chameleon.target> <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> <!-- <jboss.home>${project.build.directory}/${wildfly.test.embedded.folder}</jboss.home> --> <!-- <jboss.server.default.config>standalone-psql.xml</jboss.server.default.config> --> </systemPropertyVariables> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>org.jboss.logmanager</groupId> <artifactId>jboss-logmanager</artifactId> <version>2.0.7.Final</version> <scope>test</scope> </dependency> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.1.3</version> <scope>test</scope> </dependency> </dependencies> </profile> <profile> <id>arquillian-wildfly-remote</id> <build> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.14.1</version> <configuration> <systemPropertyVariables> <arquillian.launch>arquillian-wildfly-remote</arquillian.launch> <chameleon.target>wildfly:10.1.0.Final:REMOTE</chameleon.target> </systemPropertyVariables> </configuration> </plugin> </plugins> </build> </profile> <profile> <id>JETTY_EMBEDDED_7.X_AND_8.X</id> <dependencies> <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-jetty-embedded-7</artifactId> <version>1.0.0.CR3</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-webapp</artifactId> <version>9.4.6.v20170531</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-plus</artifactId> <version>9.4.6.v20170531</version> </dependency> </dependencies> </profile> </profiles> <dependencies> <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.0-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.arquillian.universe</groupId> <artifactId>arquillian-junit</artifactId> <type>pom</type> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${version.junit}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.arquillian.universe</groupId> <artifactId>arquillian-chameleon</artifactId> <type>pom</type> <scope>test</scope> </dependency> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-persistence-dbunit</artifactId> <version>1.0.0.Alpha7</version> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.spec</groupId> <artifactId>jboss-javaee-6.0</artifactId> <version>3.0.3.Final</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.arquillian</groupId> <artifactId>arquillian-universe</artifactId> <version>${version.arquillian_universe}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>
I generated the test project with jboss forge.
Thanks in advance!