Pages

Tuesday, August 25, 2009

Starting SOA Suite Testcases from java

In a previous blog I already explained how to unit test a Soa Suite 11g composite application. In that blog entry I create a Test Suite with a testcase but I had to start this testcase and watch the results of the test in the Enterprise Manager Website. In this blog I will start the TestSuite with the Testcases from the Soa Suite java API. This can be handy when you have a continious build system like Hudson or Apache Continuum. Now you can build your test in JDeveloper and run the test in the Continious Build System.
In this test I made a simple Test Suite with two testcases and deployed this to the Soa Suite Server.
Create a test project with the following libraries
And create a java class like this example class.

package nl.whitehorses.bpel.unit;

import java.util.Hashtable;
import java.util.List;

import javax.naming.Context;

import oracle.soa.management.facade.Locator;
import oracle.soa.management.facade.LocatorFactory;

import oracle.soa.management.util.TestSuiteFilter;
import oracle.soa.management.util.TestRunOptions;

import oracle.soa.management.facade.tst.TestSuite;
import oracle.soa.management.facade.tst.TestCase;
import oracle.soa.management.facade.tst.TestRunResults;
import oracle.soa.management.facade.tst.TestSuiteResult;
import oracle.soa.management.facade.tst.TestCaseResult;


public class StartUnitProcess {
public StartUnitProcess() {
super();

Hashtable jndiProps = new Hashtable();
jndiProps.put(Context.PROVIDER_URL, "t3://localhost:8001/soa-infra");
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
jndiProps.put(Context.SECURITY_PRINCIPAL, "weblogic");
jndiProps.put(Context.SECURITY_CREDENTIALS, "weblogic1");
jndiProps.put("dedicated.connection", "true");

Locator locator = null;
try {
// connect to the soa server
locator = LocatorFactory.createLocator(jndiProps);

TestSuiteFilter testFilter = new TestSuiteFilter();
testFilter.addSuiteName("HelloTest");
String compositeDN = "default/Helloworld!1.0";
List testSuites = locator.getTestSuites(compositeDN,testFilter);

for (TestSuite testSuite : testSuites) {
System.out.println("Found TestSuite name: "+testSuite.getName()+" description: "+testSuite.getDescription());

List testcases = testSuite.getTestCases();
System.out.println("Total TestCases: " +testcases.size());

for (TestCase testCase : testcases) {
System.out.println("Contains TestCase: " +testCase.getName());
}

TestRunOptions testRunOptions = new TestRunOptions();
testRunOptions.setTestRunId("123");
testRunOptions.setTestRunName("name123");

TestRunResults result = locator.executeTestCases(compositeDN,testRunOptions,testcases);
System.out.println("total errors: "+ result.getNumErrors() +
" status: "+ result.getStatus());

List testSuiteResults = result.getTestSuiteResults() ;
for (TestSuiteResult testSuiteResult : testSuiteResults) {
System.out.println("TestSuite name: "+testSuiteResult.getSuiteName()+
" success: "+testSuiteResult.getNumSuccesses() +
" errors: "+ testSuiteResult.getNumErrors() );
List testCaseResults = testSuiteResult.getTestResults() ;
for (TestCaseResult testCaseResult : testCaseResults) {
System.out.println("TestCase name: "+testCaseResult.getTestName()+
" status: "+testCaseResult.getStatus() );
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
StartUnitProcess startUnitProcess = new StartUnitProcess();
}
}

Here is an example of the result of invoking the TestSuite in java

2 comments:

  1. Hi,

    Thank you for the article.

    Is is possible to override messages, asserts & emulates from Java ?

    Thanks,

    Setya

    ReplyDelete