[jbpm-commits] JBoss JBPM SVN: r2601 - jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Oct 23 09:57:46 EDT 2008


Author: camunda
Date: 2008-10-23 09:57:46 -0400 (Thu, 23 Oct 2008)
New Revision: 2601

Modified:
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessArchiveDeploymentDbTest.java
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java
Log:
added class loading test cases and TODO

Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessArchiveDeploymentDbTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessArchiveDeploymentDbTest.java	2008-10-23 13:39:39 UTC (rev 2600)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessArchiveDeploymentDbTest.java	2008-10-23 13:57:46 UTC (rev 2601)
@@ -299,7 +299,13 @@
     assertEquals(ProcessClassLoader.class, resourceActionInstance.getClass().getClassLoader().getClass());
     resourceActionInstance = null;
   }
+  
+  // TODO: do the same thing when using the context class loader
+  // and check, that the hierarchy is correct ProcessClassLoader -> ContextClassLoader
+  // and not ProcessClassLoader -> ProcessClassLoader -> ContextClassLoader
+  // assertEquals(Thread.currentThread().getContextClassLoader(), resourceActionInstance.getClass().getClassLoader().getParent());
 
+
   private static void addEntry(ZipOutputStream zipOutputStream, String entryName, String resource) throws IOException
   {
     InputStream inputStream = ClassLoaderUtil.getStream(resource);

Modified: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java	2008-10-23 13:39:39 UTC (rev 2600)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java	2008-10-23 13:57:46 UTC (rev 2601)
@@ -7,9 +7,17 @@
 import org.jbpm.graph.def.ProcessDefinition;
 import org.jbpm.graph.exe.ExecutionContext;
 import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.instantiation.ConfigurableClassloadersTest;
 import org.jbpm.instantiation.ProcessClassLoader;
 
-
+/**
+ * Test case for ProcessClassLoader hierarchy and setting the ContextClassLoader correctly.
+ * 
+ * Relates to {@link ConfigurableClassloadersTest}.
+ * 
+ * @author Tom Baeyens, bernd.ruecker at camunda.com
+ *
+ */
 public class ProcessClassLoaderTest extends AbstractJbpmTestCase {
   
   public static class TestContextClassLoader extends ClassLoader {
@@ -20,23 +28,13 @@
       if ("TestContextClassLoader-knows-where-to-find-ContextLoadedAction".equals(name)) {
         return getParent().loadClass(ContextLoadedAction.class.getName());
       }
+      else if ("TestContextClassLoader-knows-where-to-find-ContextLoadedExceptionAction".equals(name)) {
+          return getParent().loadClass(ContextLoadedExceptionAction.class.getName());
+        }
       return null;
     }
   }
 
-  public static class ContextLoadedAction implements ActionHandler {
-    public void execute(ExecutionContext executionContext) throws Exception {
-      ClassLoader processClassLoader = Thread.currentThread().getContextClassLoader();
-      assertSame(ProcessClassLoader.class, processClassLoader.getClass());
-      ClassLoader testContextClassLoader = processClassLoader.getParent();
-      assertSame(TestContextClassLoader.class, testContextClassLoader.getClass());
-      
-      assertSame(originalClassLoader, testContextClassLoader.getParent());
-      
-      contextLoadedActionInvocations++;
-    }
-  }
-  
   static int contextLoadedActionInvocations = 0;
   static ClassLoader originalClassLoader = null; 
   
@@ -46,7 +44,28 @@
     originalClassLoader = Thread.currentThread().getContextClassLoader();
   }
 
+  /**
+   * test using the context class loader for jbpm. Setting an own context class loader,
+   * so we know if it was used.
+   * 
+   * Classloading hierarchy should be
+   * ProcessClassloader -> TestContextClassLoader -> Thread.currentContextClassLoader
+   */
+  public static class ContextLoadedAction implements ActionHandler {
+	  public void execute(ExecutionContext executionContext) throws Exception {
+		  ClassLoader processClassLoader = Thread.currentThread().getContextClassLoader();
+		  assertSame(ProcessClassLoader.class, processClassLoader.getClass());
+		  
+		  ClassLoader testContextClassLoader = processClassLoader.getParent();
+		  assertSame(TestContextClassLoader.class, testContextClassLoader.getClass());
+		  
+		  assertSame(originalClassLoader, testContextClassLoader.getParent());
+		  
+		  contextLoadedActionInvocations++;
+	  }
+  }
   public void testContextClassLoader() {
+		  
     JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
       "<jbpm-configuration>" +
       "  <string name='jbpm.classLoader' value='context' />" +
@@ -84,15 +103,119 @@
       jbpmContext.close();
     }
   }
+  
+  /**
+   * a second test use the default configuration and verify the 
+   * classloader hierarchy inside of the action.  The action class should 
+   * be referenced properly.  No test context classloader should be installed.
+   * The hierarchy in the action should be:
+   *   ProcessClassLoader ---> ClassLoader.getSystemClassLoader()
+   */
+  public static class DefaultLoadedAction implements ActionHandler {
+		public void execute(ExecutionContext executionContext) throws Exception {
+			ClassLoader processClassLoader = Thread.currentThread()
+					.getContextClassLoader();
+			assertSame(ProcessClassLoader.class, processClassLoader.getClass());
 
-  // TODO a second test should use the default configuration and verify the 
-  // classloader hierarchy inside of the action.  The action class should 
-  // be referenced properly.  No test context classloader should be installed.
-  // The hierarchy in the action should be:
-  //   ProcessClassLoader ---> ClassLoader.getSystemClassLoader()
-  
-  // TODO a third test should set the testcontextClassLoader in the test and then 
-  // let the action throw an exception. Then it should be verified that the 
-  // original classloader is still restored correctly.  Easiest is to start 
-  // from a copy of the testContextClassLoader
+			assertSame(originalClassLoader, processClassLoader.getParent());
+			assertSame(ClassLoader.getSystemClassLoader(), processClassLoader.getParent());
+
+			contextLoadedActionInvocations++;
+		}
+	}  
+  public void testDefaultClassLoader() {
+	    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
+	      "<jbpm-configuration>" +
+	      "  <string name='jbpm.classLoader' value='jbpm' />" +
+	      "</jbpm-configuration>"
+	    );
+	    
+	    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+	    try {
+	      ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
+	        "<process-definition>" +
+	        "  <start-state name='start'>" +
+	        "    <transition to='state'>" +
+	        "      <action class='org.jbpm.jpdl.par.ProcessClassLoaderTest$DefaultLoadedAction' />" +
+	        "    </transition>" +
+	        "  </start-state>" +
+	        "  <state name='state'>" +
+	        "    <transition to='end'/>" +
+	        "  </state>" +
+	        "  <end-state name='end'/>" +
+	        "</process-definition>"
+	      );
+	  
+	      // create the process instance
+	      ProcessInstance processInstance = new ProcessInstance(processDefinition);
+	      processInstance.signal();
+	      	      
+	      assertEquals(1, contextLoadedActionInvocations);	      
+	    } finally {
+	      Thread.currentThread().setContextClassLoader(originalClassLoader);
+	      jbpmContext.close();
+	    }
+	  }
+
+  /**
+   * a third test should set the testcontextClassLoader in the test and then 
+   * let the action throw an exception. Then it should be verified that the 
+   * original classloader is still restored correctly.  Easiest is to start 
+   * from a copy of the testContextClassLoader
+   */
+  public static class ContextLoadedExceptionAction implements ActionHandler {
+	  public void execute(ExecutionContext executionContext) throws Exception {
+		  ClassLoader processClassLoader = Thread.currentThread().getContextClassLoader();
+		  assertSame(ProcessClassLoader.class, processClassLoader.getClass());
+		  
+		  ClassLoader testContextClassLoader = processClassLoader.getParent();
+		  assertSame(TestContextClassLoader.class, testContextClassLoader.getClass());
+		  
+		  assertSame(originalClassLoader, testContextClassLoader.getParent());
+		  
+		  contextLoadedActionInvocations++;
+		  
+		  throw new Exception("simulate exception");
+	  }
+  }
+  public void testContextClassLoaderException() {
+	    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
+	      "<jbpm-configuration>" +
+	      "  <string name='jbpm.classLoader' value='context' />" +
+	      "</jbpm-configuration>"
+	    );
+	    
+	    JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+	    TestContextClassLoader testContextClassLoader = new TestContextClassLoader(originalClassLoader);
+	    try {
+	      Thread.currentThread().setContextClassLoader(testContextClassLoader);
+	    
+	      ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
+	        "<process-definition>" +
+	        "  <start-state name='start'>" +
+	        "    <transition to='state'>" +
+	        "      <action class='TestContextClassLoader-knows-where-to-find-ContextLoadedExceptionAction' />" +
+	        "    </transition>" +
+	        "  </start-state>" +
+	        "  <state name='state'>" +
+	        "    <transition to='end'/>" +
+	        "  </state>" +
+	        "  <end-state name='end'/>" +
+	        "</process-definition>"
+	      );
+	  
+	      // create the process instance
+	      ProcessInstance processInstance = new ProcessInstance(processDefinition);
+	      processInstance.signal();
+	      
+	    } catch(Exception ex) {
+	    	assertEquals(1, contextLoadedActionInvocations);
+	    	assertEquals("simulate exception", ex.getMessage());
+	    	assertSame(testContextClassLoader, Thread.currentThread().getContextClassLoader());
+	    	
+	    } finally {
+	      Thread.currentThread().setContextClassLoader(originalClassLoader);
+	      jbpmContext.close();
+	    }
+	  }  
 }




More information about the jbpm-commits mailing list