Re: EJB3 Testing

Johannes Harms <[email protected]> Tue, 20 May 2008 23:39:26 +0200
Newsgroups gmane.comp.jakarta.cactus.user
Message-ID <[email protected]>
1.) Can Cactus be used within an EJB3 / Java Enterprise 5 Environment?

I guess, the answer given in the mailing list is also true for me,  
right?
[quote Petar Tahchiev]:  First no, Cactus currently does not support  
J2EE 1.5.
http://www.mail-archive.com/[email protected]/msg07439.html

But then, does this mean Cactus is of no use for me?  I would not mind  
if Cactus is unable to start and stop Glassfish, or to undeploy and  
deploy my application, I can do this myself. I would be happy to have  
Cactus run inside my Glassfish container, and I could then run the  
tests by hand using my webbrowser.

To demonstrate this possibility, I wrote a sample application using
http://jakarta.apache.org/cactus/writing/howto_ejb_j2eeri.html and
http://jakarta.apache.org/cactus/integration/integration_browser.html
as guidelines. I can now call http://localhost:8080/Sukkulent-war/ServletTestRunner?suite=sukkulent.web.MyTestsuite&xsl=cactus-report.xsl 
  and I get a nice report.


2.) How can my Cactus TestSuite get a reference to an EJB3 Session bean?

Even though I am happy to have the above mentionned sample application  
running, I am still having difficulties. The one thing that is not  
working is this: My Cactus Testcase cannot reference my EJBs. The  
usual @EJB injection simply does not work...

public class MyTestsuite extends ServletTestCase {
     private MySessionBeanLocal mysessionbean;
     // ...
     @Override
     public void setUp() {
         // TODO: How can I get a reference to my EJB Session Bean?
     }

     public void testXXX() throws Exception {
         assertNotNull(mysessionbean);
     }
}

How can my Cactus Testcase get a reference to MySessionBean? I would  
preferably use the local interface since the rest of my application  
does not need remote interfaces... Please help!






On 19.05.2008, at 22:32, Johannes Harms wrote:

> Could you help me to find out if Cactus is right for me?
>
> (I am sorry if my questions seem stupid, please don't be offended! I  
> am new to Cactus and relatively new to the Java Enterprise World. I  
> did search through the mailing lists and I have read some of the  
> documentation..)
>
> 1.) Does Cactus support EJB3 testing?
> Can I run Cactus Tests inside the Glassfish server to test my EJBs?
> Can I use the annotation-based Java Enterprise Dependency Injection  
> to get references to my EJBs? E.g could I inject @EJB private EJB  
> myEJB; into my Cactus test case? Although not necessary (I could use  
> JNDI instead to lookup the EJB), it would be very convenient.
>
> 2.) Given my situation, would you recommend Cactus?
> For our project, we are using Glassfish, EJB3 and JSF to provide a  
> webbased interface for database-driven application. I am looking for  
> a solution to testing our EJB business logic (mainly EJB3 Entity  
> Beans and stateless Session Beans). Because the business logic EJBs  
> make use of dependency injection (injection of other EJBs, of the  
> PersistenceContext and the SessionContext), I would prefer the tests  
> to run in the EJB component's natural environment instead of a  
> mocked test environment. This is how I came to search for in- 
> Container testing strategies and found the Cactus Project...
>
> thank you and with kind regards,
> Johannes (from Austria)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]