Packaging EJBs for Testing

If you wish to test your deployed EJB module on the JBoss application server, package it with a test client.

To package EJB components for testing

  1. Package the EJB components application for deployment.
  2. Create a new Stateless Session Bean. In the Enterprise JavaBean Wizard, click Next to accept all defaults, then click Finish.
  3. In the EJB Class Editor, select the Fields tab, and add a new field named info. This creates a method on the EJB that can be invoked in the EJB test application.
  4. Create a library in JDeveloper for JBoss. The client side libraries from JBoss are located in the client directory under the JBoss directory, for example C:\JBoss-3.0.4\client, and are used to test an EJB deployed within JBoss.
  5. In JDeveloper,create a new Stateless Session Bean. In the Enterprise JavaBean Wizard, click Next to accept all defaults, then click Finish .
  6. In the EJB Class Editor, select the Fields tab, and add a new field named info. This creates a method on the EJB that can be invoked in the EJB test application.
  7. Create a test client for your EJB by right-clicking the EJB node in the Navigator and choosing the Create Sample Java Client context menu option.
  8. Choose Connect to Remote App Server and ignore the values for the J2EE A pplication Name and Oracle Application Server Connection Name. See Running and Testing EJB Methods.
  9. The default test client needs to be modified for use with JBoss because JNDI properties for JBoss are different from Oracle Application Server. Replace the initial environment with the following:

    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    env.put(Context.PROVIDER_URL, "localhost");
    env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );

  10. Add code to invoke the setInfo and getInfo methods previously added by the EJB Class Designer. For example, the test application is modified to invoke these methods:
     
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    env.put(Context.PROVIDER_URL, "localhost");
    env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
    Context ctx = new InitialContext(env);
    MySessionEJBHome mySessionEJBHome = (MySessionEJBHome)ctx.lookup("MySessionEJB");
    // Use one of the create() methods below to create a new instance
    MySessionEJB mySessionEJB = mySessionEJBHome.create( );
    // Call any of the Remote methods below to access the EJB
    mySessionEJB.setInfo( "Hello World" );
    System.out.println( MySessionEJB.getInfo() );        

To test the EJB in JBoss

  1. In JDeveloper, edit your project properties, remove the J2EE and Oracle Application Server libraries, and add the JBoss library to your project.
  2. Run the test client.
  3. Verify that "Hello World" is displayed in the Message Log.

For more information, see the JBoss website at www.jboss.org.


Related topics

About J2EE Deployment
About J2EE Archive Formats
About Deployment Profiles
About Deployment Descriptors
Packaging J2EE Applications
Deploying J2EE Applications
Deploying Applications to J2EE Application Servers

 

Copyright © 1997, 2004, Oracle. All rights reserved.