Hi,

Babu had been working on providing support for EJB testing in Cactus. Sadly,
he sent an email to me today saying that he has learnt he was not allowed to
work for open source project and thus could not contribute the code he had
almost finished writing ...

Here is what he was doing :

Writing an EjbTestCase class that :

1. EJBTestCase extends TestCase.
2. In constructor call a method(create initial context) which will allow you
to create initial context using properties read from j2ee.properties.
3. EJBTestCase has methods to create/remove session ejbs and
create/find/remove entity objects.
4. There is a helper method called lookup which will allow you to do a JNDI
lookup using JNDI name.

I had also another idea in order to try to push further the concept of unit
testing, similar to what we do for Servlet in Cactus :

* Implement a stateless Session Bean EJB redirector and have the EJBTestCase
call this redirector. This redirector will have access to container objects
such as the SessionContext objects and thus could provide this object as an
implicit object in the EJBTestCase class. So, when you write your testXXX()
method you can do something like :

MyEJBBean bean = new MyEJBBean();
bean.setContext(sessionContext);
// call the method to test
// do some asserts

* This will enable to unit test method that uses container APIs such as :
security API, accessing environment resources using JNDI, transactions, ...
* We might need to implement several rediretor: one for testing stateless
session beans, one for BMP entity beans, one for CMP entity beans, ... ?
* It is not perfect ...
* Maybe the only solution is to modify the container to support unit testing
(see the http://jakarta.apache.org/commons/cactus/goals.html page)

Thoughts ?

Thanks
Vincent

Reply via email to