Create a test client (client for operation check) from the created Enterprise Beans and check the operation of each business method. This section explains how to create a test client and how to conduct the test. Here, It explains how to create an EJB test client as a Web application.
Point
If you are creating an EJB test client that is connected remotely to an EJB, create a Java application project, and in [Client type] in the EJB test client wizard, specify a client type other than "Web".
"Web" cannot be selected in [Client type] in an EJB test client if the EJB does not contain a LocalHome/Local interface.
Creating a project
From [New] wizard, select [Web] > [Dynamic Web Project] to create a Web application project for use as a test client.
Select the created Web application project, and then, in the context menu, select [Properties] > [Java Build Path] > [Projects] tab. Add the Enterprise Bean project targeted for testing.
Creating the EJB test client source
From the [New] wizard, select [EJB] > [J2EE] > [EJB Test Client], and use the wizard to create the EJB test client source.
See below for the wizard settings. Since the EJB test client is being created as a Web application in this case, select "Web" at [Client type].
Source folder
Specify the folder of source generation.
Package
Specify package name. Used in all the classes to be generated.
Name
Specify the main class name of test client.
EJB JAR file/EJB project
Specify the path or the project of EJB JAR file including the Enterprise Bean carried out for operation confirmation. The Enterprise Bean carried out for operation confirmation must have either a Home/Remote interface or a LocalHome/Local interface. The Message-driven Bean does not require an interface.
EJB Test Client Detail Information
See below.
Option | Description | |
---|---|---|
Enterprise Bean test clients | Display the list of Enterprise Bean included in EJB JAR file. According to the specification in [Client type], the Enterprise Beans displayed in the list will change. Specify with a check on the left side of the list, if the test client is generated or not for the Enterprise Bean, | |
Enterprise Bean Name | The Enterprise Bean name described in the deployment descriptor that is included in the EJB JAR file will be displayed. The Enterprise Bean list, which is displayed according to the conditions specified in [Client type], will change as shown below.
| |
Class Name | Specify the class name of test client corresponding to the Enterprise Bean In Message-driven Bean, it is not necessary to specify, since source is not generated for each Enterprise Bean. | |
lookup ID | Incase of Session Bean and Entity Bean, for acquiring the Home interface specify the lookup identifier. Specify lookup identifier for getting the destination incases of Message-driven Bean. | |
Client type | Client classification is specified. | |
EJB | Deployment descriptor is not created. Transaction management from a client etc. cannot be performed for those therefore simply call only Enterprise Bean. | |
J2EE1.3 | Deployment descriptor is not created. Transaction management from a client etc. cannot be performed for those therefore simply call only Enterprise Bean. | |
Web | Generates a Servlet class which calls the Enterprise Bean and displays the results. Selection becomes possible if the project specified in [Source folder] is a Web application. |
Point
Developing a test client requires the following classes included in the Enterprise Bean to be tested:
If [Client type] is "EJB" or "J2EE1.3".
Home interface class and remote interface class (mandatory)
If [Client type] id "Web".
Local interface class and localhome interface class (mandatory)
Common conditions
User-defined class to be passed as a parameter or return value in Enterprise Bean invocation (valid when this class is being used)
Note
EJB2.1 applications cannot be accessed from remote environment. Therefore specify [Web] in [Client type] in the EJB Test Client wizard to check the operation of the EJB2.1 application from the created Web application, via the local interface.
A test client cannot be created for an Enterprise Bean that exposed a Stateless Session Bean as a Web service.
If J2EE1.3 is selected as the client type, a J2EE1.3 format deployment descriptor is generated in the EJB test client project, but this project cannot be added to an enterprise application project.
Editing generated files
If required, edit the files generated by wizards.
The business methods expanded into the doGet method are invoked in the same order as in the analysis. For this reason, rearrange the business methods in correct order.
Check the values to be set in the method parameter.
To obtain the values of the array elements, add output processing.
Run
Deploy the EJB application to be tested and the created Web application to a J2EE execution environment where the IJServer type is [Web and EJB Applications run in the same Java VM], and launch the applications. Check the operation of the Web application from the Web browser.