SOA Suite 11g Unit Testing Experiences

I've been working on doing some unit testing for our SOA composites over the last few days. It has been one of those things that we keep putting off, but I finally got around to it and I wanted to write down some of the things I learned over the last few days.

Key Take Aways

You need a SOA Suite server

One of the first things that I was thoroughly surprised by was that you actually need a full running SOA Suite server to be able to do any sort of Unit Testing on your composite. Bad Oracle, Bad Oracle... I understand that the engines that the various components go through (BPEL, Mediator etc) are needed, but there should be a more lightweight alternative to having a full running Suite.

There are Ant scripts available

I kind of figured there were Ant Scripts available, given that we have the whole ant-sca package of Ant scripts to use for building, deploying etc. The one you want to look at in this case is the ant-sca-test.xml Ant script. It has two targets. A "test" and a "report" target. It wasn't immediately apparent to me how they worked, even after reading the documentation. But with a little trial and error I managed to incorporate it into our normal build scripts using the following:

    <ant antfile="${ant-sca-test}" target="test" inheritall="false">
      <!-- Environment Properties -->
<property name="scatest.result" value="${build}/test" />
<property name="scatest.input" value="${project.name}"/>
<property name="scatest.partition" value="default"/>
<property name="scatest.format" value="junit"/>
    <property name="jndi.properties.input" value="${build}/jndi.properties"/>
    </ant>

    <ant antfile="${ant-sca-test}" target="report" inheritall="false">
      <!-- Environment Properties -->
<property name="scatest.result" value="${build}/test" />
    </ant>

From these ant calls we can see that I call the "test" target first before calling the "report" target. The important bit that took me awhile to figure out was which properties I needed to set.
  • scatest.result
    • The folder where the test results are stored. It's important that this value is the same for both targets
  • scatest.input
    • The Name of the Composite to test. This was not clear to me from the beginning. I initially thought it was the path to the composite source.
  • scatest.partition
    • The partition the composite is deployed to
  • scatest.format
    • I'm not sure which values are available here, but I do know that the report target doesn't work if it isn't set to junit
  • jndi.properties.input
    • A property file with properties describing the server. I'll elaborate on that below.
The jndi property file needs the following values:
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
java.naming.provider.url=t3://SOA_SERVER_HOST:SOA_SERVER_PORT/soa-infra
java.naming.security.principal=WEBLOGIC_USERNAME
java.naming.security.credentials=WEBLOGIC_PASSWORD
dedicated.connection=true
dedicated.rmicontext=true

The values should be self explanatory.

Final thoughts

With these things sorted out we can now run "ant test" in our build scripts and it will build, deploy and run the unit tests against our server. I still feel that it is a bit crazy that we need a full SOA Suite installation to run these tests, but I guess it's as good as it's going to get at the moment. It also seems it has been improved a lot in the 12c version of the Oracle SOA suite. As we get more into this I will try to either update this post, or write new ones.