{
public static void testContext2()
throws Exception
{
UserActivity ua = UserActivityFactory.userActivity();
DemoHLS demoHLS = new DemoHLS();
FailureHLS failureHLS = new FailureHLS(); // this constructor means it will lnto fail
HLS[] currentHLS = ActivityManagerFactory.activityManager().allHighLevelServices();
for (HLS hls : currentHLS) {
ActivityManagerFactory.activityManager().removeHLS(hls);
}
try
{
ActivityManagerFactory.activityManager().addHLS(demoHLS);
ActivityManagerFactory.activityManager().addHLS(failureHLS);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
org.w3c.dom.Document doc = docBuilder.newDocument();
org.w3c.dom.Element root = doc.createElement("Context2-test");
doc.appendChild(root);
ua.start();
System.out.println("Started: "+ua.activityName());
ua.start();
System.out.println("Started: "+ua.activityName()+"\n");
ContextManager contextManager = new ContextManager();
Context[] contexts = contextManager.contexts();
Context theContext1 = null;
Context theContext2 = null;
int numContexts = (contexts != null ? contexts.length : 0);
for (int i = 0; i < numContexts; i++) {
if (contexts[i] != null) {
if (theContext1 == null) {
theContext1 = contexts[i];
} else {
theContext2 = contexts[i];
break;
}
}
}
if (theContext1 == null || theContext2 == null) {
fail("Demo contexts not found");
}
if (!(theContext1 instanceof DemoSOAPContextImple) ||
!(theContext1 instanceof DemoSOAPContextImple)) {
fail("Demo contexts not found");
}
((SOAPContext)theContext1).serialiseToElement(root);
((SOAPContext)theContext2).serialiseToElement(root);
System.out.println("Context is " + root.getTextContent());
ua.end();
System.out.println("\nFinished child activity.\n");
contexts = contextManager.contexts();
theContext1 = null;
theContext2 = null;
numContexts = (contexts != null ? contexts.length : 0);
for (int i = 0; i < numContexts; i++) {
if (contexts[i] != null) {
if (theContext1 == null) {
theContext1 = contexts[i];
} else {
theContext2 = contexts[i];
break;
}
}
}
if (theContext1 == null || theContext2 == null) {
fail("Demo contexts not found");
}
if (!(theContext1 instanceof DemoSOAPContextImple) ||
!(theContext1 instanceof DemoSOAPContextImple)) {
fail("Demo contexts not found");
}
doc = docBuilder.newDocument();
root = doc.createElement("Context2-test");
doc.appendChild(root);
((SOAPContext)theContext1).serialiseToElement(root);
((SOAPContext)theContext2).serialiseToElement(root);
System.out.println("Context is " + root.getTextContent());
ua.end();
System.out.println("\nFinished parent activity.\n");
}
catch (Exception ex)
{