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 kendo <ke...@yahoo.com> on 2002/09/26 16:32:25 UTC

testing ejb's with cactus

Hi all

 

I have recently downloaded cactus to use for testing ejb's, however from working with junit  I know the setup method should be called before each test method etc. But when using cactus and following your example on the apache site, it seems that the setup method is not called at all but the test methods are.  Also I can test the ejb using junit by itself and this works but rather than extending ServletTestCase, i extend the general TestCase.

However with extending ServletTestCase

I always get connection refused from the container(which happens to be OC4J)

 

 

1) can you inform me on the proceedure is for testing ejb's with cactus because I have looked the apache site and followed the example :

 

package org.apache.cactus.sample.ejb; 

 

import javax.ejb.*; 

 

public class ConverterEJB implements SessionBean 

{ 

private SessionContext context; 

 

public double convertYenToDollar(double theYenAmount) 

{ 

return theYenAmount / 100.0; 

} 

 

public ConverterEJB() 

{ 

} 

 

public void ejbCreate() throws CreateException 

{ 

} 

 

public void setSessionContext(SessionContext theContext) 

{ 

this.context = theContext; 

} 

 

public void ejbActivate() 

{ 

} 

 

public void ejbPassivate() 

{ 

} 

 

public void ejbRemove() 

{ 

} 

} 

and added the test with main to call the 

junit.textui.TestRunner.run(suite()), however, this does not seem

to work. 

test example:

package org.apache.cactus.sample.ejb; 

 

import javax.naming.*; 

import javax.rmi.*; 

import junit.framework.*; 

 

import org.apache.cactus.*; 

 

public class ConverterTest extends ServletTestCase 

{ 

private Converter converter; 

 

public ConverterTest(String name) 

{ 

super(name); 

} 

 //added this method to call on the cmd line

 //acting as a client

 public static void main(String []args){
      junit.textui.TestRunner.run(suite());
      
    } 

public static Test suite() 

{ 

return new TestSuite(ConverterTest.class); 

} 

 

public void setUp() 

{ 

Context ctx = new InitialContext(); 

ConverterHome home = (ConverterHome) 

PortableRemoteObject.narrow(ctx.lookup("java:comp/ejb/Converter"), 

ConverterHome.class); 

this.converter = home.create(); 

} 

 

public void testConvert() throws Exception 

{ 

double dollar = this.converter.convertYenToDollar(100.0); 

assertEquals("dollar", 1.0, dollar, 0.01); 

} 

} 

 

Can anyone let me know to go about testing ejb's with cactus 

 Many thanks for your help or advice in advance

 

Kendo



---------------------------------
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!

RE: testing ejb's with cactus

Posted by Vincent Massol <vm...@octo.com>.
Hi Kendo,

> -----Original Message-----
> From: kendo [mailto:kencactus@yahoo.com]
> Sent: 26 September 2002 15:32
> To: cactus usergroup
> Subject: testing ejb's with cactus
> 
> 
> Hi all
> 
> 
> 
> I have recently downloaded cactus to use for testing ejb's, however
from
> working with junit  I know the setup method should be called before
each
> test method etc. But when using cactus and following your example on
the
> apache site, it seems that the setup method is not called at all but
the
> test methods are.  

This is not supposed to happen and there are tests in the cactus test
suite to ensure the setUp()/tearDown() methods are called before and
after each test. They are called on the server side though.

> Also I can test the ejb using junit by itself and this
> works but rather than extending ServletTestCase, i extend the general
> TestCase.
> 
> However with extending ServletTestCase
> 
> I always get connection refused from the container(which happens to be
> OC4J)
> 

You need to provide us with more details (the stack trace you get would
be useful to start with).

> 
> 
> 
> 
> 1) can you inform me on the proceedure is for testing ejb's with
cactus
> because I have looked the apache site and followed the example :
> 

[snip]

> 
> Can anyone let me know to go about testing ejb's with cactus
> 
>  Many thanks for your help or advice in advance
> 

You need to tell us what problem you are getting before we can help.
Please provide us with stack traces.

-Vincent


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>