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

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Feb 11 11:32:49 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-02-11 11:32:49 -0500 (Wed, 11 Feb 2009)
New Revision: 3837

Modified:
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java
Log:
[JBPM-1976] Bad usage of ClassLoader.loadClass() under JDK 6

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	2009-02-11 16:01:39 UTC (rev 3836)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessClassLoaderTest.java	2009-02-11 16:32:49 UTC (rev 3837)
@@ -19,35 +19,51 @@
  * @author Tom Baeyens, bernd.ruecker at camunda.com
  *
  */
-public class ProcessClassLoaderTest extends AbstractJbpmTestCase {
-  
-  public static class TestContextClassLoader extends ClassLoader {
-    public TestContextClassLoader(ClassLoader parent) {
+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 Class.forName(ContextLoadedAction.class.getName(), false, getParent());
-      }
-      else if ("TestContextClassLoader-knows-where-to-find-ContextLoadedExceptionAction".equals(name)) {
-        return Class.forName(ContextLoadedExceptionAction.class.getName(), false, getParent());
-      }
-      return null;
+
+    protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
+    {
+      //System.out.println("loadClass: " + name + ",resolve=" + resolve);
+      return super.loadClass(name, resolve);
     }
+
+    @Override
+    public Class<?> loadClass(String name) throws ClassNotFoundException
+    {
+      //System.out.println("loadClass: " + name);
+      return super.loadClass(name);
+    }
+
+    protected Class<?> findClass(String name) throws ClassNotFoundException
+    {
+      //System.out.println("findClass: " + name);
+      return super.findClass(name);
+    }
   }
 
   static int contextLoadedActionInvocations = 0;
-  static ClassLoader originalClassLoader = null; 
-  
-  protected void setUp() throws Exception {
+  static ClassLoader originalClassLoader = null;
+
+  protected void setUp() throws Exception
+  {
     super.setUp();
     contextLoadedActionInvocations = 0;
     originalClassLoader = Thread.currentThread().getContextClassLoader();
   }
 
-  public static class DefaultLoadedAction implements ActionHandler {
+  public static class DefaultLoadedAction implements ActionHandler
+  {
+    private static final long serialVersionUID = 1L;
 
-    public void execute(ExecutionContext executionContext) throws Exception {
+    public void execute(ExecutionContext executionContext) throws Exception
+    {
       ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
       assertSame(ProcessClassLoader.class, contextClassLoader.getClass());
 
@@ -57,35 +73,37 @@
       contextLoadedActionInvocations++;
     }
   }
-  
-  /** DOES NOT configure usage of the context classloader.  So this tests the default (backwards compatible) behaviour.    
-   * so the classloading hierarchy of DefaultLoadedAction should be
-   * ProcessClassloader -> jbpm-lib classloader */
-  public void testDefaultClassLoader() {
-    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>" +
-      "</process-definition>"
-    );
 
+  /*
+   *  DOES NOT configure usage of the context classloader. So this tests the default (backwards compatible) behaviour. so the classloading hierarchy of
+   * DefaultLoadedAction should be ProcessClassloader -> jbpm-lib classloader
+   */
+  public void testDefaultClassLoader()
+  {
+    ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" 
+        + "  <start-state name='start'>" 
+        + "    <transition to='state'>"
+        + "      <action class='" + DefaultLoadedAction.class.getName() + "' />" 
+        + "    </transition>" 
+        + "  </start-state>"
+        + "  <state name='state'>" 
+        + "    <transition to='end'/>" 
+        + "  </state>" 
+        + "</process-definition>");
+
     // create the process instance
     ProcessInstance processInstance = new ProcessInstance(processDefinition);
     processInstance.signal();
-            
-    assertEquals(1, contextLoadedActionInvocations);        
+
+    assertEquals(1, contextLoadedActionInvocations);
   }
-  
 
-  public static class ContextLoadedAction implements ActionHandler {
+  public static class ContextLoadedAction implements ActionHandler
+  {
+    private static final long serialVersionUID = 1L;
 
-    public void execute(ExecutionContext executionContext) throws Exception {
+    public void execute(ExecutionContext executionContext) throws Exception
+    {
       ClassLoader processClassLoader = Thread.currentThread().getContextClassLoader();
       assertSame(ProcessClassLoader.class, processClassLoader.getClass());
 
@@ -98,106 +116,112 @@
     }
   }
 
-  /** configures usage of the context classloader   
-   * so the classloading hierarchy of ContextLoadedAction should be
-   * ProcessClassloader -> TestContextClassLoader -> Thread.currentContextClassLoader */
-  public void testContextClassLoader() {
-      
-    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString(
-      "<jbpm-configuration>" +
-      "  <string name='jbpm.classLoader' value='context' />" +
-      "</jbpm-configuration>"
-    );
-    
+  /*
+   *  configures usage of the context classloader so the classloading hierarchy of ContextLoadedAction should be ProcessClassloader -> TestContextClassLoader ->
+   * Thread.currentContextClassLoader
+   */
+  public void testContextClassLoader()
+  {
+
+    JbpmConfiguration jbpmConfiguration = JbpmConfiguration.parseXmlString("<jbpm-configuration>" 
+        + "  <string name='jbpm.classLoader' value='context' />"
+        + "</jbpm-configuration>");
+
     JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
-    try {
+    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>" +
-        "</process-definition>"
-      );
-  
+
+      ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" 
+          + "  <start-state name='start'>"
+          + "    <transition to='state'>" 
+          + "      <action class='" + ContextLoadedAction.class.getName() + "' />" 
+          + "    </transition>"
+          + "  </start-state>" 
+          + "  <state name='state'>" 
+          + "    <transition to='end'/>" 
+          + "  </state>" 
+          + "</process-definition>");
+
       // create the process instance
       ProcessInstance processInstance = new ProcessInstance(processDefinition);
       processInstance.signal();
-      
+
       assertEquals(1, contextLoadedActionInvocations);
       assertSame(testContextClassLoader, Thread.currentThread().getContextClassLoader());
-      
-    } finally {
+
+    }
+    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
+  /*
+   * 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 {
+  public static class ContextLoadedExceptionAction implements ActionHandler
+  {
+    private static final long serialVersionUID = 1L;
+
+    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>"
-    );
-    
+
+  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 {
+    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>" +
-        "</process-definition>"
-      );
-  
+
+      ProcessDefinition processDefinition = ProcessDefinition.parseXmlString("<process-definition>" 
+          + "  <start-state name='start'>"
+          + "    <transition to='state'>" 
+          + "      <action class='" + ContextLoadedExceptionAction.class.getName() + "' />"
+          + "    </transition>" 
+          + "  </start-state>" 
+          + "  <state name='state'>" 
+          + "    <transition to='end'/>" 
+          + "  </state>" 
+          + "</process-definition>");
+
       // create the process instance
       ProcessInstance processInstance = new ProcessInstance(processDefinition);
       processInstance.signal();
-      
-    } catch(Exception ex) {
+
+    }
+    catch (Exception ex)
+    {
       assertEquals(1, contextLoadedActionInvocations);
       assertEquals("simulate exception", ex.getMessage());
       assertSame(testContextClassLoader, Thread.currentThread().getContextClassLoader());
-      
-    } finally {
+
+    }
+    finally
+    {
       Thread.currentThread().setContextClassLoader(originalClassLoader);
       jbpmContext.close();
     }
-  }  
+  }
 }




More information about the jbpm-commits mailing list