# How Do I: Test an Enterprise JavaBean?

In WebLogic Workshop you can quickly generate a JWS (web service) file with which to test controls. You can also use this to test a session or entity bean via EJB controls. The current topic describes how to generate the test JWS and how to use the test JWS to run, test, and debug the EJB.

Build and Deploy the EJB

- In the Application pane, right-click the EJB Project containing the EJB you plan to test, and select Build 'Project Name'. Ensure that the build completes successfully. The EJBs are automatically deployed on the server.
- (Optional.) Examine the generated EJB JAR to verify that the correct bean class and interfaces have been created.

- (Optional.) From the Tools menu, choose WebLogic Server-->WebLogic Console. Sign in using your user name and password. (For more general information on the WebLogic Console, see How Do I: Administer WebLogic Server Through the Administration Console?)
- (Optional.) In the WebLogic Console, select Applications from Your Deployed Resources in the Domain Configurations section. Locate the application in the table and click the Modules number. Locate the EJB JAR in the table and click its name.

Create the Built-In Control

- If you have not created a web service project in your application yet, create a new web service project. For more information, see How Do I: Create a New Project?
- Right-click the web service project and choose New-->Folder to create a new folder for your EJB control (for session and entity beans) or JSM control (for message-driven beans).
- Make sure that WebLogic Server is started. Right-click the folder and choose New-->Java Control. The New Java Control dialog appears. Select EJB control and complete the steps in the control wizard. For more information on EJB controls, see Creating a New EJB Control.

Generate the Test JWS

- In the Application pane, right-click the JCX file you just created and choose Generate Test JWS File. The test web service with a JWS extension will be created. For more information, see How Do I: Generate a JWS File to Test a Java Control?

Run the Test JWS

- Open the Test JWS file in Design View. You will notice the startTestDrive and finishTestDrive methods as well as methods of your EJB.
- Click the Start icon to run the web service. The Test View window appears.
- In Test View, click startTestDrive to begin testing. This starts the web service's conversation.
- After Test View refreshes, click the Continue this conversation link for access to test forms and buttons through which you can test each of your control's methods. After each test, click Continue this conversation to test another method.

  Note. When you test some EJB methods you might notice that although a value is returned correctly by the method, an XMLEncodingException error is thrown in the service response. These types of errors result from the return type not being Serializable, which is a prerequisite for a proper XML response. However, these errors do not affect the operations of the EJB or your ability to use the test web service to test the EJB.

- When you are finished testing, click finishTestDrive to finish testing.

Using Debugging

- You can set breakpoints in your EJB code and run the Test JWS in debugging mode. You do not need to rebuild or redeploy the EJB when you change debugging settings. For more information, see Debugging Your Application.

Making Changes

- When you make changes to the EJB, you will need to rebuild the EJB and, if you added/removed methods or changed method signatures, regenerate the test JWS. It is, however, not necessary to recreate the EJB control. When rebuilding, WebLogic Workshop will automatically redeploy the EJB.

Note. A JMS Control is not used to call a message-driven bean. Instead it is used as an alternative to message-driven bean, and is used to easily interact with messaging systems that provide a JMS implementation.

Related Topics

EJB Control

How Do I: Generate a JWS File to Test a Java Control?

How Do I: WebLogic Workshop-Enable an Existing WebLogic Server Domain?