The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

sqll_rn (5) [Avatar] Offline
#1
Hello,
I am developing a J2EE application that has the following structure

JSP/Servlet ---+
\___ Stateless Session EJB ___ Hibernate ___ DB
/
Swing ---+

and I want to unit testing the Session EJB in container by using
Hibernate.

The test class is as follow:

==================================================================

public class TestGroupeBean extends ServletTestCase
{
protected static Session session;
protected static Configuration configuration;
protected static SessionFactory sf;

{
try
{
configuration = new Configuration();
configuration..[more classes here]..addClass(BDGroupe.class);
sf = configuration.buildSessionFactory();
}
catch (MappingException e)
{
e.printStackTrace();
}
catch (HibernateException e)
{
e.printStackTrace();
}
}

protected void setUp() throws Exception
{
super.setUp();
session = sf.openSession();
}

protected void tearDown() throws Exception
{
super.tearDown();
session.close();
}

public void testListerGroupePersonne() throws Exception
{
long idUser = 22;

GroupeLocalHome groupeLocalHome = (GroupeLocalHome) new InitialContext()
.lookup("GroupeLocal");
GroupeLocal groupeLocal = groupeLocalHome.create();

Map resultMap = groupeLocal.listerGroupePersonne(idUser, session);
assertNotNull(resultMap);
assertTrue(!resultMap.isEmpty());
assertTrue(resultMap.containsKey("groupes"));

Set resultSet = (Set) resultMap.get("groupes");
assertNotNull(resultSet);
assertTrue(!resultSet.isEmpty());
assertEquals(1, resultSet.size());

Object[] objects = resultSet.toArray();
Groupe groupe = (Groupe) objects[0];
assertNotNull(groupe);
assertEquals(2, groupe.getId().longValue());
assertEquals("Groupe Personne 22", groupe.getNom());
}

}


==================================================================

But this class do not work.
In fact, when I run the test, the program succeeded to map all the
classes to the database (Initializing the Configuration and the
SessionFactory) but it stops just before the setUp() method and throws
the following error:

==================================================================

[cactus] Running com.centiris.elise.metier.team.ejb.TestGroupeBean
[cactus] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 1,468 sec
[cactus] Testsuite: com.centiris.elise.metier.team.ejb.TestGroupeBean
[cactus] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 1,468 sec
[cactus] Testcase: testListerGroupePersonne(com.centiris.elise.metier.team.ejb.TestGroupeBean): Caused an ERROR
[cactus] null
[cactus] java.lang.NullPointerException
[cactus] at com.centiris.elise.metier.team.ejb.TestGroupeBean.tearDown(Unknown Source)
[cactus] at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
[cactus] at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
[cactus] at

org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
[cactus] at

org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:2

24)
[cactus] at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
[cactus] at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
[cactus] at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
[cactus] at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
[cactus] at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
[cactus] at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
[cactus] at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
[cactus] at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
[cactus] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
[cactus] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
[cactus] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
[cactus] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
[cactus] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
[cactus] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
[cactus] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
[cactus] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
[cactus] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
[cactus] at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:19smilie
[cactus] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
[cactus] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
[cactus] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
[cactus] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
[cactus] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:15smilie
[cactus] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
[cactus] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
[cactus] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
[cactus] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
[cactus] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:11smilie
[cactus] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
[cactus] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
[cactus] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
[cactus] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
[cactus] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
[cactus] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
[cactus] at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
[cactus] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
[cactus] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
[cactus] at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
[cactus] at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
[cactus] at java.lang.Thread.run(Thread.java:534)
[cactus] Shutdown message has been posted to the server.

==================================================================

I do not understand what happened. And when I tried to comment out all
the Hibernate code, the test runs normally and succeeds (of course).
So I think that the problem comes from integration of Hibernate and
Cactus. But I am not sure.
The result code when I take out Hibernate code is:

==================================================================

public class TestGroupeBean extends ServletTestCase
{
protected void setUp()
{
}

protected void tearDown() throws Exception
{
}

public void testListerGroupePersonne() throws Exception
{
assertTrue(true);
}
}

==================================================================

I am using Cactus 1.7, JBoss 3.2.6 and Hibernate 2.1.8 (and Ant 1.6.2,
MySQL 4.1).
I succeeded to test
- Hibernate + POJO
- database using Cactus and DbUnit
- Session Bean (in container) using Cactus
independently and I have used Session Bean with Hibernate (but not test).
Now I put all the things together and it does not work.

Can you explain me the cause of this error and tell me how to test
Hibernate using Cactus.

I really need it now.

Thanks a lot

Squall