DAO tests with Arquillian, class not found exception org.hibernate.ejb.HibernatePersistance
welocity Apr 17, 2013 11:56 AMHi,
I am developping a Java EE entreprise applicaiton using Netbeans 7.1, Maven2 and Glassfish3.
I created entities and DAO facades which i want to test with Arquillian. I followed the Arquillian Getting started and JPA persistance Tutorials.
I have tryied a long time with no success to make work, though it's supposed to be simple.
I could make one test with dependency injection from First tutorial but not with dependency injection.
Error message when tests ran:
Exception while preparing the app: java.lang.classNotFoundException org.hibernate.ejb.HibernatePersistance.
Here are configuration files.
If you want you can find EJB module in this link you can get EJB module from this link: https://dl.dropboxusercontent.com/u/55939918/EJB.rar
pesistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="FLAMS-PU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>flams_ds</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
//Arquillian.xml
<?xml version="1.0" encoding="UTF-8"?>
<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 qualifier="glassfish-embedded" default="true">
<configuration>
<property name="resourcesXml">
src/test/resources-glassfish-embedded/glassfish-resources.xml
</property>
</configuration>
</container>
</arquillian>
//Glassfish-resources.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC
"-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN"
"http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-resource pool-name="ArquillianEmbeddedDerbyPool"
jndi-name="jdbc/arquillian"/>
<jdbc-connection-pool name="ArquillianEmbeddedDerbyPool"
res-type="javax.sql.DataSource"
datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource"
is-isolation-level-guaranteed="false">
<property name="databaseName" value="target/databases/derby"/>
<property name="createDatabase" value="create"/>
</jdbc-connection-pool>
</resources>
//Test-persistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="test">
<jta-data-source>jdbc/arquillian</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>
Snippet from pom.xml
<dependency> | |
<groupId>junit</groupId> | |
<artifactId>junit</artifactId> | |
<version>4.10</version> | |
<scope>test</scope> | |
</dependency> | |
<!-- javaEE API--> | |
<dependency> | |
<groupId>org.jboss.spec</groupId> | |
<artifactId>jboss-javaee-6.0</artifactId> | |
<version>1.0.0.Final</version> | |
<type>pom</type> | |
<scope>provided</scope> | |
</dependency> | |
<!-- Arquillian JUnit API--> | |
<dependency> | |
<groupId>org.jboss.arquillian.junit</groupId> | |
<artifactId>arquillian-junit-container</artifactId> | |
<scope>test</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.eclipse.persistence</groupId> | |
<artifactId>eclipselink</artifactId> | |
<version>2.3.2</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.eclipse.persistence</groupId> | |
<artifactId>javax.persistence</artifactId> | |
<version>2.0.3</version> | |
<scope>provided</scope> | |
</dependency> | |
<dependency> | |
<groupId>org.eclipse.persistence</groupId> | |
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId> | |
<version>2.3.2</version> | |
<scope>provided</scope> | |
</dependency> |
<profile>
<!-- Arquillian Glassfish container adapter-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<id>arquillian-glassfish-remote</id>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-api</artifactId>
<version>1.1.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-remote-3.1</artifactId>
<version>1.0.0.CR3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/test/resources-glassfish-embedded</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemPropertyVariables>
<java.util.logging.config.file>
${project.build.testOutputDirectory}/logging.properties
</java.util.logging.config.file>
<derby.stream.error.file>
${project.build.directory}/derby.log
</derby.stream.error.file>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Snippet from DAO class:
@RunWith(Arquillian.class)
public class AlertFacadeTest {
@Deployment
public static JavaArchive createDeployment(){
return ShrinkWrap.create(JavaArchive.class)
.addClasses(Alert.class)
.addPackage(AlertFacade.class.getPackage())
.addAsManifestResource("META-INF/persistence.xml", "persistence.xml")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
public AlertFacadeTest() {
}
/**
* Test of create method, of class AlertFacade.
*/
@Test
public void testCreate() throws Exception {
System.out.println("create");
Alert entity = null;
EJBContainer container = javax.ejb.embeddable.EJBContainer.createEJBContainer();
AlertFacadeLocal instance = (AlertFacadeLocal)container.getContext().lookup("java:global/classes/AlertFacade");
instance.create(entity);
container.close();
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}