Previous Topic: Tutorial 6 - Part C - Modify Request Test StepsNext Topic: Tutorial 8 - Test a Web Service


Tutorial 7 - Test an Enterprise JavaBean (EJB)

The LISA Bank application provides a full set of EJBs to interact with an account, get the user and account information from the Java interface.

This tutorial uses the Enterprise JavaBean Execution test step to call EJB methods in a test case and test the response with an assertion. You test a simple EJB to verify that the addUser and deleteUser methods work as expected.

Tutorial Tasks

In this tutorial, you:

Prerequisites

Step 1 - Create a Test Case

Follow these steps:

  1. In the Project pane, right-click the Tests folder and select Create New Test Case.
  2. Set the file name to tutorial7.
  3. Click Save.

Step 2 - Create a Configuration

You previously worked with configurations in Tutorial 2 - Data Sets.

Follow these steps:

  1. Open the project.config file.
  2. If the configuration does not contain the User and Password properties, add these properties. You do not need to set the values.
  3. Create a configuration with the name config7.
  4. Add the User property to the config7 configuration and set the value to Lisa7.
  5. Add the Password property to the config7 configuration and set the value to Pass7.

    Screenshot of config7 config file for Tutorial 7

  6. Click Save.
  7. In the Project pane, right-click the config7 configuration and select Make Active.

    The configuration now appears in purple.

Step 3 - Add an EJB Test Step

The Enterprise JavaBean Execution test step enables you to make calls on a running EJB.

Follow these steps:

  1. Click the tutorial7 tab.
  2. Click LISA--icon_image_whiteplussignbluecircle Add Step.
  3. Select Java/J2EE and select Enterprise JavaBean Execution.

    The New EJB Setup wizard appears.

    Screenshot of New EJB Setup wizard for Tutorial 7

Step 4 - Connect to the Server

The New EJB Setup wizard prompts you to specify the connection information for the EJB server.

Follow these steps:

  1. From the Select Server From List drop-down list, select JBoss 3.2/4.0.
  2. In the Host Name or IP Address field, enter localhost.
  3. Click Next.

    The list of JNDI names is retrieved from the EJB server.

Step 5 - Locate the EJB Interface

The New EJB Setup wizard prompts you to specify the name of the EJB interface.

Follow these steps:

  1. In the Remote tab, select EJB3UserControlBean/remote.

    Screenshot of New EJB Steup wizard screen for Tutorial 7

  2. Click Next.

    The Complex Object Editor opens.

    Screenshot of COE for Tutorial 7

Step 6 - Configure the EJB

Follow these steps:

  1. If you use the same EJB object repeatedly, and the Keep EJB Object Reference check box is not already selected, select the check box.
  2. Set the If environment error field to the step to execute if an exception occurs while executing this EJB step. Select Fail the Test from the list.
  3. In the Object Editor area, select the Call Sheet tab and select the addUser method.
  4. Click Icon - right arrow Add selected method to Object Call Tree.

    Screenshot for COE Call Sheet tab for Tutorial 7

    The Object Call Tree now displays the addUser method.

    Screenshot of Object Call Tree with addUser method for Tutorial 7

Important! You can only add User and Password once. To execute this tutorial more than once, change the values that are associated with User and Password.

 

Step 7 - Add an Assertion

To enter the method parameters and add an inline assertion:

  1. In the Object Call Tree pane, select Expert Mode if it is not already enabled.
  2. Select the Use Property check boxes for each argument.

    Use Property is a column heading in the Parameters area.

  3. In the Value column for arg1, select User from the Defaults list of properties.
  4. In the Value column for arg2, select Password from the Defaults list of properties.
  5. In the Status/Result area, add the inline assertion by selecting Exact and clearing the True check box.
  6. In the Comparison on Result NOT Exactly field, enter True.
  7. From the Exact drop-down, select Fail the Test.
  8. Click Execute.

    Screenshot of Object Call Tree for Tutorial 7

    The parameters to the method are displayed in the Object Call Tree, next to the Input Parameter Icon for the Complex Object Editor input parameter icon. The return value of this method is the value of the User field, "Lisa7," in the Object Call Tree.

    Screenshot of Object Call Tree with User of Lisa7 for Tutorial 7

  9. Test the addUser method again by clicking Execute.
  10. The return Icon for the Complex Object Editor return value changes to null and an error is produced because the user has already been added.

    Screenshot of Object Call Tree with error for Tutorial 7

Step 8 - Verify the Method Execution

From the LISA Bank application, you can verify that the user was added.

Follow these steps:

  1. Go to the LISA Bank application.
  2. Log in as user admin with the password admin.
  3. To confirm that Lisa7 was added, view the list of users.

    Screenshot of LISA Bank user list for Tutorial 7

Step 9 - Add Another EJB Test Step

Now try the preceding steps again to invoke the deleteUser method.

Follow these steps:

  1. Repeat the tutorial beginning with Step 3 to add an EJB step with the name DeleteUser.
  2. Use the method parameter property User.

    Screenshot of EJB step for DeleteUser for Tutorial 7

  3. Click Execute to execute this method and get results.

    Screenshot Object Call Tree for  DeleteUser for Tutorial 7

    The return Icon for the Complex Object Editor return value is true, indicating the user has been deleted.

  4. Click Save.

Tutorial 7 - Review

In this tutorial, you: