Skip Headers
Oracle® Fusion Middleware Developer's Guide for Oracle SOA Suite
11g Release 1 (11.1.1.7)

Part Number E10224-20
Go to Documentation Home
Home
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

44 Automating Testing of SOA Composite Applications

This chapter describes how to create, deploy, and run test cases that automate the testing of SOA composite applications. You can also create test cases for testing BPEL process service components included in the SOA composite application. Test cases enable you to simulate the interaction between a SOA composite application and its web service partners before deployment in a production environment. This helps to ensure that a process interacts with web service partners as expected when it is ready for deployment to a production environment.

This chapter includes the following sections:

44.1 Introduction to the Composite Test Framework

Oracle SOA Suite provides an automated test suite framework for creating and running repeatable tests on a SOA composite application.

The test suite framework provides the following features:

44.1.1 Test Cases Overview

The test framework supports testing at the SOA composite application level. In this type of testing, wires, service binding components, service components (such as BPEL processes and Oracle Mediator service components), and reference binding components are tested.

For more information, see Section 44.3, "Creating Test Suites and Test Cases."

44.1.2 Overview of Test Suites

Test suites consist of a logical collection of one or more test cases. Each test case contains a set of commands to perform as the test instance is executed. The execution of a test suite is known as a test run. Each test corresponds to a single SOA composite application instance.

For more information, see the following:

44.1.3 Overview of Emulations

Emulations enable you to simulate the behavior of the following components with which your SOA composite application interacts during execution:

  • Internal service components inside the composite

  • Binding components outside the composite

Instead of invoking another service component or binding component, you can specify a response from the component or reference.

For more information, see the following:

44.1.4 Overview of Assertions

Assertions enable you to verify variable data or process flow. You can perform the following types of assertions:

  • Entire XML document assertions:

    Compare the element values of an entire XML document to the expected element values. For example, compare the exact contents of an entire loan request XML document to another document. The XMLTestCase class in the XMLUnit package includes a collection of methods for performing assertions between XML files. For more information about these methods, visit the following URL:

    http://xmlunit.sourceforge.net
    
  • Part section of message assertions:

    Compare the values of a part section of a message to the expected values. An example is a payload part of an entire XML document message.

  • Nonleaf element assertions:

    Compare the values of an XML fragment to the expected values. An example is a loan application, which includes leaf elements SSN, email, customerName, and loanAmount.

  • Leaf element assertions:

    Compare the value of a selected string or number element or a regular expression pattern to an expected value. An example is the SSN of a loan application.

For more information about asserts, see Section 44.2.3, "Assertions."

44.2 Introduction to the Components of a Test Suite

This section describes and provides examples of the test components that comprise a test case. Methods for creating and importing these tests into your process are described in subsequent sections of this chapter.

44.2.1 Process Initiation

You first define the operation of your process in a binding component service such as a SOAP web service. Example 44-1 defines the operation of initiate to initiate the TestFwk SOA composite application. The initiation payload is also defined in this section:

Example 44-1 Process Initiation

<?xml version="1.0" encoding="UTF-8" ?>
<!-- Generated by Oracle SCA Test Modeler version 1.0 at [6/13/07 10:50 AM]. -->
<compositeTest compositeDN="TestFwk"
 xmlns="http://xmlns.oracle.com/sca/2006/test">
  <about></about>
  <initiate serviceName="client" operation="initiate" isAsync="true">
    <message>
      <part partName="payload">
        <content>
          <loanApplication xmlns="http://www.autoloan.com/ns/autoloan">
            <SSN>111222333</SSN>
            <email>joe.smith@example.com</email>
            <customerName>Joe Smith</customerName>
            <loanAmount>20000</loanAmount>
            <carModel>Camry</carModel>
            <carYear>2007</carYear>
            <creditRating>800</creditRating>
          </loanApplication>
        </content>
      </part>
    </message>
  </initiate>
</compositeTest>

44.2.2 Emulations

You create emulations to simulate the message data that your SOA composite application receives from web service partners.

In the test code in Example 44-2, the loan request is initiated with an error. A fault message is received in return from a web service partner:

Example 44-2 Emulations

<?xml version="1.0" encoding="UTF-8" ?>
<!-- Generated by Oracle SCA Test Modeler version 1.0 at [7/3/07 3:29 PM]. -->
<compositeTest compositeDN="CompositeTest"
 xmlns="http://xmlns.oracle.com/sca/2006/test">
  <about></about>
  <initiate serviceName="client" operation="initiate" isAsync="true">
    <message>
      <part partName="payload">
        <filePath>loanApplication.xml</filePath>
      </part>
    </message>
  </initiate>
  <wireActions wireSource="LoanBroker/CreditRatingService" operation="process">
    <emulate duration="PT0S">
      <fault faultName="ser:NegativeCredit" xmlns:ser="http://services.otn.com">
        <message>
          <part partName="payload">
            <filePath>creditRatingFault.xml</filePath>
          </part>
        </message>
      </fault>
    </emulate>
  </wireActions>
</compositeTest>

Two message files, loanApplication.xml and creditRatingFault.xml, are invoked in this emulation. If the loan application request in loanApplication.xml contains a social security number beginning with 0, the creditRatingFault.xml file returns the fault message shown in Example 44-3:

Example 44-3 Fault Message

<error xmlns="http://services.otn.com">
  Invalid SSN, SSN cannot start with digit '0'.
</error>

For more information, see Section 44.4, "Creating the Contents of Test Cases."

44.2.3 Assertions

You create assertions to validate an entire XML document, a part section of a message, a nonleaf element, or a leaf element at a point during SOA composite application execution. Example 44-4 instructs Oracle SOA Suite to ensure that the content of the customerName variable matches the content specified.

Example 44-4 Assertions

<?xml version="1.0" encoding="UTF-8" ?>
<!-- Generated by Oracle SCA Test Modeler version 1.0 at [6/13/07 10:51 AM]. -->
<compositeTest compositeDN="TestFwk"
 xmlns="http://xmlns.oracle.com/sca/2006/test">
  <about></about>
  <initiate serviceName="client" operation="initiate" isAsync="true">
    <message>
      <part partName="payload">
        <content>
          <loanApplication xmlns="http://www.autoloan.com/ns/autoloan">
            <SSN>111222333</SSN>
            <email>joe.smith@example.com</email>
            <customerName>Joe Smith</customerName>
            <loanAmount>20000</loanAmount>
            <carModel>Camry</carModel>
            <carYear>2007</carYear>
            <creditRating>800</creditRating>
          </loanApplication>
        </content>
      </part>
    </message>
  </initiate>
  <wireActions wireSource="client" operation="initiate">
    <assert comparisonMethod="string">
      <expected>
        <location key="input" partName="payload"
 xpath="/s1:loanApplication/s1:customerName"
 xmlns:s1="http://www.autoloan.com/ns/autoloan"/>
        <simple>Joe Smith</simple>
      </expected>
    </assert>
  </wireActions>
</compositeTest>

For more information, see Section 44.4, "Creating the Contents of Test Cases."

44.2.4 Message Files

Message instance files provide a method for simulating the message data received back from web service partners. You can manually enter the received message data into this XML file or load a file through the test mode of the SOA Composite Editor. For example, the following message file simulates a credit rating result of 900 returned from a partner:

<rating xmlns="http://services.otn.com">900</rating>

For more information about loading message files into test mode, see Section 44.4, "Creating the Contents of Test Cases."

44.3 Creating Test Suites and Test Cases

This section describes how to create test suites and their test cases for a SOA composite application. The test cases consist of sets of commands to perform as the test instance is executed.

Note:

Do not enter a multibyte character string as a test suite name or test case name. Doing so causes an error to occur when the test is executed from Oracle Enterprise Manager Fusion Middleware Control.

44.3.1 How to Create Test Suites and Test Cases

To create test suites and test cases:

  1. Open the SOA Composite Editor.

  2. Open the SOA composite application in which to create a test suite.

  3. Go to the Application Navigator or Structure window. If the Structure window shown in Figure 44-1 does not appear, select Structure from the View main menu.

    Figure 44-1 Structure Window

    Description of Figure 44-1 follows
    Description of "Figure 44-1 Structure Window"

  4. Create a test suite in either of two ways:

    1. In the Application Navigator, right-click the testsuites folder and select Create Test Suite. Figure 44-2 provides details.

      Figure 44-2 Create Test Suite Selection

      Description of Figure 44-2 follows
      Description of "Figure 44-2 Create Test Suite Selection"

    2. In the Structure window, right-click Test Suites and select Create Test Suite. Figure 44-3 provides details.

      Figure 44-3 Create Test Suite Selection

      Description of Figure 44-3 follows
      Description of "Figure 44-3 Create Test Suite Selection"

  5. Enter a test suite name (for example, OrderBookingMainTestsuite of the Fusion Order Demo).

  6. Click OK.

    The Create Composite Test dialog appears.

  7. Enter a test name (for this example, NoErrorSanityTest of the Fusion Order Demo is entered) and an optional description. This description displays in the Description column of the Test Cases page of the Unit Tests tab in Oracle Enterprise Manager Fusion Middleware Control.

  8. Click OK.

    This action creates a test named NoErrorSanityTest.xml in the Application Navigator, along with the following subfolders:

    • componenttests

      This folder is not used in 11g Release 1.

    • includes

      This folder is not used in 11g Release 1.

    • messages

      Contains message test files that you load into this directory through the test mode user interface.

    • tests

      Contains NoErrorSanityTest.xml.

    A NoErrorSanityTest.xml folder also displays in the Structure window. Figure 44-4 provides details. This indicates that you are in the test mode of the SOA Composite Editor. You can create test initiations, assertions, and emulations in test mode. No other modifications, such as editing the property dialogs of service components or dropping service components into the editor, can be performed in test mode.

    Figure 44-4 NoErrorSanityTest.xml Folder

    Description of Figure 44-4 follows
    Description of "Figure 44-4 NoErrorSanityTest.xml Folder"

    The following operating system test suite directory is also created:

    C:\JDeveloper\mywork\application_name\project_name\testsuites\OrderBookingMainTestsuite
    

    The following subdirectories for adding test files are created beneath OrderBookingMainTestsuite: componenttests, includes, messages, and tests.

  9. If you want to exit test mode and return to design mode in the SOA Composite Editor, click the last icon below NoErrorSanityTest.xml above the designer. Figure 44-5 provides details.

    Figure 44-5 Test Mode Exit

    Description of Figure 44-5 follows
    Description of "Figure 44-5 Test Mode Exit"

  10. Save your changes when prompted.

  11. Under the testsuites folder in the Application Navigator, double-click NoErrorSanityTest.xml to return to test mode. Figure 44-6 provides details.

    Figure 44-6 Test Mode Access

    Description of Figure 44-6 follows
    Description of "Figure 44-6 Test Mode Access"

    Notes:

    • Do not edit the filelist.xml files that display under the subfolders of the testsuites folder. These files are automatically created during design time, and are used during runtime to calculate the number of test cases.

    • You cannot create test suites within other test suites. However, you can organize a test suite into subdirectories.

    The Fusion Order Demo provides examples of using test suites. For more information about the Fusion Order Demo, see Chapter 3, "Introduction to the SOA Sample Application."

44.4 Creating the Contents of Test Cases

Test cases consist of process initiations, emulations, and assertions. You add these actions to test cases in the test mode of the SOA Composite Editor. You create process initiations to initiate client inbound messages into your SOA composite application. You create emulations to simulate input or output message data, fault data, callback data, or all of these types that your SOA composite application receives from web service partners. You create assertions to validate entire XML documents, part sections of messages, nonleaf elements, and leaf elements as a process is executed.

44.4.1 How to Initiate Inbound Messages

To initiate inbound messages:

You must first initiate the sending of inbound client messages to the SOA composite application.

  1. Go to the SOA Composite application in test mode.

  2. Double-click the service binding component shown in Figure 44-7 (for this example, named initiate).

    Figure 44-7 Service Binding Component Access

    Description of Figure 44-7 follows
    Description of "Figure 44-7 Service Binding Component Access"

    The Edit Initiate dialog appears.

  3. Enter the details shown in Table 44-1:

    Table 44-1 Edit Initiate Dialog Fields and Values

    Field Value

    Service

    Displays the name of the binding component service (client).

    Operation

    Displays the operation type of the service binding component (initiate).

    Part

    Select the type of inbound message to send (for example, payload).

    Value

    Create a simulated message to send from a client:

    • Enter Manually

    Click to manually enter message data in the Enter Value field. A Generate Sample button enables you to automatically generate a sample file for testing. Click Save As to save the sample file.

    • Load From File

    Click the Browse icon to load message data from a file. The file is added to the messages folder in the Application Navigator.


    Figure 44-8 shows this dialog:

    Figure 44-8 Edit Initiate Dialog

    Description of Figure 44-8 follows
    Description of "Figure 44-8 Edit Initiate Dialog"

    The inbound process initiation message from a client looks as follows:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- Generated by Oracle SCA Test Modeler version 1.0 at [7/12/07 8:36 AM]. -->
    <compositeTest compositeDN="CompositeTest"
     xmlns="http://xmlns.oracle.com/sca/2006/test">
      <about/>
      <initiate serviceName="client" operation="initiate" isAsync="true">
        <message>
          <part partName="payload">
            <filePath>loanApplication.xml</filePath>
          </part>
        </message>
      </initiate>
    . . .
    . . .
    

    The loanApplication.xml referenced in the process initiation file contains a loan application payload:

    <loanApplication xmlns="http://www.autoloan.com/ns/autoloan">
      <SSN>111222333</SSN>
      <email>joe.smith@example.com</email>
      <customerName>Joe Smith</customerName>
      <loanAmount>20000</loanAmount>
      <carModel>Camry</carModel>
      <carYear>2007</carYear>
      <creditRating>800</creditRating>
    </loanApplication>
    
  4. Click OK.

44.4.2 How to Emulate Outbound Messages

To emulate outbound messages:

Note:

The creation of multiple emulations in an instance in a test case is supported only if one emulation is for an output message and the other is for a callback message.

You can simulate a message returned from a synchronous web service partner.

  1. Go to the SOA composite application in test mode.

  2. Beneath the testsuites folder in the Application Navigator, double-click a test case. Figure 44-9 provides details.

    Figure 44-9 Test Case Access

    Description of Figure 44-9 follows
    Description of "Figure 44-9 Test Case Access"

    The SOA composite application in the SOA Composite Editor is refreshed to display in test mode. This mode enables you to define test information.

  3. Double-click the wire of the SOA composite application area to test. For the example shown in Figure 44-10, the wire between the LoanBroker process and the synchronous CreditRating web service is selected.

    This displays the Wire Actions dialog shown in Figure 44-11, from which you can design emulations and assertions for the selected part of the SOA composite application.

    Figure 44-11 Wire Actions Dialog

    Description of Figure 44-11 follows
    Description of "Figure 44-11 Wire Actions Dialog"

  4. Click the Emulates tab.

  5. Click the Add icon.

  6. Click Emulate Output.

  7. Enter the details described in Table 44-2:

    Table 44-2 Emulate Output Message Dialog Fields and Values

    Field Value

    Part

    Select the message part containing the output (for example, payload).

    Value

    Create a simulated output message to return from a web service partner:

    • Enter Manually

    Click to manually enter message data in the Enter Value field. A Generate Sample button enables you to automatically generate a sample file for testing. Click Save As to save the sample file.

    • Load From File

    Click the Browse icon to load message data from a file. The file is added to the messages folder in the Application Navigator.

    Duration

    Enter the maximum amount of time to wait for the message to be delivered from the web service partner.


    Figure 44-12 shows this dialog:

    Figure 44-12 Emulate Dialog with Emulate Output Selected

    Description of Figure 44-12 follows
    Description of "Figure 44-12 Emulate Dialog with Emulate Output Selected"

    A simulated output message from a synchronous web service partner that you enter manually or load from a file looks as follows:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- Generated by Oracle SCA Test Modeler version 1.0 at [7/3/07 3:26 PM]. -->
    <compositeTest compositeDN="CompositeTest"
     xmlns="http://xmlns.oracle.com/sca/2006/test">
      <about></about>
      <initiate serviceName="client" operation="initiate" isAsync="true">
        <message>
          <part partName="payload">
            <filePath>loanApplication.xml</filePath>
          </part>
        </message>
      </initiate>
      <wireActions wireSource="LoanBroker/CreditRatingService" operation="process">
        <emulate duration="PT0S">
          <message>
            <part partName="payload">
              <filePath>creditRatingResult.xml</filePath>
            </part>
          </message>
        </emulate>
      </wireActions>
    </compositeTest>
    

    The creditRatingResult.xml message file referenced in the output message provides details about the credit rating result.

    <rating xmlns="http://services.otn.com">900</rating>
    
  8. Click OK.

44.4.3 How to Emulate Callback Messages

To emulate callback messages:

Note:

The creation of multiple emulations in an instance in a test case is supported only if one emulation is for an output message and the other is for a callback message.

You can simulate a callback message returned from an asynchronous web service partner.

  1. Access the Wire Actions dialog by following Step 1 through Step 3 of Section 44.4.2, "How to Emulate Outbound Messages."

  2. Click the Emulates tab.

  3. Click the Add icon.

  4. Click Emulate Callback. This field is only enabled for asynchronous processes.

  5. Enter the details described in Table 44-3:

    Table 44-3 Emulate Callback Message Fields

    Field Value

    Callback Operation

    Select the callback operation (for example, onResult).

    Callback Message

    Displays the callback message name of the asynchronous process.

    Part

    Select the message part containing the callback (for example, payload).

    Value

    Create a simulated callback message to return from an asynchronous web service partner:

    • Enter Manually

    Click to manually enter message data in the Enter Value field. A Generate Sample button enables you to automatically generate a sample file for testing. Click Save As to save the sample file.

    • Load From File

    Click the Browse icon to load message data from a file. The file is added to the messages folder in the Application Navigator.

    Duration

    Enter the maximum amount of time to wait for the callback message to be delivered from the web service partner.


    Figure 44-13 shows this dialog:

    Figure 44-13 Emulate Dialog with Emulate Callback Selected

    Description of Figure 44-13 follows
    Description of "Figure 44-13 Emulate Dialog with Emulate Callback Selected"

    The simulated callback message from a web service partner looks as follows. You enter this message manually or load it from a file:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!-- Generated by Oracle SCA Test Modeler version 1.0 at [7/3/07 3:27 PM]. -->
    <compositeTest compositeDN="CompositeTest"
     xmlns="http://xmlns.oracle.com/sca/2006/test">
      <about></about>
      <initiate serviceName="client" operation="initiate" isAsync="true">
        <message>
          <part partName="payload">
            <filePath>loanApplication.xml</filePath>
          </part>
        </message>
      </initiate>
      <wireActions wireSource="LoanBroker/LoanService" operation="initiate">
        <emulate callbackOperation="onResult" duration="PT0S">
          <message>
            <part partName="payload">
              <filePath>loanOffer.xml</filePath>
            </part>
          </message>
        </emulate>
      </wireActions>
    </compositeTest>
    

    The loanOffer.xml message file referenced in the callback message provides details about the credit rating approval.

    <loanOffer xmlns="http://www.autoloan.com/ns/autoloan">
      <providerName>Bank Of America</providerName>
      <selected>false</selected>
      <approved>true</approved>
      <APR>1.9</APR>
    </loanOffer>
    
  6. Click OK.

44.4.4 How to Emulate Fault Messages

To emulate fault messages:

You can simulate a fault message returned from a web service partner. This simulation enables you to test fault handling capabilities in your process.

  1. Access the Wire Actions dialog by following Step 1 through Step 3 of Section 44.4.2, "How to Emulate Outbound Messages."

  2. Click the Emulates tab.

  3. Click the Add icon.

  4. Click Emulate Fault.

  5. Enter the details described in Table 44-4:

    Table 44-4 Emulate Fault Message Fields

    Field Value

    Fault

    Select the fault type to return from a partner (for example, NegativeCredit).

    Fault Message

    Displays the message name.

    Part

    Select the message part containing the fault (for example, payload).

    Value

    Create a simulated fault message to return from a web service partner:

    • Enter Manually

    Click to manually enter message data in the Enter Value field. A Generate Sample button enables you to automatically generate a sample file for testing. Click Save As to save the sample file.

    • Load From File

    Click the Browse icon to load message data from a file. The file is added to the messages folder in the Application Navigator.

    Duration

    Enter the maximum amount of time to wait for the fault message to be delivered from the web service partner.


    Figure 44-14 shows this dialog:

    Figure 44-14 Emulate Dialog with Emulate Fault Selected

    Description of Figure 44-14 follows
    Description of "Figure 44-14 Emulate Dialog with Emulate Fault Selected"

    An example of a simulated fault message from a web service partner that you enter manually or load from a file is shown in Section 44.2.2, "Emulations."

  6. Click OK.

44.4.5 How to Create Assertions

To create assertions:

You perform assertions to verify variable data or process flow. Assertions enable you to validate test data in an entire XML document, a part section of a message, a nonleaf element, or a leaf element as a process is executed. This is done by extracting a value and comparing it to an expected value.

  1. Access the Wire Actions dialog by following Step 1 through Step 3 of Section 44.4.2, "How to Emulate Outbound Messages."

  2. Click the Asserts tab.

    Figure 44-15 shows this dialog:

    Figure 44-15 Wire Actions Dialog with Asserts Tab Selected

    Description of Figure 44-15 follows
    Description of "Figure 44-15 Wire Actions Dialog with Asserts Tab Selected"

  3. Click the Add icon.

    The Create Assert dialog appears.

  4. Select the type of assertion to perform at the top of the dialog, as shown in Table 44-5. If the operation supports only input messages, the Assert Input button is enabled. If the operation supports both input and output messages, the Assert Input and Assert Output buttons are both enabled.

    Table 44-5 Assertion Types

    Type Description

    Assert Input

    Select to create an assertion in the inbound direction.

    Assert Output

    Select to create an assertion in the outbound direction.

    Assert Callback

    Select to create an assertion on a callback.

    Assert Fault

    Select to assert a fault into the application flow.


  5. See the section shown in Table 44-6 based on the type of assertion you want to perform.

    Table 44-6 Assertion Types

    For an Assertion on... See...
    • A part section of a document

    • A nonleaf element

    • An entire XML document

    Section 44.4.5.1, "Creating Assertions on a Part Section, Nonleaf Element, or Entire XML Document"

    A leaf element

    Section 44.4.5.2, "Creating Assertions on a Leaf Element"


44.4.5.1 Creating Assertions on a Part Section, Nonleaf Element, or Entire XML Document

To create assertions on a part section, nonleaf element, or entire XML document:

This test compares the values to the expected values.

Note:

If the message contains multiple parts (for example, payload1, payload2, and payload3), you must create separate assertions for each part.

  1. Click Browse to select the target part section, nonleaf element, or entire XML document to assert.

    The Select Assert Target dialog appears.

  2. Select a value, and click OK. For example, select a variable such as payload to perform a part section assertion.

    Figure 44-16 shows this dialog. While this example shows how to perform a part section assertion, selecting LoanBrokerRequestMessage is an example of an entire XML document assertion and selecting loanApplication is an example of a nonleaf assertion.

    Figure 44-16 Select a Part Section of a Message

    Description of Figure 44-16 follows
    Description of "Figure 44-16 Select a Part Section of a Message"

    The Create Assert dialog refreshes based on your selection of a variable.

  3. Enter details in the remaining fields, as shown in Table 44-7:

    Table 44-7 Create Assert Dialog Fields and Values

    Field Value

    Fault

    Select the type of fault to assert (for example, NegativeCredit). This field only displays if you select Assert Fault in Step 4.of Section 44.4.5, "How to Create Assertions."

    Assert Target

    Displays the assert target you selected in Step 2.

    Compare By

    Specify the strictness of the comparison.

    • xml-identical: Used when the comparison between the elements and attributes of the XML documents must be exact. If there is any difference between the two XML documents, the comparison fails. For example, the comparison fails if one document uses an element name of purchaseOrder, while the other uses an element name of invoice. The comparison also fails if the child attributes of two elements are the same, but the attributes are ordered differently in each element.

    • xml-similar: Used when the comparison must be similar in content, but does not need to exactly match. For example, the comparison succeeds if both use the same namespace URI, but have different namespace prefixes. The comparison also succeeds if both contain the same element with the same child attributes, but the attributes are ordered differently in each element.

      In both of these examples, the differences are considered recoverable, and therefore similar.

    For more information about comparing the contents of XML files, see the XMLUnit web site:

    http://xmlunit.sourceforge.net/userguide/html/ar01s03.html#The%20Difference%20Engine
    

    Part

    Select the message part containing the XML document (for example, payload).

    Value

    Create an XML document whose content is compared to the assert target content:

    • Enter Manually

    Click to manually enter message data in the Enter Value field. A Generate Sample button enables you to automatically generate a sample file for testing. Click Save As to save the sample file.

    • Load From File

    Click the Browse icon to load message data from a file. The file is added to the messages folder in the Application Navigator.

    Description

    Enter an optional description.


    Figure 44-17 shows this dialog with Assert Input selected:

    Figure 44-17 Create Assert Dialog with Assert Input Selected

    Description of Figure 44-17 follows
    Description of "Figure 44-17 Create Assert Dialog with Assert Input Selected"

  4. Click OK.

    The Wire Actions dialog shown in Figure 44-18 displays your selection.

    Figure 44-18 Wire Actions Dialog with Asserts Tab Selected

    Description of Figure 44-18 follows
    Description of "Figure 44-18 Wire Actions Dialog with Asserts Tab Selected"

  5. Click OK.

44.4.5.2 Creating Assertions on a Leaf Element

To create assertions on a leaf element:

This test compares the value to an expected value.

  1. Click Browse to select the leaf element to assert.

    The Select Assert Target dialog appears.

  2. Select a leaf element, and click OK. For example, select loanAmount to perform an assertion. Figure 44-19 provides details.

    Figure 44-19 Selection of a Leaf Element

    Description of Figure 44-19 follows
    Description of "Figure 44-19 Selection of a Leaf Element"

    The Create Assert dialog refreshes based on your selection of an entire XML document.

  3. Enter details in the remaining fields, as shown in Table 44-8:

    Table 44-8 Create Assert Dialog Fields and Values

    Field Value

    Fault

    Select the type of fault to assert (for example, NegativeCredit). This field only displays if you select Assert Fault in Step 4 of Section 44.4.5, "How to Create Assertions."

    Callback Operation

    Select the type of callback to assert (for example, onResult). This field only displays if you select Assert Callback in Step 4 of Section 44.4.5, "How to Create Assertions."

    Assert Target

    Displays the variable assert target you selected in Step 2.

    Compare By

    Select the type of comparison:

    • string: Compares string values.

    • number: Compares numeric values.

    • pattern-match: Compares a regular expression pattern (for example, [0-9]*). Java Development Kit (JDK) regular expression (regexp) constructs are supported. For example, entering a pattern of ab[0-9]*cd means that a value of ab123cd or ab456cd is correct. An asterisk (*) indicates any number of occurrences.

    Assert Value

    Enter the value you are expecting. This value is compared to the value for the assert target.

    Description

    Enter an optional description.


    Figure 44-20 shows this dialog with Assert Input selected:

    Figure 44-20 Create Assert Dialog

    Description of Figure 44-20 follows
    Description of "Figure 44-20 Create Assert Dialog"

  4. Click OK.

    The Wire Actions dialog shown in Figure 44-21 displays your selection.

    Figure 44-21 Wire Actions Dialog with Asserts Tab Selected

    Description of Figure 44-21 follows
    Description of "Figure 44-21 Wire Actions Dialog with Asserts Tab Selected"

44.4.6 What You May Need to Know About Assertions

When a test is executed, and the response type returned is different from the type expected, the assertion is skipped. For example, you are expecting a fault (RemoteFault) to be returned for a specific message, but a response (BpelResponseMessage) is instead returned.

As a best practice, always assert and emulate the expected behavior.

44.5 Testing BPEL Process Service Components

You can automate the testing of an individual BPEL process service component included in a new or existing SOA composite application test suite. These test cases enable you to simulate the interaction between a BPEL process and its web service partners before deployment in a production environment. This helps to ensure that a BPEL process interacts with web service partners as expected by the time it is ready for deployment to a production environment.

Example 44-5 provides an example of a SOA composite application test suite that includes a component test for the LoanBroker BPEL process service component.

Example 44-5 BPEL Process Server Component Tests in a SOA Composite Application Test Suite

<compositeTest compositeDN="TestFwk"
 xmlns="http://xmlns.oracle.com/sca/2006/test">
  <about></about>
  <initiate serviceName="client" operation="initiate" isAsync="true">
    <message>
      <part partName="payload">
        <content>
          <loanApplication xmlns="http://www.autoloan.com/ns/autoloan">
            <SSN>111222333</SSN>
            <email>joe.smith@example.com</email>
            <customerName>Joe Smith</customerName>
            <loanAmount>20000</loanAmount>
            <carModel>Camry</carModel>
            <carYear>2007</carYear>
            <creditRating>800</creditRating>
          </loanApplication>
        </content>
      </part>
    </message>
  </initiate>
  <componentTest componentName="LoanBroker" filePath="assert.xml"/>
</compositeTest>

The assert.xml test shown in Example 44-5 specifies assertions for variables and faults.

Note:

You cannot automate the testing of business rule, human task, Oracle Mediator, or spring service components.

44.5.1 Overview of Assertions on BPEL Process Activities

You can create variable and fault assertions on BPEL process activities. Example 44-6 instructs the BPEL process to ensure that the contents of textVar and crOutput match the contents specified.

Example 44-6 Assertion on a BPEL Activity

<bpelTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns="http://xmlns.oracle.com/sca/2006/test"
               componentName="LoanBroker">
 <activityActions activityName="elementAssign">
    <assert comparisonMethod="number">
      <description>Some other assertion.</description>
      <expected>
        <location key="textVar"
                  xmlns:loan="http://www.autoloan.com/ns/autoloan"/>
        <simple>111222333</simple>
      </expected>
    </assert>
  </activityActions>
 <activityActions activityName="invokeCR">
    <assert comparisonMethod="number">
      <description>Make sure we got the output.</description>
      <expected>
        <location key="crOutput" partName="payload" xpath="/tns:rating"
 xmlns:tns="http://services.otn.com"/>
        <simple>560</simple>
      </expected>
    </assert>
  </activityActions>
</bpelTest>

For more information about creating assertions on BPEL process activities, see Section 44.5.5, "How to Create Assertions."

44.5.2 Overview of a Fast Forward Action on a Wait Activity

A wait activity allows a process to wait for a given time period or until a time limit has been reached. When testing a BPEL process service component, you may want to bypass the wait activity to continue with testing. A fast forward action enables you to specify the amount of time for which to bypass a wait activity and move forward in the test scenario. Example 44-7 instructs the BPEL process to bypass the wait activity for 1 second.

Example 44-7 Fast Forward Action on a Wait Activity

<bpelTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://xmlns.oracle.com/sca/2006/test
 TestFwk.xsd"
               xmlns="http://xmlns.oracle.com/sca/2006/test"
               componentName="LoanBroker">
    <activityActions activityName="wait1">
      <fastForward duration="PT1S"/>
    </activityActions>
</bpelTest>

For more information about creating fast forward actions on wait activities, see Section 44.5.6, "How to Bypass a Wait Activity."

44.5.3 Overview of Assert Activity Execution

You can specify and validate the number of times an activity is executed in a BPEL process. Example 44-8 instructs the BPEL process to execute the invoke, elementAssign, invokeCR, and replyOutput activities one time each.

Example 44-8 Assert Activity Executed

<bpelTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns="http://xmlns.oracle.com/sca/2006/test"
               componentName="LoanBroker">
    <assertActivityExecuted activityName="invoke" executionCount="1"/>
    <assertActivityExecuted activityName="elementAssign" executionCount="1"/>
    <assertActivityExecuted activityName="invokeCR" executionCount="1"/>
    <assertActivityExecuted activityName="replyOutput" executionCount="1"/>
</bpelTest>

For more information about creating assert activity executions, see Section 44.5.7, "How to Specify the Number of Times to Execute an Activity."

44.5.4 How to Create BPEL Process Service Component Tests

To create BPEL process service component tests:

  1. Double-click a BPEL process in a test suite (for this example, LoanBroker).

    If you have not yet created a test suite, see Section 44.3.1, "How to Create Test Suites and Test Cases." The BPEL process service component test that you create is included in the overall test suite for the SOA composite application.

    The Create Component Test dialog is displayed, as shown in Figure 44-22.

    Figure 44-22 Create Component Test Dialog

    Description of Figure 44-22 follows
    Description of "Figure 44-22 Create Component Test Dialog"

  2. Accept the default name or enter a different name, as shown in Figure 44-22.

  3. Click OK.

    The BPEL process in test mode is displayed, as shown in Figure 44-23.

    In the lower left section, the Structure window displays the Asserts, Fast Forwards, and Assert Execution Counts folders. You can right-click these folders to create assertions, fast forwards (to bypass executions of wait activities), and assertion execution counts, respectively.

    Above the designer, the following buttons are displayed:

    • BPEL: Click to access the BPEL process service component in design mode of Oracle BPEL Designer (that is, in nontest mode). This button is currently enabled in Figure 44-23 because you are in test mode for the BPEL process.

    • Monitor: Click to configure BPEL process monitors in Oracle BPEL Designer. BPEL process monitors can send data to Oracle BAM for analysis and graphical display through the Oracle BAM adapter. For more information, see Section 53.3, "Using Oracle BAM Monitor Express With BPEL Processes."

    • Test: This button is currently disabled because you are in test mode for the BPEL process service component. This button is enabled when you click the BPEL button to enter design mode in Oracle BPEL Designer.

    Figure 44-23 BPEL Process Service Component in Test Mode

    Description of Figure 44-23 follows
    Description of "Figure 44-23 BPEL Process Service Component in Test Mode"

44.5.5 How to Create Assertions

You can create assertions for variables and faults in BPEL process activities.

To create assertions:

  1. Select the activity on which to create an assertion through one of the following methods:

    1. In the Structure window, right-click the Asserts folder and select Create, or select the Asserts folder and click the Add button.

      The Assert dialog is displayed.

    2. In the Activity Name field, click the Browse icon to select an activity.

    or

    1. Right-click a specific BPEL activity in the designer, and select Edit Activity Test Data.

    2. Click the Asserts tab.

    3. Click the Add icon.

      The activity you selected is displayed in the Activity Name field.

  2. Enter details in the remaining fields, as shown in Table 44-9.

    Table 44-9 Assertions on BPEL Activities

    Field Value

    Assert Variable

    Select to assert a variable.

    Assert Fault

    Select to assert a fault.

    Target

    Select a target to assert:

    • If you selected Assert Variable, click the Browse icon to select the type of variable to assert (for example: /autoloan:loanApplication/autoloan:SSN).

    • If you selected Assert Fault, click the Browse icon to select the type of fault to assert (for example, NegativeCredit).

    Compare By

    If comparing XML documents, specify the strictness of the comparison:

    • XML Identical: Use when the comparison between the elements and attributes of the XML documents must be exact. If there is any difference between the two XML documents, the comparison fails. For example, the comparison fails if one document uses an element name of purchaseOrder, while the other uses an element name of invoice. The comparison also fails if the child attributes of two elements are the same, but the attributes are ordered differently in each element.

    • XML Similar: Use when the comparison must be similar in content, but does not need to exactly match. For example, the comparison succeeds if both use the same namespace URI, but have different namespace prefixes. The comparison also succeeds if both contain the same element with the same child attributes, but the attributes are ordered differently in each element.

      In both of these examples, the differences are considered recoverable, and therefore similar.

    If comparing variables, specify the type:

    • String: Select to compare string values.

    • Pattern Match Using Java Regular Expressions: Select to compare a regular expression pattern (for example, [0-9]*). Java Development Kit (JDK) regular expression (regexp) constructs are supported. For example, entering a pattern of ab[0-9]*cd means that a value of ab123cd or ab456cd is correct. An asterisk (*) indicates any number of occurrences.

    • Number: Select to compare numeric values.

    Parts

    Select the message part containing the XML document (for example, payload).

    Value

    Create an XML document whose content is compared to the assert target content:

    • Enter Manually

    Click to manually enter message data in the Enter Value field. A Generate Instance Sample icon enables you to automatically generate a sample file for testing. Click the Save As icon to save the sample file.

    • Load From File

    Click the Browse icon to load message data from a file. The file is added to the messages folder in the Application Navigator.

    Description

    Enter an optional description.


  3. Click OK.

    Expand the Assert folder in the Structure window to view the activities on which you have created asserts. Figure 44-24 provides details.

    Figure 44-24 Assert Folder in Structure Window

    Description of Figure 44-24 follows
    Description of "Figure 44-24 Assert Folder in Structure Window"

44.5.6 How to Bypass a Wait Activity

You can specify the amount of time for which to bypass a wait activity and move forward in the test scenario. Once the time limit expires, the wait activity is processed.

To bypass a wait activity:

  1. Select the wait activity to bypass through one of the following methods:

    1. In the Structure window, right-click the Fast Forwards folder and select Create, or select the Fast Forwards folder and click the Add button.

      The Fast Forward dialog is displayed.

    2. In the Activity Name field, click the Browse icon to select the wait activity.

    or

    1. Right-click a specific wait activity in the designer, and select Edit Activity Test Data.

    2. Click the Fast Forward tab. This tab is only displayed if there are wait activities in the BPEL process.

    3. Click the Add icon.

      The wait activity you selected is displayed in the Activity Name field.

  2. In the Duration list, specify a time period for which to bypass the wait activity (for example, 1 second).

  3. Click OK.

  4. Expand the Fast Forwards folder in the Structure window to view the amount of time for which to bypass the wait activity and move forward in the test scenario. Figure 44-25 provides details.

    Figure 44-25 Fast Forwards Folder in Structure Window

    Description of Figure 44-25 follows
    Description of "Figure 44-25 Fast Forwards Folder in Structure Window"

For more information about wait activities, see Section 15.4, "Creating a Wait Activity to Set an Expiration Time."

44.5.7 How to Specify the Number of Times to Execute an Activity

You can specify to execute an activity a specified number of times. This provides a method for verifying that an activity executes the correct number of times in a process flow (for example, ensuring that a while activity executes the correct number of times).

To specify the number of times an activity is executed:

  1. Select the activity to execute through one of the following methods:

    1. In the Structure window, right-click the Assert Execution Counts folder and select Create, or select the Assert Execution Counts folder and click the Add button.

      The Assert Execution Count dialog is displayed.

    2. In the Activity Name field, click the Browse icon to select the activity to execute.

    or

    1. Right-click a specific BPEL activity in the designer, and select Edit Activity Test Data.

    2. Click the Assert Execution Count tab.

    3. Click the Add icon.

      The activity you selected is displayed in the Activity Name field.

  2. In the Count list, select a value.

  3. Click OK.

    The Activity Test Data dialog looks as shown in Figure 44-26.

    Figure 44-26 Activity Test Data Dialog

    Description of Figure 44-26 follows
    Description of "Figure 44-26 Activity Test Data Dialog"

  4. Expand the Assert Execution Counts folder in the Structure window to view execution counts assigned to activities. Figure 44-27 provides details.

    Figure 44-27 Assert Execution Counts Folder in Structure Window

    Description of Figure 44-27 follows
    Description of "Figure 44-27 Assert Execution Counts Folder in Structure Window"

44.6 Deploying and Running a Test Suite

After creating a test suite of test cases, you deploy the suite as part of a SOA composite application. You then run the test suites from Oracle Enterprise Manager Fusion Middleware Control.