# Testing Framework

Olivier Le Diouris
March 28th, 2006.

### Resources

- XMLUnit
- JUnit 3.8.1
- Generic BPEL Clients
- XMLUnit/JUnit/Ant sample
- BPEL Testing Sample with Ant, JUnit, and XMLUnit

This document is suggesting the first step of a testing framework for BPEL Processes, based on Ant, JUnit and XMLUnit.
I have succesfully used the Ant and JUnit coming with JDeveloper 10.1.3. I just had to download XMLUnit, from the link mentionned above.

### The Generic BPEL Clients

We have developped here 3 generic java clients for BPEL Processes. They are generic for:

- Synchronous processes
- Asynchronous processes, with no callback required
- Asynchronous processes, with reply to the client

Those clients can be found in the archive named GenericBPELClient.zip.
In this archive you also have a bat-file - runnable on windows - that shows how to start those clients from the command line.

    :: Sync
    java bpel.util.GenericSyncClient -process MinWait \
                                     -method process \
                                     -domain default \
                                     -password bpel \
                                     -input input-sync.xml \
                                     -output output.xml \
                                     -context context.properties

This shows how to call a synchronous process. It takes several parameters:

-process | This stands for the name of the BPEL Process to invoke, as it is deployed in the BPEL Process Manager
-method | The name of the method to call, process is the default for the synchronous processes.
-domain | The name of the domain you deployed to process to call to.
-password | The password associated with the domain mentionned above.
-input | The name of the file containing the payload to invoke the method with. For example:
    <?xml version='1.0' encoding='windows-1252'?>
    <MinWaitProcessRequest xmlns="http://xmlns.oracle.com/MinWait">
      <wait-time>123</wait-time>
    </MinWaitProcessRequest>
-output | The name of the file to write the process output in. This file can be then used by XMLUnit to compare its content with some reference data.
-context | The name of the file containing the properties to use to create a connection on the BPEL Server. For example:
    orabpel.platform=oc4j_10g
    java.naming.factory.initial=com.evermind.server.rmi.RMIInitialContextFactory
    java.naming.provider.url=ormi://localhost/orabpel
    # java.naming.provider.url=opmn:ormi://ansoda01.turkcell.com.tr:6003:OC4J_BPEL/orabpel
    java.naming.security.principal=admin
    java.naming.security.credentials=welcome
    dedicated.connection=true

    :: Async One Way
    java bpel.util.GenericAsyncOneWayClient -process SayHello \
                                            -method initiate \
                                            -domain default \
                                            -password bpel \
                                            -input input.xml \
                                            -context context.properties

The above shows how to call an Asynchronous process, that does not return anything to the caller. That one will not be very useful in our context, but it might be interesting.
Parameters have the same meaning as above, notice that there is no output parameter.

    :: Async Two Ways
    java bpel.util.GenericAsyncTwoWaysClient -process SayHello \
                                             -method initiate \
                                             -domain default \
                                             -password bpel \
                                             -input input.xml \
                                             -output output2.xml \
                                             -context context.properties \
                                             -polling 100 \
                                             -outputVariable outputVariable

This one has the same parameters as the first one, plus two extra ones:

-polling | The time between each polling on the process, to see if it is completed. This value is in milliseconds.
-outputVariable | The name of the XML Element containing the result we are interested in. The default value of such an element is outputVariable.

### An example, involving the above, JUnit and XMLUnit

BPELXMLUnit.zip contains an example of a test running a BPEL Process and comparing its output with what it should be.
It mostly contains an Ant build file - called test.xml:

    <?xml version="1.0" encoding="windows-1252" ?>
    <project default="xmltest">

      <property name="bpel.home" value="C:/OraBPELPM_10.1.2.Ph.2"/>
      <property name="jdev.home" value="${bpel.home}/integration/jdev"/>

       <path id="classpath">
          <pathelement location="${jdev.home}/jdev/lib/ext/orabpel.jar"/>
          <pathelement location="${jdev.home}/jdev/lib/ext/orabpel-common.jar"/>
          <pathelement location="${jdev.home}/jdev/lib/ext/orabpel-thirdparty.jar"/>
          <pathelement location="${jdev.home}/jdev/lib/ext/bpm-infra.jar"/>
          <pathelement location="${jdev.home}/jdev/lib/ext/bpm-services.jar"/>
          <pathelement location="${bpel.home}/integration/orabpel/system/appserver/oc4j/j2ee/home/oc4j.jar"/>
          <pathelement location="${bpel.home}/integration/orabpel/system/appserver/oc4j/j2ee/home/oc4jclient.jar"/>
          <pathelement location="${bpel.home}/integration/orabpel/system/appserver/oc4j/j2ee/home/rmic.jar"/>
          <pathelement location="${bpel.home}/integration/orabpel/system/appserver/oc4j/j2ee/home/lib/jmxri.jar"/>
          <pathelement location="${bpel.home}/integration/orabpel/system/appserver/oc4j/lib/dms.jar"/>

          <pathelement location="C:/_myWork/MiscTests/GenericBPELClient/deploy/client.jar"/>
       </path>

      <target name="xmltest" depends="startBPELProcess">
        <echo message="Starting xmltest"/>
        <junit fork="yes" dir=".">
          <classpath>
            <pathelement path=".\classes"/>
            <pathelement path="C:\JDev3673\jdev\extensions\oracle.jdeveloper.junit.10.1.3\junit3.8.1\junit.jar"/>
            <pathelement path="C:\xmlunit\lib\xmlunit1.0.jar"/>
            <pathelement path="C:\JDev3673\lib\xmlparserv2.jar"/>
            <pathelement path="C:\JDev3673\lib\xml.jar"/>
            <pathelement path="C:\JDev3673\jdev\extensions\oracle.jdeveloper.junit.10.1.3.jar"/>
          </classpath>
          <formatter type="plain"/>
          <!--formatter type="xml"/-->
          <test name="bpelxmlunit.BPELResultXMLTester"/>
        </junit>
      </target>

      <target name="startBPELProcess">
        <java fork="yes" classname="bpel.util.GenericAsyncTwoWaysClient" dir=".">
          <classpath refid="classpath"/>
          <arg line="-process SayHello"/>
          <arg line="-method initiate"/>
          <arg line="-domain default"/>
          <arg line="-password bpel"/>
          <arg line="-input ./input.xml"/>
          <arg line="-output ./output2.xml"/>
          <arg line="-context ./context.properties"/>
          <arg line="-polling 100"/>
          <arg line="-outputVariable outputVariable"/>
        </java>
      </target>

    </project>

Notice the classpath, that refers to JUnit, XMLUnit, and the Generic Clients described above.
The test we want to run is the target called xmltest. It depends on another one, named startBPELProcess that starts the BPEL Process which we want the output of.
The formatter can be xml, plain, or brief. This impacts the format of the output generated by the test case.
The output of the test looks like this:

    Buildfile: C:\_myWork\Projects\BPELTestingFramework\BPELXMLUnit\test.xml

    startBPELProcess:
         [java] Process launched in 430 ms
         [java] Check out ./output2.xml
         [java] Done.

    xmltest:
         [echo] Starting xmltest

    BUILD SUCCESSFUL
    Total time: 3 seconds