You can create your own client that accesses the enterprise beans, but the IDE also includes a mechanism for testing enterprise beans without having to manually create a client test application. This feature creates a test application and packages it along with the enterprise bean. You can use this test application to create an instance of the enterprise bean and interact with it.
Testing a session bean follows these steps:
To create the test client:
Right-click on the session bean logical node and choose Create New EJB Test Application. The EJB Test Application wizard appears. Accept all default values and click the OK button.
A progress monitor appears briefly and then goes away when the process is complete. Another window appears informing you that the web module that was created is also visible in the Project tab. It should go away automatically also. If not, click OK to close the window.
The IDE has created an EJB module named session_bean_name_EJBModule
, a web module named session_bean_name_WebModule
, and a J2EE application named session_bean_name_TestApp
in the ejb
subdirectory. The EJB module contains the session bean, which is to be tested. The web module contains a number of JSP pages and Java class files that support the test client. The J2EE application includes references to the EJB module and to the web module. In addition, the IDE mounts the web module.
NOTE - The EJB module, web module, and J2EE application generated by the IDE are not intended to be modified. If you modify them you might not be able to redeploy the J2EE application.
Deployment is the process of compiling the source files that make up a J2EE application and installing the compiled files into directories managed by a J2EE application server.
NOTE - Make sure that the Sun ONE Application Server instance is set as the default server and is running.
To deploy the test application:
_TestApp
J2EE application node and choose Deploy.As the deployment progresses, you see a progress bar window showing you what phase the deployment is in. See the new tabs in the IDE's Output window that display messages about the deployment.
Click the server1(localhost:port):server.log
tab in the Output window.
The server.log
view displays any error conditions that prevent deployment.
Click the Editing tab and then click the Explorer's Runtime tab. Expand the Server Registry ->
Installed Servers -> Sun ONE Application Server 7 ->
default_server ->
server_instance -> Deployed Applications
nodes.
You should see the session_bean_name_TestApp
node under the Deployed Applications node. If the session_bean_name_TestApp
node is not listed, right-click on the Deployed Applications node and choose Refresh List.
Point your web browser to the test page to start the application. On the test client's web page that is displayed, use the create method of the session bean's home interface to create an instance of the bean. Then test a business method on that instance.
To test the session bean:
http://localhost:80/
session_bean_name_TestApp
Note - Port 80 is the default port Sun ONE Application Server runs on. If you need to verify that this is the correct port, pointing your browser to http://localhost:80/ should display the welcome page of the HTTP server.
Your browser displays the test client.
From this page, you can invoke the methods of the session_bean_nameHome
remote interface.
The create method is under the heading "Invoke Methods on package.session_bean_nameHome
."
The web browser will now display the new session bean instance as shown below:
The instance of the session bean created by invoking the create method on the session_bean_nameHome
interface is added in the instances list.
This action selects the instance as the EJB module to test. The web browser now displays the methods that can be invoked, including the bean's business method.
The business method is called, and its return value is listed in the Results area:
The access view displays the browser accesses recorded in the access log like this: