Combining Persistence Extension with Liquibase?
lexsoto Nov 29, 2014 1:11 PMHello:
I am trying to test my persistence layer using Arquillian, Arquillian Persistence Extension 1.0.0.Alpha7, WildFly 8.1.0.Final, H2, Liquibase, and DBUnit.
I would like the schema to be created by LiquiBase, then load sample data using the @UsingDataSet and @ShouldMatchDataSet annotations.
So far, the deployment works correctly, and Liquibase runs fine creating the database schema, however when the unit test runs, the tables are not found.
Anybody ever attempted this?
My application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd"
version="7">
<module>
<web>
<web-uri>test.war</web-uri>
<context-root>/test</context-root>
</web>
</module>
<module>
<ejb>test.jar</ejb>
</module>
<data-source>
<name>java:/hoverla/datasources/enterprise</name>
<class-name>org.h2.jdbcx.JdbcDataSource</class-name>
<url>jdbc:h2:mem:hoverla;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</url>
</data-source>
</application>
Persistence.xml:
<persistence-unit name="default" transaction-type="JTA">
<jta-data-source>java:/hoverla/datasources/enterprise</jta-data-source>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="none" />
<property name="hibernate.show_sql" value = "true"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
<!--
Very unfortunate workaround to get the data source to work with JPA in WildFly 8.
See https://issues.jboss.org/browse/WFLY-2727
-->
<property name="wildfly.jpa.twophasebootstrap" value="false" />
</properties>
</persistence-unit>
Test class:
@RunWith(Arquillian.class) public class CompanyServiceTest { @Deployment public static EnterpriseArchive deployment() { File[] liquibaseJars = Maven.resolver() .loadPomFromFile("pom.xml") .resolve("org.liquibase:liquibase-cdi", "com.mattbertolini:liquibase-slf4j") .withTransitivity().asFile(); JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "test.jar") .addPackages(true, "com.hoverla.data.entity") .addPackages(true, "com.hoverla.data.service.company") .addPackages(true, "com.hoverla.test.data.liquibase") .addAsResource("liquibase") .addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); // Web module is needed to prevent Arquillian generating an illegal application.xml // Add the the class containing the test WebArchive war = create(WebArchive.class, "test.war") .addClass(CompanyServiceTest.class) .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); File h2Jars = Maven.resolver().loadPomFromFile("pom.xml") .resolve("com.h2database:h2") .withoutTransitivity() .asSingleFile(); EnterpriseArchive result = ShrinkWrap.create(EnterpriseArchive.class, "test.ear") .addAsModule(war) .addAsModule(ejbJar) .setApplicationXML("application.xml") .addAsLibraries(liquibaseJars) .addAsLibraries(h2Jars); System.out.println(war.toString(true)); System.out.println(result.toString(true)); return result; } @EJB private CompanyService svc; /** * Test of withdraw method, of class AccountSessionBean. */ @Test @ShouldMatchDataSet(value = "company/pepe.yml", excludeColumns = {"id", "created_date", "created_by"}) public void createCompany() { Company company = svc.create("Pepe"); assertNotNull(company); assertEquals("Pepe", company.getName()); assertNotNull(svc.getCompany(company.getId())); }
WildFly Log shows this:
12:48:58,126 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "test.ear" (runtime-name: "test.ear")
12:48:58,650 WARN [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015960: Class Path entry lib/snakeyaml-1.13.jar in /content/test.ear/lib/liquibase-core-3.1.1.jar does not point to a valid jar for a Class-Path reference.
12:48:58,657 INFO [org.jboss.as.server.deployment] (MSC service thread 1-11) JBAS015973: Starting subdeployment (runtime-name: "test.war")
12:48:58,657 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015973: Starting subdeployment (runtime-name: "test.jar")
12:48:58,831 INFO [org.jboss.as.jpa] (MSC service thread 1-6) JBAS011401: Read persistence.xml for default
12:48:58,925 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016002: Processing weld deployment test.ear
12:48:58,999 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-1) HV000001: Hibernate Validator 5.1.0.Final
12:48:59,131 INFO [org.jboss.weld.deployer] (MSC service thread 1-13) JBAS016002: Processing weld deployment test.war
12:48:59,133 INFO [org.jboss.weld.deployer] (MSC service thread 1-12) JBAS016002: Processing weld deployment test.jar
12:48:59,138 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-12) JNDI bindings for session bean named CompanyServiceImpl in deployment unit subdeployment "test.jar" of deployment "test.ear" are as follows:
java:global/test/test.jar/CompanyServiceImpl!com.hoverla.data.service.company.CompanyService
java:app/test.jar/CompanyServiceImpl!com.hoverla.data.service.company.CompanyService
java:module/CompanyServiceImpl!com.hoverla.data.service.company.CompanyService
java:global/test/test.jar/CompanyServiceImpl
java:app/test.jar/CompanyServiceImpl
java:module/CompanyServiceImpl
12:48:59,168 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-14) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4)
12:48:59,168 INFO [org.jboss.weld.deployer] (MSC service thread 1-14) JBAS016005: Starting Services for CDI deployment: test.ear
12:48:59,198 INFO [org.jboss.weld.Version] (MSC service thread 1-14) WELD-000900: 2.1.2 (Final)
12:48:59,208 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) JBAS010417: Started Driver service with driver-name = test.ear_org.h2.Driver_1_4
12:48:59,208 INFO [org.jboss.weld.deployer] (MSC service thread 1-11) JBAS016008: Starting weld service for deployment test.ear
12:48:59,217 WARN [org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService$AS7DataSourceDeployer] (MSC service thread 1-2) IJ020016: Missing <recovery> element. XA recovery disabled for: java:/hoverla/datasources/enterprise
12:48:59,217 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-12) JBAS010400: Bound data source [java:/hoverla/datasources/enterprise]
12:48:59,363 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 50) JBAS011402: Starting Persistence Unit Service 'test.ear/test.jar#default'
12:48:59,421 INFO [org.hibernate.Version] (ServerService Thread Pool -- 50) HHH000412: Hibernate Core {4.3.5.Final}
12:48:59,423 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 50) HHH000206: hibernate.properties not found
12:48:59,424 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 50) HHH000021: Bytecode provider name : javassist
12:48:59,716 INFO [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 50) HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
12:48:59,886 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 50) HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
12:49:00,028 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 50) HHH000397: Using ASTQueryTranslatorFactory
12:49:00,913 WARN [org.jboss.weld.Validator] (weld-worker-5) WELD-001473: javax.enterprise.inject.spi.Bean implementation liquibase.integration.cdi.CDIBootstrap$1@6a44dd76 declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
12:49:01,061 INFO [liquibase.integration.cdi.CDILiquibase] (MSC service thread 1-10) Booting Liquibase 3.1.1
12:49:01,281 INFO [liquibase] (MSC service thread 1-10) Successfully acquired change log lock
12:49:01,691 INFO [liquibase] (MSC service thread 1-10) Creating database history table with name: PUBLIC.DATABASECHANGELOG
12:49:01,712 INFO [liquibase] (MSC service thread 1-10) Reading from PUBLIC.DATABASECHANGELOG
12:49:01,714 INFO [liquibase] (MSC service thread 1-10) liquibase/initial.xml: create-address::alex.soto: Reading from PUBLIC.DATABASECHANGELOG
12:49:01,733 INFO [liquibase] (MSC service thread 1-10) liquibase/initial.xml: create-company::alex.soto: Table COMPANY created
12:49:01,768 INFO [liquibase] (MSC service thread 1-10) Successfully released change log lock
12:49:01,965 INFO [org.wildfly.extension.undertow] (MSC service thread 1-15) JBAS017534: Registered web context: /test
12:49:01,995 INFO [org.jboss.as.server] (management-handler-thread - 1) JBAS018559: Deployed "test.ear" (runtime-name : "test.ear")
12:49:03,036 INFO [stdout] (default task-2) Hibernate: insert into COMPANY (id, created_by, deleted_date, deleted, deleted_by, updated_by, billing_address_id, mailing_address_id, name) values (null, ?, ?, ?, ?, ?, ?, ?, ?)
12:49:03,053 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-2) SQL Error: 42102, SQLState: 42S02
12:49:03,053 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-2) Table "COMPANY" not found; SQL statement:
Any ideas about what I am doing wrong?