[jbpm-commits] JBoss JBPM SVN: r6422 - in jbpm4/trunk/modules: test-db/src/test/java/org/jbpm/test/variables and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jun 17 13:22:46 EDT 2010


Author: swiderski.maciej
Date: 2010-06-17 13:22:46 -0400 (Thu, 17 Jun 2010)
New Revision: 6422

Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetHistoryVariablesCmd.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java
Log:
JBPM-2506: refactored to be consistent with executionService variable operations and to prevent NPE when wrong data are given

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetHistoryVariablesCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetHistoryVariablesCmd.java	2010-06-17 17:15:22 UTC (rev 6421)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetHistoryVariablesCmd.java	2010-06-17 17:22:46 UTC (rev 6422)
@@ -26,6 +26,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.jbpm.api.JbpmException;
 import org.jbpm.api.cmd.Environment;
 import org.jbpm.api.history.HistoryProcessInstance;
 import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
@@ -48,6 +49,12 @@
   public GetHistoryVariablesCmd(String processInstanceId, Set<String> variableNames) {
     super();
     this.processInstanceId = processInstanceId;
+    if (processInstanceId==null) {
+      throw new JbpmException("processInstanceId is null");
+    }
+    if (variableNames==null) {
+      throw new JbpmException("variableNames is null");
+    }
     this.variableNames = variableNames;
   }
 
@@ -56,7 +63,9 @@
     HistoryProcessInstanceQueryImpl queryImpl = new HistoryProcessInstanceQueryImpl();
     
     HistoryProcessInstance historyProcessInstance = queryImpl.processInstanceId(processInstanceId).uniqueResult();
-    
+    if (historyProcessInstance==null) {
+      throw new JbpmException("process instance "+processInstanceId+" doesn't exist in history");
+    }
     Iterator<HistoryVariableImpl> variables = ((HistoryProcessInstanceImpl) historyProcessInstance).getHistoryVariables().iterator();
     
     Map<String, Object> variableMap = new HashMap<String, Object>();
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java	2010-06-17 17:15:22 UTC (rev 6421)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java	2010-06-17 17:22:46 UTC (rev 6422)
@@ -199,4 +199,68 @@
     String historyValue = (String) historyService.getVariable("var.one", "test");
     assertEquals(variableValue.toString(), historyValue);
   }
+  public void testDeclaredVariableWithHistoryWrongProcessInstanceId() {
+    deployJpdlXmlString("<process name='var'>"
+        + "  <variable name='test' type='string' init-expr='history' history='true'/>"
+        + "  <start name='a'>"
+        + "    <transition to='b' />"
+        + "  </start>"
+        + "  <state name='b'/>"
+        + "</process>");
+
+      executionService.startProcessInstanceByKey("var", "one");
+
+      Set<String> variableNames = executionService.getVariableNames("var.one");
+      assertEquals(1, variableNames.size());
+      assertEquals("test", variableNames.iterator().next());
+
+      String executionValue = (String) executionService.getVariable("var.one", "test");
+      assertEquals("history", executionValue);
+
+      Set<String> historyVariables = historyService.getVariableNames("var.one");
+      assertEquals(1, historyVariables.size());
+      assertEquals("test", historyVariables.iterator().next());
+
+      String wrongProcessInstanceId = "var.one.1";
+      try {
+        
+        historyService.getVariable(wrongProcessInstanceId, "test");
+        fail("should fail since it uses wrong process instance id");
+      } catch (Exception e) {
+        assertEquals("process instance "+wrongProcessInstanceId+" doesn't exist in history", e.getMessage());
+      }
+    }
+  
+  public void testDeclaredVariableWithHistoryWrongProcess() {
+    deployJpdlXmlString("<process name='var'>"
+        + "  <variable name='test' type='string' init-expr='history' history='true'/>"
+        + "  <start name='a'>"
+        + "    <transition to='b' />"
+        + "  </start>"
+        + "  <state name='b'/>"
+        + "</process>");
+
+      executionService.startProcessInstanceByKey("var", "one");
+
+      Set<String> variableNames = executionService.getVariableNames("var.one");
+      assertEquals(1, variableNames.size());
+      assertEquals("test", variableNames.iterator().next());
+
+      String executionValue = (String) executionService.getVariable("var.one", "test");
+      assertEquals("history", executionValue);
+      try {
+        
+        historyService.getVariables(null, null);
+        fail("should fail since process instance id is null");
+      } catch (Exception e) {
+        assertEquals("processInstanceId is null", e.getMessage());
+      }
+      try {
+        
+        historyService.getVariables("var.one", null);
+        fail("should fail since variable names set is null");
+      } catch (Exception e) {
+        assertEquals("variableNames is null", e.getMessage());
+      }
+    }
 }



More information about the jbpm-commits mailing list