![]() |
![]() ![]() |
![]() |
![]() |
![]() |
The IDE includes a facility to automatically generate a test environment for the Enterprise JavaBeans[tm]. This feature creates a web-based test client application and packages it along with the enterprise bean. You can use this test application to create an instance of the enterprise bean and to interact with it. In this section you will use this test facility to exercise the GreeterDB bean's create() and getGreeting() methods.
|
![]() |
|
|
Before deploying the test application, ensure that the application server is running and it is set as the default server in the IDE.
To deploy the test application:
1. Right-click the GreeterDB_TestApp J2EE application node and
select Deploy.
The progress of the deployment process is displayed in a dialog window.
See the new tabs in the IDE's Output window that display messages about the deployment.
2. Click the server1(localhost:port):server.log tab in the output
window.
The server.log view displays any error conditions that prevent deployment. When the deployment was successful, the output window resembles the following:
![]() |
3. On the IDE's toolbar, select the Editing tab.
The Explorer window should be displayed. If not, select View -> Explorer from the IDE's menu bar.
4. In the Explorer window, select the Runtime tab.
5. Expand the Server Registry, Installed Servers, Sun ONE Application Server 7, localhost:port, server1(localhost:port), and Deployed Applications nodes.
You should see the GreeterDB_TestApp node under the Deployed Applications node. If the GreeterDB_TestApp node is not listed, right-click on the Deployed Applications node and select Refresh List.
During the initial deployment of an application containing EJBs, the administrative server automatically generates the EJB's stubs and skeletons. Until the EJB interfaces are changed, subsequent redeployment of the application does not entail stub and skeleton generation. This smart redeployment feature greatly optimizes redeployment operations.. |
Since the test client is web-based, you need to open a web browser window to access the initial test page of the generated web application.
On the initial test clients web page, you'll invoke the create() method of the GreeterDB beans home interface to create an instance of the bean. Then you'll execute the getGreeting()business method of the bean.
To test the GreeterDB bean:
1. Start a web browser and point it to the following URL:
http://localhost:port/GreeterDB_TestApp
Where port is the HTTP server port number specified during installation. The default HTTP server port number is 80, but it may be different based on the ports in use during installation.
Your browser displays the test client.
1. Under the Runtime tab of Explorer, expand the Server Registry, Installed Servers, Sun ONE Application Server 7, localhost:port 2. Right click the server1(localhost:port) object and select Properties. 3. Read the HTTP server's port number from the Server Instance Port property. |
![]() |
From this page, you can invoke the methods of the GreeterDBHome remote
interface.
|
2. Click the Invoke button next to the create method to create an instance of the GreeterDB bean.
The create method is under the heading "Invoke Methods on samples.jdbc.simple.ejb.GreeterDBHome."
The web browser displays the new GreeterDB instance as shown below:
![]() |
Notice that the samples.jdbc.simple.ejb.GreeterDB [7] item is added in the instances list in the upper left hand portion of the page. The item represents the instance of the GreeterDB bean created by invoking the create method on the GreeterDBHome interface.
3. Click the samples.jdbc.simple.ejb.GreeterDB
[7] instance link.
This action selects the GreeterDB instance as the EJB module to test. The web browser displays the methods that can be invoked, including the getGreeting() business method.
4. Click the Invoke button next to the getGreeting method.
The getGreeting() method is called, and its return value is listed in the Results area:
![]() |
In the example above, the web browser above shows the word "evening" as the return value. Because the getGreeting() method generates a greeting based on the current time, you might see a different greeting value.
5. In the main menu bar of the IDE, select the Running tab. In the Output window, click the server1:(localhost:port): access tab.
A display of the HTTP requests and responses processed by the application server is shown:
![]() |
If you encountered problems while running your EJB, you might normally want to exercise the debugging facilities at this stage. However, for the purposes of this tutorial, we'll defer debugging exercises until we develop and deploy the combined web and EJB application.
Now that you've successfully tested your session bean, proceed to Packaging the Enterprise Bean in an EJB Module to prepare to include the EJB in an enterprise application.
![]() |
![]() |
![]() |