Hi, 

I've just downloaded and installed cactus. I'm trying to use it to test my
EJBs.

I've deployed my EJBs to JRun, and created a standalone Java application to
test the EJB. The java application works fine. (I have to put the stub
classes in the classpath).

I then modify this Java application and make it an extension to TestCase.
When running it, it reports:

java.lang.ClassCastException    
        at
com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemo
teObject.java:296)      
        at
javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)    
        at test.HDAgentTest.setUp(HDAgentTest.java:48) 

If I extend the test class from ServletTestCase (as described in EJB HOWTO),
this time it reports:

javax.servlet.ServletException: Error instanciating class
[test.HDAgentTest(testHDAgent)]         
        at
org.apache.cactus.server.AbstractTestCaller.getTestClassInstance(AbstractTes
tCaller.java:311)       
        at
org.apache.cactus.server.AbstractTestCaller.doTest(AbstractTestCaller.java:1
30)     
        at
org.apache.cactus.server.AbstractTestController.handleRequest(AbstractTestCo
ntroller.java:122)      
        at
org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.
java:134)       
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

        at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1416)

        at
allaire.jrun.session.JRunSessionService.service(../session/JRunSessionServic
e.java:1082)    
        at
allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:1270)     
        at
allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDis
patcher.java:89)        
        at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1552)

        at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1542)

        at
allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:364)

        at
allaire.jrun.jrpp.ProxyEndpoint.run(../jrpp/ProxyEndpoint.java:388)     
        at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)  
        at allaire.jrun.WorkerThread.run(../WorkerThread.java:75) 

Can any one tell me why the code works as a standalone java application but
does not work as a JUnit/cactus test case?

Thanks.

Li

The Code:

public class HDAgentTest extends ServletTestCase {
  private HDAgent agent;

  public HDAgentTest(String name) {
    super(name);
  }

  public static TestSuite suite() {
    return new TestSuite(HDAgentTest.class);
  }

  public void setUp() throws Exception {
    java.util.Properties properties = new java.util.Properties();
    // Define remote properties in initial context
 
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"allaire.ejipt.Contex
tFactory");
    properties.setProperty(Context.PROVIDER_URL, "ejipt://127.0.0.1:2323");

    Context ctx = new InitialContext(properties);
    HDAgentHome home = (HDAgentHome)PortableRemoteObject.narrow(
      ctx.lookup("java:comp/env/ejb/HDAgentHome",HDAgentHome.class);
    this.agent = home.create();
  }

  public void testHDAgent() throws Exception {
    HD hd = new HD();
    hd.setA(new java.util.Date());
    hd.setB(1);
    hd.setC("ACTIVE");
    hd.setD("RR");
    hd.setE(100);
    hd.setF(20);
    if (this.agent.exists(hd)) {
      this.agent.removeHD(hd);
    }
    this.assertTrue(!this.agent.exists(hd));
    this.agent.createHD(hd);
    this.assertTrue(this.agent.exists(hd));
    this.agent.removeHD(hd);
    this.assertTrue(!this.agent.exists(hd));
  }

  // this main method is missed in EJB HOWTO
  public static void main(String[] args) {
    junit.swingui.TestRunner.main(new String[]
{HDAgentTest.class.getName()});
  }
}

Reply via email to