[jboss-svn-commits] JBL Code SVN: r18920 - in labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests: junit/hls and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Mar 13 08:02:04 EDT 2008


Author: adinn
Date: 2008-03-13 08:02:04 -0400 (Thu, 13 Mar 2008)
New Revision: 18920

Modified:
   labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/DemoHLS.java
   labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/DemoSOAPContextImple.java
   labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/FailureHLS.java
   labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/WSASTestSuite.java
   labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/junit/hls/Context1.java
   labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/junit/hls/Context2.java
Log:
patched context tests to do soemthing useful - changes for JBTM-339

Modified: labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/DemoHLS.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/DemoHLS.java	2008-03-13 11:55:06 UTC (rev 18919)
+++ labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/DemoHLS.java	2008-03-13 12:02:04 UTC (rev 18920)
@@ -44,6 +44,8 @@
 
 import com.arjuna.mw.wsas.exceptions.*;
 
+import java.util.*;
+
 /**
  * @author Mark Little (mark.little at arjuna.com)
  * @version $Id: DemoHLS.java,v 1.2 2005/05/19 12:13:19 nmcl Exp $
@@ -52,7 +54,13 @@
 
 public class DemoHLS implements HLS
 {
+    private Stack<GlobalId> _id;
 
+    public DemoHLS()
+    {
+        _id = new Stack<GlobalId>();
+    }
+
     /**
      * An activity has begun and is active on the current thread.
      */
@@ -63,7 +71,9 @@
 	{
 	    GlobalId activityId = UserActivityFactory.userActivity().activityId();
 
-	    System.out.println("DemoHLS.begun "+activityId);
+        _id.push(activityId);
+
+        System.out.println("DemoHLS.begun "+activityId);
 	}
 	catch (Exception ex)
 	{
@@ -74,8 +84,6 @@
     /**
      * The current activity is completing with the specified completion status.
      *
-     * @param CompletionStatus cs The completion status to use.
-     *
      * @return The result of terminating the relationship of this HLS and
      * the current activity.
      */
@@ -84,8 +92,8 @@
     {
 	try
 	{
-	    System.out.println("DemoHLS.complete ( "+cs+" ) "+UserActivityFactory.userActivity().activityId());
-	}
+	    System.out.println("DemoHLS.complete ( "+cs+" ) " + UserActivityFactory.userActivity().activityId());
+    }
 	catch (Exception ex)
 	{
 	    ex.printStackTrace();
@@ -101,7 +109,7 @@
 
     public void suspended () throws SystemException
     {
-	System.out.println("DemoHLS.suspended");
+    System.out.println("DemoHLS.suspended");
     }	
 
     /**
@@ -110,7 +118,7 @@
 
     public void resumed () throws SystemException
     {
-	System.out.println("DemoHLS.resumed");
+    System.out.println("DemoHLS.resumed");
     }	
 
     /**
@@ -120,15 +128,15 @@
 
     public void completed () throws SystemException
     {
-	try
-	{
-	    System.out.println("DemoHLS.completed "+UserActivityFactory.userActivity().activityName());
-	}
-	catch (NoActivityException ex)
-	{
-	    ex.printStackTrace();
-	}
-    }		
+        try {
+        System.out.println("DemoHLS.completed "+ UserActivityFactory.userActivity().activityId());
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        if (!_id.isEmpty()) {
+            _id.pop();
+        }
+    }
 
     /**
      * The HLS name.
@@ -164,7 +172,16 @@
 
     public Context context () throws SystemException
     {
-	return new DemoSOAPContextImple(identity());
+        if (_id.isEmpty()) {
+            throw new SystemException("request for context when inactive");
+        }
+    try {
+        System.out.println("DemoHLS.context "+ UserActivityFactory.userActivity().activityId());
+    } catch (Exception ex) {
+        ex.printStackTrace();
     }
 
+        return new DemoSOAPContextImple(identity() + "_" + _id.size());
+    }
+
 }

Modified: labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/DemoSOAPContextImple.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/DemoSOAPContextImple.java	2008-03-13 11:55:06 UTC (rev 18919)
+++ labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/DemoSOAPContextImple.java	2008-03-13 12:02:04 UTC (rev 18920)
@@ -35,6 +35,7 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.w3c.dom.Element;
+import org.w3c.dom.Document;
 
 import com.arjuna.mw.wsas.context.soap.SOAPContext;
 import com.arjuna.mwlabs.wsas.util.XMLUtils;
@@ -53,10 +54,9 @@
     	    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
     	
     	    org.w3c.dom.Document doc = docBuilder.newDocument();
+            _context = doc.createElement(id);
 
-    	    _context = doc.createElement(id);
-
-    	    _context.appendChild(doc.createTextNode("urn:mycomputer.org:"+id+":foo:bar"));
+            _context.appendChild(doc.createTextNode("urn:mycomputer.org:"+id+":foo:bar"));
     	}
     	catch (Exception ex)
     	{
@@ -77,8 +77,12 @@
      */
     public Element serialiseToElement(final Element element)
     {
-        element.appendChild(_context) ;
-        return _context ;
+        Document document = element.getOwnerDocument();
+        // copy the context structure into the document
+        Element context = document.createElement(_context.getTagName());
+        context.appendChild(document.createTextNode(_context.getTextContent()));
+        element.appendChild(context);
+        return context;
     }
     
     public String identifier ()

Modified: labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/FailureHLS.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/FailureHLS.java	2008-03-13 11:55:06 UTC (rev 18919)
+++ labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/FailureHLS.java	2008-03-13 12:02:04 UTC (rev 18920)
@@ -44,6 +44,8 @@
 
 import com.arjuna.mw.wsas.exceptions.*;
 
+import java.util.Stack;
+
 /**
  * @author Mark Little (mark.little at arjuna.com)
  * @version $Id: FailureHLS.java,v 1.2 2005/05/19 12:13:19 nmcl Exp $
@@ -52,6 +54,7 @@
 
 public class FailureHLS implements HLS
 {
+    private Stack<GlobalId> _id;
 
     public static final int BEGUN_FAIL = 0;
     public static final int COMPLETE_FAIL = 1;
@@ -69,6 +72,7 @@
     public FailureHLS (int failPoint)
     {
 	_failPoint = failPoint;
+    _id = new Stack<GlobalId>();
     }
     
     /**
@@ -84,7 +88,9 @@
 	{
 	    GlobalId activityId = UserActivityFactory.userActivity().activityId();
 
-	    System.out.println("FailureHLS.begun "+activityId);
+        _id.push(activityId);
+
+        System.out.println("FailureHLS.begun "+activityId);
 	}
 	catch (Exception ex)
 	{
@@ -95,7 +101,7 @@
     /**
      * The current activity is completing with the specified completion status.
      *
-     * @param CompletionStatus cs The completion status to use.
+     * @param cs cs The completion status to use.
      *
      * @return The result of terminating the relationship of this HLS and
      * the current activity.
@@ -108,7 +114,7 @@
 
 	try
 	{
-	    System.out.println("FailureHLS.complete ( "+cs+" ) "+UserActivityFactory.userActivity().activityId());
+	    System.out.println("FailureHLS.complete ( "+cs+" ) "+ UserActivityFactory.userActivity().activityId());
 	}
 	catch (Exception ex)
 	{
@@ -155,7 +161,10 @@
 
 	try
 	{
-	    System.out.println("FailureHLS.completed "+UserActivityFactory.userActivity().activityName());
+	    System.out.println("FailureHLS.completed " + UserActivityFactory.userActivity().activityId());
+        if (!_id.isEmpty()) {
+            _id.pop();
+        }
 	}
 	catch (NoActivityException ex)
 	{
@@ -192,10 +201,6 @@
      * Return the context augmentation for this HLS, if any on the current
      * activity.
      *
-     * @param ActivityHierarchy current The handle on the current activity
-     * hierarchy. The HLS may use this when determining what information to
-     * place in its context data.
-     *
      * @return a context object or null if no augmentation is necessary.
      */
 
@@ -204,9 +209,19 @@
 	if (_failPoint == FailureHLS.CONTEXT_FAIL)
 	    throw new SystemException();
 
-	return new DemoSOAPContextImple(identity());
+    if (_id.isEmpty()) {
+        throw new SystemException("request for context when inactive");
     }
 
+    try {
+    System.out.println("DemoHLS.context "+ UserActivityFactory.userActivity().activityId());
+    } catch (Exception ex) {
+        ex.printStackTrace();
+    }
+
+	return new DemoSOAPContextImple(identity() + "_" + _id.size());
+    }
+
     private int _failPoint;
     
 }

Modified: labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/WSASTestSuite.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/WSASTestSuite.java	2008-03-13 11:55:06 UTC (rev 18919)
+++ labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/WSASTestSuite.java	2008-03-13 12:02:04 UTC (rev 18920)
@@ -39,10 +39,8 @@
         addTest(new junit.framework.TestSuite(com.arjuna.wsas.tests.junit.basic.Suspend.class));
         addTest(new junit.framework.TestSuite(com.arjuna.wsas.tests.junit.basic.Timeout.class));
         // wsas hls tests
-        // this test fails because the deployment context factory code has changed
-        //addTest(new junit.framework.TestSuite(com.arjuna.wsas.tests.junit.hls.Context1.class));
-        // this test fails because the deployment context factory code has changed
-        //addTest(new junit.framework.TestSuite(com.arjuna.wsas.tests.junit.hls.Context2.class));
+        addTest(new junit.framework.TestSuite(com.arjuna.wsas.tests.junit.hls.Context1.class));
+        addTest(new junit.framework.TestSuite(com.arjuna.wsas.tests.junit.hls.Context2.class));
         addTest(new junit.framework.TestSuite(com.arjuna.wsas.tests.junit.hls.Service.class));
     }
 }
\ No newline at end of file

Modified: labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/junit/hls/Context1.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/junit/hls/Context1.java	2008-03-13 11:55:06 UTC (rev 18919)
+++ labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/junit/hls/Context1.java	2008-03-13 12:02:04 UTC (rev 18920)
@@ -40,10 +40,12 @@
 import com.arjuna.mw.wsas.context.Context;
 import com.arjuna.mw.wsas.context.DeploymentContext;
 import com.arjuna.mw.wsas.context.DeploymentContextFactory;
+import com.arjuna.mw.wsas.context.ContextManager;
 import com.arjuna.mw.wsas.context.soap.SOAPContext;
 import com.arjuna.mwlabs.wsas.util.XMLUtils;
 import com.arjuna.wsas.tests.DemoHLS;
 import com.arjuna.wsas.tests.WSASTestUtils;
+import com.arjuna.wsas.tests.DemoSOAPContextImple;
 import junit.framework.TestCase;
 
 /**
@@ -65,8 +67,9 @@
 	    ActivityManagerFactory.activityManager().addHLS(demoHLS);
 	    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
 	    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
-	    org.w3c.dom.Document factory = docBuilder.newDocument();
-	    org.w3c.dom.Element root = factory.createElement("Context1-test");
+	    org.w3c.dom.Document doc = docBuilder.newDocument();
+	    org.w3c.dom.Element root = doc.createElement("Context1-test");
+        doc.appendChild(root);
 	    
 	    ua.start();
 	    
@@ -76,46 +79,64 @@
 	    
 	    System.out.println("Started: "+ua.activityName()+"\n");
 
-        // this no longer works because DeploymentContextFactory has changed
-        DeploymentContext manager = DeploymentContextFactory.deploymentContext();
-	    Context theContext = manager.context();
+        ContextManager contextManager = new ContextManager();
+        Context[] contexts = contextManager.contexts();
+        Context theContext = null;
 
+        for (int i = 0; i < contexts.length; i++) {
+            if (contexts[i] != null) {
+                theContext = contexts[i];
+                break;
+            }
+        }
+
+        if (theContext == null) {
+            fail("Demo context not found");
+        }
+
+        if (!(theContext instanceof DemoSOAPContextImple)) {
+            fail("Demo context not found");
+        }
+
         ((SOAPContext)theContext).serialiseToElement(root);
 	    
-	    org.w3c.dom.Document doc = docBuilder.newDocument();
-	    doc.appendChild(root);
-	    
-	    System.out.println(XMLUtils.writeToString(doc));
+        System.out.println("Context is " + root.getTextContent());
 
 	    ua.end();
 
 	    System.out.println("\nFinished child activity.\n");
 
-	    theContext = manager.context();
+        contexts = contextManager.contexts();
+        theContext = null;
 
-	    root = factory.createElement("Context1-test");
+        for (int i = 0; i < contexts.length; i++) {
+            if (contexts[i] != null) {
+                theContext = contexts[i];
+                break;
+            }
+        }
 
+        if (theContext == null) {
+            fail("Demo context not found");
+        }
+
+        if (!(theContext instanceof DemoSOAPContextImple)) {
+            fail("Demo context not found");
+        }
+
+        doc = docBuilder.newDocument();
+	    root = doc.createElement("Context1-test");
+        doc.appendChild(root);
+
+
         ((SOAPContext)theContext).serialiseToElement(root);
 	    
-	    doc = docBuilder.newDocument();
-	    doc.appendChild(root);
+        System.out.println("Context is " + root.getTextContent());
 
-	    System.out.println(XMLUtils.writeToString(doc));
-
 	    ua.end();
 
 	    System.out.println("\nFinished parent activity.\n");
 
-	    theContext = manager.context();
-
-	    root = factory.createElement("Context1-test");
-
-        ((SOAPContext)theContext).serialiseToElement(root);
-	    
-	    doc = docBuilder.newDocument();
-	    doc.appendChild(root);
-
-	    System.out.println(XMLUtils.writeToString(doc));
 	}
 	catch (Exception ex)
 	{

Modified: labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/junit/hls/Context2.java
===================================================================
--- labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/junit/hls/Context2.java	2008-03-13 11:55:06 UTC (rev 18919)
+++ labs/jbosstm/trunk/XTS/WSAS/tests/classes/com/arjuna/wsas/tests/junit/hls/Context2.java	2008-03-13 12:02:04 UTC (rev 18920)
@@ -40,11 +40,13 @@
 import com.arjuna.mw.wsas.context.Context;
 import com.arjuna.mw.wsas.context.DeploymentContext;
 import com.arjuna.mw.wsas.context.DeploymentContextFactory;
+import com.arjuna.mw.wsas.context.ContextManager;
 import com.arjuna.mw.wsas.context.soap.SOAPContext;
 import com.arjuna.mwlabs.wsas.util.XMLUtils;
 import com.arjuna.wsas.tests.DemoHLS;
 import com.arjuna.wsas.tests.FailureHLS;
 import com.arjuna.wsas.tests.WSASTestUtils;
+import com.arjuna.wsas.tests.DemoSOAPContextImple;
 import junit.framework.TestCase;
 
 /**
@@ -61,7 +63,7 @@
     {
         UserActivity ua = UserActivityFactory.userActivity();
         DemoHLS demoHLS = new DemoHLS();
-        FailureHLS failureHLS = new FailureHLS();
+        FailureHLS failureHLS = new FailureHLS(); // this constructor means it will lnto fail
     try
 	{
 	    ActivityManagerFactory.activityManager().addHLS(demoHLS);
@@ -69,9 +71,10 @@
 
 	    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
 	    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
-	    org.w3c.dom.Document factory = docBuilder.newDocument();
-	    org.w3c.dom.Element root = factory.createElement("Context2-test");
-	    
+	    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());
@@ -80,46 +83,79 @@
 	    
 	    System.out.println("Started: "+ua.activityName()+"\n");
 
-        // this no longer works because DeploymentContextFactory has changed
-	    DeploymentContext manager = DeploymentContextFactory.deploymentContext();
-	    Context theContext = manager.context();
+        ContextManager contextManager = new ContextManager();
+        Context[] contexts = contextManager.contexts();
+        Context theContext1 = null;
+        Context theContext2 = null;
+        int numContexts = (contexts != null ? contexts.length : 0);
 
-        ((SOAPContext)theContext).serialiseToElement(root);
-	    
-	    org.w3c.dom.Document doc = docBuilder.newDocument();
-	    doc.appendChild(root);
+        for (int i = 0; i < numContexts; i++) {
+            if (contexts[i] != null) {
+                if (theContext1 == null) {
+                    theContext1 = contexts[i];
+                } else {
+                    theContext2 = contexts[i];
+                    break;
+                }
+            }
+        }
 
-	    System.out.println(XMLUtils.writeToString(doc));
-	    
+        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");
 
-	    theContext = manager.context();
+	    contexts = contextManager.contexts();
+        theContext1 = null;
+        theContext2 = null;
+        numContexts = (contexts != null ? contexts.length : 0);
 
-	    root = factory.createElement("Context2-test");
+        for (int i = 0; i < numContexts; i++) {
+            if (contexts[i] != null) {
+                if (theContext1 == null) {
+                    theContext1 = contexts[i];
+                } else {
+                    theContext2 = contexts[i];
+                    break;
+                }
+            }
+        }
 
-        ((SOAPContext)theContext).serialiseToElement(root);
-	    
-	    doc = docBuilder.newDocument();
-	    doc.appendChild(root);
-	    
-	    System.out.println(XMLUtils.writeToString(doc));
+        if (theContext1 == null || theContext2 == null) {
+            fail("Demo contexts not found");
+        }
 
-	    ua.end();
+        if (!(theContext1 instanceof DemoSOAPContextImple) ||
+                !(theContext1 instanceof DemoSOAPContextImple)) {
+            fail("Demo contexts not found");
+        }
 
-	    System.out.println("\nFinished parent activity.\n");
+        doc = docBuilder.newDocument();
+	    root = doc.createElement("Context2-test");
+        doc.appendChild(root);
 
-	    theContext = manager.context();
 
-	    root = factory.createElement("Context2-test");
+        ((SOAPContext)theContext1).serialiseToElement(root);
+        ((SOAPContext)theContext2).serialiseToElement(root);
 
-        ((SOAPContext)theContext).serialiseToElement(root);
-	    
-	    doc = docBuilder.newDocument();
-	    doc.appendChild(root);
-	    
-	    System.out.println(XMLUtils.writeToString(doc));
+        System.out.println("Context is " + root.getTextContent());
+
+	    ua.end();
+
+	    System.out.println("\nFinished parent activity.\n");
 	}
     catch (Exception ex)
     {




More information about the jboss-svn-commits mailing list