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 "Chiu, Eric T" <Er...@CIBC.ca> on 2003/02/12 00:01:42 UTC

running EJB tests on WLS

Has anyone tried the EJB tests on WLS 7.0 
http://jakarta.apache.org/cactus/howto_ejb_j2eeri.html
If you have the deployment descriptor and ConverterTest
for WLS, I would appreciate it if you can posted it to the list.

Thanks,
Eric 

I'm getting this small problem compiling...
    [javac]
C:\cactus\jakarta-cactus-13-1.4\sample-servlet\src\sample\org\apache\cactus\
sample\ejb\ConverterTest.java:32: unreported exception
javax.naming.NamingException; must be caught or declared to be thrown
    [javac]         Context ctx = new InitialContext();
    [javac]                       ^
    [javac]
C:\cactus\jakarta-cactus-13-1.4\sample-servlet\src\sample\org\apache\cactus\
sample\ejb\ConverterTest.java:34: unreported exception
javax.naming.NamingException; must be caught or declared to be thrown
    [javac]
PortableRemoteObject.narrow(ctx.lookup("java:comp/ejb/Converter"),
    [javac]                                            ^
    [javac]
C:\cactus\jakarta-cactus-13-1.4\sample-servlet\src\sample\org\apache\cactus\
sample\ejb\ConverterTest.java:36: unreported exception
java.rmi.RemoteException; must be caught or declared to be thrown
    [javac]         this.converter = home.create();
    [javac]                              ^
    [javac] 3 errors

BUILD FAILED

C:\cactus\jakarta-cactus-13-1.4\sample-servlet\build\build.xml:206: Compile
failed, messages should have been provided.

modified ConverterTest.java----------------
package org.apache.cactus.sample.ejb;

import javax.naming.*;
import javax.rmi.*;
import junit.framework.*;
import org.apache.cactus.*;

//added
import java.util.Properties;
import javax.ejb.*;


public class ConverterTest extends ServletTestCase
{
	private static final String JNDI_NAME = "ConverterHome";
	private String url;	
	private Converter converter;

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

    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 setUp() throws NamingException
    {
	String url       = "t3://localhost:7001";
    // Lookup the beans home using JNDI
    	Context ctx = getInitialContext();
    try 
    	{
	    Object home = ctx.lookup(JNDI_NAME);
	    return (ConverterHome) narrow(home, ConverterHome.class);

	} 
    catch (NamingException ne) 
    	{
	    log("The client was unable to lookup the EJBHome.  Please make
sure ");
	    log("that you have deployed the ejb with the JNDI name
"+JNDI_NAME+" on the WebLogic server at "+url);
	    throw ne;
	}
    } 
*/
//added
   private Context getInitialContext() throws NamingException 
   {
    
    try {
      // Get an InitialContext
      Properties h = new Properties();
      h.put(Context.INITIAL_CONTEXT_FACTORY,
        "weblogic.jndi.WLInitialContextFactory");
      h.put(Context.PROVIDER_URL, url);
      return new InitialContext(h);
    } catch (NamingException ne) {
      log("We were unable to get a connection to the WebLogic server at
"+url);
      log("Please make sure that the server is running.");
      throw ne;
    }
  }

    public void testConvert() throws Exception
    {
        double dollar = this.converter.convertYenToDollar(100.0);
        assertEquals("dollar", 1.0, dollar, 0.01);
    }

    //added    
    private static void log(String s) {
	    System.out.println(s);
    }
    
}