Previous Topic: Tutorial 3 - Filters and AssertionsNext Topic: Tutorial 5 - Run a Demo Server Web Application


Tutorial 4 - Manipulate Java Objects (POJOs)

In this tutorial, you create and manipulate a simple Java object and use the java.util.Date class to create a date object.

First, you construct the object and review how to call methods on the object. Then you incorporate the object into a simple DevTest model editor.

Tutorial Tasks

In this tutorial, you:

Prerequisites

Step 1 - Create a Test Case

To create a test case:

Step 2 - Create a Dynamic Java Execution Test Step

The Dynamic Java Execution test step lets you create a Java object from a class in the DevTest classpath. In the following procedure, you use the java.util.Date class.

Follow these steps:

  1. Click LISA--icon_image_whiteplussignbluecircle Add Step.

    The Add step menu is displayed.

  2. Select Java/J2EE and then select Dynamic Java Execution.

    The Dynamic Java Execution editor opens.

    Screenshot of Dynamic Java Execution editor for Tutorial 4

  3. In the Local JVM Settings area, ensure that Make New Object of Class is selected.
  4. In the field to the right of Make New Object of Class, type java.util.Date.
  5. Click Construct/Load Object.

    The Complex Object Constructor wizard appears. The first step shows the available constructors.

  6. Select the Date( java.lang.Long ) constructor.

    Screenshot of Complex Object Constructor

  7. Click Next.
  8. Click Finish.

    The Complex Object Editor opens.

    Screenshot of COE for Tutorial 4

    Now you have a Java object to manipulate in the Complex Object Editor.

Step 3 - Make a Call on the Java Object

The Complex Object Editor is divided into two panels. The left panel contains the Object Call Tree, which tracks method invocations and their input parameters and return values. The following icons are used to identify the branches in the object call tree:

Icon for the Complex Object Editor type The type (class) of the currently loaded object, followed by the response from calling the 'toString' method of the object.

Icon for the Complex Object Editor constructor The Constructor that was called. This icon is shown if multiple constructors exist.

Icon for the Complex Object Editor non-executed method call A method call that has not been executed.

Icon for the executed method call A method call that has been executed.

Icon for the Complex Object Editor input parameter The input parameters (type and current value) for the enclosing method.

Icon for the Complex Object Editor return value The return value (current value if the call has been executed) for the enclosing method.

The contents of the right panel vary depending on what is selected in the left panel.

To call the Java object:

  1. In the right panel of the Complex Object Editor, click the Call Sheet tab.

    The Call Sheet tab shows the available methods that you can call.

  2. Double-click the setYear() method. Or, you can select the setYear() method and click Icon - right arrow Add selected method to Object Call Tree.

    Screenshot of the Call Sheet tab for the Dynamic Java Execution step.

    The setYear() method is added to the Object Call Tree. The right panel now displays the Call tab and Docs tab.

    The Call tab lists the argument information.

  3. In the Value field for arg1, enter 104.
  4. Click Execute.

    Screenshot of Dynamic Java  Execution step COE Call Tree tab for Tutorial 4

  5. In the Object Call Tree, select the java.util.Date object.
  6. In the Data Sheet tab, verify that the year field is now set to 104.

    Screenshot of Dynamic Java  Execution step COE Data Sheet tab for Tutorial 4

Step 4 - Add an Inline Filter

You can add an inline filter from the Complex Object Editor. Inline filters (and assertions) do not result in a filter being added to the test step in the elements panel. Inline filter management is always done in the Complex Object Editor.

Follow these steps:

  1. With the java.util.Date object selected, click the Call Sheet tab.
  2. To retrieve the date to be placed in a property, invoke the toString() method.

    The right panel now displays the Call tab and Docs tab.

  3. To add an inline filter, enter Date_prop as the property name in the Save Result in Property field in the Status/Result area on the Call tab.

    Screenshot of COE Call tab for Tutorial 4

  4. Click Execute.
  5. Click Main Toolbar Save icon Save.

Step 5 - Verify the Property Created

You can display the Property Window to verify that the Date_prop property was created.

Follow these steps:

  1. Click Model properties icon Show model properties on the test case toolbar. Or, you can select Help, View Properties from the main menu.
  2. Click Refresh Icon - arrows in a circle.
  3. Locate the Date_prop property.

    Screenshot of Property window for Tutorial 4

  4. Click Close.

Tutorial 4 - Review

In this tutorial, you: