You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Ja...@transplace.com on 2004/05/24 21:36:44 UTC

Testing MDB

I have a message bean which creates a set of data in the database after
parsing the xml . In the setUp() the message is sent to this MDB. And in
the testXXX() I test to see if the records are properly created and in the
tearDown() those records created are deleted, so that the test data  in the
xml is reusable.

The problem is that when the testXXX() are being executed the MDB's method
might not have been done with the creation and so the test fails, while the
MDB did not fail at all.

Is there any suggested approach to test this MDB? Reading the archive/
documentation also did not help on how to code the above scenario. Is this
kind of testing possible or am I way off?

Also, is there any documentation on how to use the JMSRedirector?

Thanks
Jayaraman



Re: Testing MDB

Posted by "J. B. Rainsberger" <jb...@rogers.com>.
Jayaraman.Dorai@transplace.com wrote:
> I have a message bean which creates a set of data in the database after
> parsing the xml . In the setUp() the message is sent to this MDB. And in
> the testXXX() I test to see if the records are properly created and in the
> tearDown() those records created are deleted, so that the test data  in the
> xml is reusable.
> 
> The problem is that when the testXXX() are being executed the MDB's method
> might not have been done with the creation and so the test fails, while the
> MDB did not fail at all.
> 
> Is there any suggested approach to test this MDB? Reading the archive/
> documentation also did not help on how to code the above scenario. Is this
> kind of testing possible or am I way off?
> 
> Also, is there any documentation on how to use the JMSRedirector?

I don't recommend this approach.

Instead, create the appropriate Message object yourself, then simply 
invoke onMessage(). (If you need to, fake it.) Avoid sending the Message 
through the EJB container to eliminate an unnecessary layer of complexity.

Good luck.
-- 
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

RE: Testing MDB

Posted by Vincent Massol <vm...@pivolis.com>.

> -----Original Message-----
> From: Jayaraman.Dorai@transplace.com
> [mailto:Jayaraman.Dorai@transplace.com]
> Sent: 24 May 2004 21:37
> To: cactus-user@jakarta.apache.org
> Subject: Testing MDB
> 
> I have a message bean which creates a set of data in the database
after
> parsing the xml . In the setUp() the message is sent to this MDB. And
in
> the testXXX() I test to see if the records are properly created and in
the
> tearDown() those records created are deleted, so that the test data
in
> the
> xml is reusable.
> 
> The problem is that when the testXXX() are being executed the MDB's
method
> might not have been done with the creation and so the test fails,
while
> the
> MDB did not fail at all.
> 
> Is there any suggested approach to test this MDB? Reading the archive/
> documentation also did not help on how to code the above scenario. Is
this
> kind of testing possible or am I way off?

Hmm... Not easy to do. It'll be very easy to perform with Cactus2. ATM,
I would suggest not using Cactus for unit testing MDBs. Use the approach
suggested by JB, i.e. mockobjects + JUnit (the JMS API lends itself
quite nicely to this approach). I have a full chapter on unit testing
EJBs including MDBs in my JUnit in Action book if you're interested.

> 
> Also, is there any documentation on how to use the JMSRedirector?

This is work I had started some time ago but I've never finished it.
It's not in a usable state (it's in a branch in CVS somewhere).

Thanks
-Vincent