[jbpm-commits] JBoss JBPM SVN: r2581 - in jbpm3/trunk/modules/core/src: test/java/org/jbpm/jpdl/par and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Oct 22 09:25:54 EDT 2008
Author: tom.baeyens at jboss.com
Date: 2008-10-22 09:25:54 -0400 (Wed, 22 Oct 2008)
New Revision: 2581
Added:
jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java
Modified:
jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/Delegation.java
Log:
[JBPM-1448] Added a context classloader test
Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/Delegation.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/Delegation.java 2008-10-22 13:08:30 UTC (rev 2580)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/instantiation/Delegation.java 2008-10-22 13:25:54 UTC (rev 2581)
@@ -133,7 +133,7 @@
Object newInstance = null;
// find the classloader to use
- ClassLoader classLoader = JbpmConfiguration.getProcessClassLoader(processDefinition);
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
// load the class that needs to be instantiated
Class clazz = null;
Added: 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 (rev 0)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java 2008-10-22 13:25:54 UTC (rev 2581)
@@ -0,0 +1,98 @@
+package org.jbpm.jpdl.par;
+
+import org.jbpm.AbstractJbpmTestCase;
+import org.jbpm.JbpmConfiguration;
+import org.jbpm.JbpmContext;
+import org.jbpm.graph.def.ActionHandler;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ExecutionContext;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.instantiation.ProcessClassLoader;
+
+
+public class ProcessClassLoaderTest extends AbstractJbpmTestCase {
+
+ public static class TestContextClassLoader extends ClassLoader {
+ public TestContextClassLoader(ClassLoader parent) {
+ super(parent);
+ }
+ protected Class< ? > findClass(String name) throws ClassNotFoundException {
+ if ("TestContextClassLoader-knows-where-to-find-ContextLoadedAction".equals(name)) {
+ return getParent().loadClass(ContextLoadedAction.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;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ contextLoadedActionInvocations = 0;
+ originalClassLoader = Thread.currentThread().getContextClassLoader();
+ }
+
+ public void testContextClassLoader() {
+ JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
+ "<jbpm-configuration>" +
+ " <string name='jbpm.classLoader' value='context' />" +
+ "</jbpm-configuration>"
+ );
+
+ JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
+ try {
+ TestContextClassLoader testContextClassLoader = new TestContextClassLoader(originalClassLoader);
+ Thread.currentThread().setContextClassLoader(testContextClassLoader);
+
+ ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
+ "<process-definition>" +
+ " <start-state name='start'>" +
+ " <transition to='state'>" +
+ " <action class='TestContextClassLoader-knows-where-to-find-ContextLoadedAction' />" +
+ " </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);
+ assertSame(testContextClassLoader, Thread.currentThread().getContextClassLoader());
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ jbpmContext.close();
+ }
+ }
+
+ // 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
+}
More information about the jbpm-commits
mailing list