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

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Oct 8 07:09:58 EDT 2008


Author: camunda
Date: 2008-10-08 07:09:58 -0400 (Wed, 08 Oct 2008)
New Revision: 2507

Added:
   jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/NotInParAction.java
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/ProcessLoadedActionHandler.java
Log:
JBPM-1404
added testcase for uncorrect ProcessClassLoader (in the area of https://jira.jboss.org/jira/browse/JBPM-1404)

Added: jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/NotInParAction.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/NotInParAction.java	                        (rev 0)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/NotInParAction.java	2008-10-08 11:09:58 UTC (rev 2507)
@@ -0,0 +1,20 @@
+package org.jbpm.jpdl.par;
+
+import org.jbpm.graph.def.ActionHandler;
+import org.jbpm.graph.exe.ExecutionContext;
+
+public class NotInParAction implements ActionHandler {
+
+  public void execute(ExecutionContext executionContext) throws Exception {
+    // create new action without specifying classloader
+    // should use the ProcessClassLoader specified as ContextClassLoader
+    // this can be verified later on
+    ProcessArchiveDeploymentDbTest.resourceActionInstance = 
+      Thread.currentThread().getContextClassLoader().loadClass("org.jbpm.jpdl.par.ResourceAction").newInstance();
+
+    // TODO: why doesn't the following work? I thought it is delegated to 
+    // the context class loader? But it seems not that easy?
+    // ProcessArchiveDeploymentDbTest.resourceActionInstance = new ResourceAction();
+  }
+
+}

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-08 11:06:20 UTC (rev 2506)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessArchiveDeploymentDbTest.java	2008-10-08 11:09:58 UTC (rev 2507)
@@ -23,6 +23,7 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -35,6 +36,7 @@
 import org.jbpm.db.AbstractDbTestCase;
 import org.jbpm.graph.def.ProcessDefinition;
 import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.instantiation.ProcessClassLoader;
 import org.jbpm.taskmgmt.def.Task;
 import org.jbpm.taskmgmt.def.TaskMgmtDefinition;
 import org.jbpm.util.ClassLoaderUtil;
@@ -245,6 +247,59 @@
     resourceActionInstance = null;
   }
 
+  /**
+   * start process with action, which itselfs loads an action via "new ResourceAction()".
+   * This action is checked if it gets loaded by the ProcessClassLoader
+   * correctly (which should be set as ContextClassLoader)
+   * 
+   * TODO: doesn't yet test the right thing, looks like the Action
+   * first tries its own classloader (which is a ProcessClassLoader)
+   * and thus it works even without the ContextClassLoader set.
+   */
+  public void testProcessClassLoaderAsContextClassLoader() throws Exception {
+    // create a process archive file and save it to disk
+    String fileName = getTestClassesDir() + "/resource.process";
+    FileOutputStream fileOutputStream = new FileOutputStream(fileName);
+    ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
+    addEntry(zipOutputStream, "processdefinition.xml", "org/jbpm/jpdl/par/classloadingprocess.xml");
+    addEntry(zipOutputStream, "classes/org/jbpm/jpdl/par/ResourceAction.class", "org/jbpm/jpdl/par/ResourceAction.class");
+    addEntry(zipOutputStream, "classes/org/jbpm/jpdl/par/ProcessLoadedActionHandler.class", "org/jbpm/jpdl/par/ProcessLoadedActionHandler.class");
+    zipOutputStream.close();
+
+    // deploy the saved process file
+    ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(fileName));
+    ProcessDefinition processDefinition = ProcessDefinition.parseParZipInputStream(zipInputStream);
+  
+    // rename the resources to force usage of the process classloader by preventing that they will be found in the test classpath
+    String classOriginalName1 = getTestClassesDir() + "org/jbpm/jpdl/par/ResourceAction.class";
+    String classTmpName1 = classOriginalName1 + ".hiddenFromTestClasspath";
+    String classOriginalName2 = getTestClassesDir() + "org/jbpm/jpdl/par/ProcessLoadedActionHandler.class";
+    String classTmpName2 = classOriginalName2 + ".hiddenFromTestClasspath";
+
+    // move the files
+    assertTrue(new File(classOriginalName1).renameTo(new File(classTmpName1)));
+    assertTrue(new File(classOriginalName2).renameTo(new File(classTmpName2)));
+
+    try {
+      jbpmContext.deployProcessDefinition(processDefinition);
+      try {
+        newTransaction();
+
+        ProcessInstance processInstance = jbpmContext.newProcessInstance("the deployable process");
+        processInstance.signal();
+      } finally {
+        jbpmContext.getGraphSession().deleteProcessDefinition(processDefinition.getId());
+      }
+    } finally {
+      // put the files back into original position
+      new File(classTmpName1).renameTo(new File(classOriginalName1));
+      new File(classTmpName2).renameTo(new File(classOriginalName2));
+    }
+    
+    assertEquals(ProcessClassLoader.class, resourceActionInstance.getClass().getClassLoader().getClass());
+    resourceActionInstance = null;
+  }
+
   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/ProcessLoadedActionHandler.java
===================================================================
--- jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessLoadedActionHandler.java	2008-10-08 11:06:20 UTC (rev 2506)
+++ jbpm3/trunk/modules/core/src/test/java/org/jbpm/jpdl/par/ProcessLoadedActionHandler.java	2008-10-08 11:09:58 UTC (rev 2507)
@@ -32,5 +32,10 @@
     // notify the ProcessArchiveClassLoadingTest that this 
     // class has been executed
     ProcessArchiveClassLoadingDbTest.isLoadedActionHandlerExecuted = true;
+    
+    // create new action without specifying classloader
+    // should use the ProcessClassLoader specified as ContextClassLoader
+    // this can be verified later on
+    new NotInParAction().execute(executionContext);
   }
 }




More information about the jbpm-commits mailing list