-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Help - JUNIT Tests do not find Hibernate Persistent Context
PostPosted: Tue Jul 14, 2009 7:20 am 
Newbie

Joined: Tue Jul 14, 2009 5:48 am
Posts: 2
We have an application with backend JBoss, Hibernate and Front End Flex.

I am trying to define my first junit test for the backend.
I get a nullPointerException when calling the PersistenceContext.

The test is found and run by maven test.

The hibernate.cfg.xml is under Disposer\disposer-backend\disposer-ejb\src\main\resources

Error:-------------------------------------------------------------------------------
Test set: de.camsystems.disposer.testServices.ProjectServiceTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.047 sec <<< FAILURE!
testFindAll(de.camsystems.disposer.testServices.ProjectServiceTest) Time elapsed: 0 sec <<< ERROR!
java.lang.NullPointerException
at de.camsystems.disposer.dao.beans.ProjectDAOBean.getAll(ProjectDAOBean.java:62)
at de.camsystems.disposer.testServices.ProjectServiceTest.testFindAll(ProjectServiceTest.java:32)


Test Code:
public class ProjectServiceTest extends TestCase {


private ProjectDAO projectDAO = new ProjectDAOBean();

/**
* Tests
*/
public void testFindAll () throws Exception {
HashSet aHashSet = new HashSet();
List<Project> projects = this.projectDAO.getAll(aHashSet);
assertNotNull(projects);
assertTrue("There should be 122 projects, found: " + projects.size(),
projects.size() == 122);
}

}

ProjectDAOBean:
/**
* Session Bean for handling Projects
*
* @author Nebojsa Milic
*
*/
@Stateless
public class ProjectDAOBean implements ProjectDAO {

private static final long serialVersionUID = 3826891945688056002L;


@PersistenceContext(unitName="Disposer")
private EntityManager entityManager;

/**
* @return list of Project objects
*
* @ejb.interface-method
*/
@SuppressWarnings("unchecked")
public List<Project> getAll (Set<SearchObject> queryArray) {

List<Project> result = null;
Session session = (Session) entityManager.getDelegate();
Criteria criteria = session.createCriteria(Project.class);
criteria = SearchEngine.generateCriteria(queryArray, criteria);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
result = (List<Project>) criteria.addOrder(Order.asc("id")).list();
return result;
}

The pom for the project:
<?xml version="1.0"?>

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>de.camsystems.disposer</groupId>
<version>1.0</version>
<artifactId>disposer</artifactId>
<packaging>pom</packaging>
<name>Disposer</name>
<description>Disposer System</description>

<modules>
<module>disposer-backend</module>
<module>disposer-frontend</module>
<module>disposer-deploy</module>
</modules>

<pluginRepositories>

<pluginRepository>
<id>flex-mojos-repository</id>
<url>http://flex-mojos.googlecode.com/svn/trunk/repository/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>



<pluginRepository>

<id>flex-mojos-googlecode-repository</id>

<url>http://svn.sonatype.org/flexmojos/repository/</url>

</pluginRepository>

<pluginRepository>
<id>epseelon-repository</id>
<url>http://m2repo.epseelon.org/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>

<pluginRepository>
<id>igenko-repository</id>
<url>http://igenko.org/archiva/repository/igenko/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>

<pluginRepository>
<id>onemore-jboss-repository</id>
<url>http://repository.jboss.com/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>

</pluginRepositories>

</project>

The POM for disposer-backend
<?xml version="1.0"?>

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>de.camsystems.disposer</groupId>
<version>1.0</version>
<artifactId>disposer-backend</artifactId>
<packaging>pom</packaging>
<name>Disposer Backend</name>

<parent>
<groupId>de.camsystems.disposer</groupId>
<version>1.0</version>
<artifactId>disposer</artifactId>
</parent>

<modules>
<module>disposer-core</module>
<module>disposer-ejb</module>
<module>disposer-service</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>

</project>

The POM for disposer-service<?xml version="1.0"?>

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>de.camsystems.disposer</groupId>
<version>1.0</version>
<artifactId>disposer-service</artifactId>
<packaging>jar</packaging>
<name>Disposer Service</name>
<description>This module contains the API and the implementation thereof for the Disposer 2008 application.</description>

<parent>
<groupId>de.camsystems.disposer</groupId>
<artifactId>disposer-backend</artifactId>
<version>1.0</version>
</parent>

<dependencies>

<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.0-318.jdbc3</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.3</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-j2ee</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>jboss</groupId>
<artifactId>jbossall-client</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>de.camsystems.disposer</groupId>
<artifactId>disposer-ejb</artifactId>
<version>1.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.