[jbpm-commits] JBoss JBPM SVN: r6402 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/cmd and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jun 10 14:43:19 EDT 2010


Author: alex.guizar at jboss.com
Date: 2010-06-10 14:43:18 -0400 (Thu, 10 Jun 2010)
New Revision: 6402

Removed:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariable.java
Modified:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SetExecutionVariablesCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/VariablesCmd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java
Log:
JBPM-2506: reapply variable history patch

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java	2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java	2010-06-10 18:43:18 UTC (rev 6402)
@@ -104,17 +104,17 @@
    * queries that include finished process instances. */
   ProcessInstanceQuery createProcessInstanceQuery();
 
-  /** creates or overwrites a variable value on the referenced execution */
+  /** creates or overwrites a variable value in the referenced execution */
   void setVariable(String executionId, String name, Object value);
 
-  /** creates or overwrites the variable values on the referenced execution */
+  /** creates or overwrites variable values in the referenced execution */
   void setVariables(String executionId, Map<String, ?> variables);
   
-  /** creates or overwrites a variable value on the referenced execution and marks the variable to be stored in history*/
-  void setVariable(String executionId, String name, Object value, boolean historyEnabled);
+  /** creates a variable value in the referenced execution. optionally enables variable history tracking. */
+  void createVariable(String executionId, String name, Object value, boolean historyEnabled);
   
-  /** creates or overwrites the variable values on the referenced execution and marks the variables to be stored in history*/
-  void setVariables(String executionId, Map<String, ?> variables, boolean historyEnabled);
+  /** creates variable values in the referenced execution. optionally enables variable history tracking. */
+  void createVariables(String executionId, Map<String, ?> variables, boolean historyEnabled);
 
   /** retrieves a variable */
   Object getVariable(String executionId, String variableName);

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SetExecutionVariablesCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SetExecutionVariablesCmd.java	2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/SetExecutionVariablesCmd.java	2010-06-10 18:43:18 UTC (rev 6402)
@@ -24,12 +24,9 @@
 import org.jbpm.api.JbpmException;
 import org.jbpm.api.cmd.Environment;
 import org.jbpm.pvm.internal.client.ClientExecution;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
 
-
 /**
  * @author Tom Baeyens
- * @author Maciej Swiderski
  */
 public class SetExecutionVariablesCmd extends VariablesCmd<Void> {
   
@@ -46,12 +43,7 @@
 
   public Void execute(Environment environment) throws Exception {
     ClientExecution execution = getExecution(environment, executionId);
-    if (isHistoryEnabled()) {
-      ((ExecutionImpl) execution).setVariables(variables, historyEnabled);
-    } else {
-      execution.setVariables(variables);
-    }
-    
+    execution.setVariables(variables);
     return null;
   }
 

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/VariablesCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/VariablesCmd.java	2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/VariablesCmd.java	2010-06-10 18:43:18 UTC (rev 6402)
@@ -38,9 +38,7 @@
 
   protected Map<String, ?> variables;
   private Map<String, Object> internalMap;
-  protected boolean historyEnabled;
 
-
   public void addVariable(String key, Object variable) {
     if (internalMap == null) {
       if (variables != null) {
@@ -59,14 +57,6 @@
     this.variables = variables;
   }
 
-  public boolean isHistoryEnabled() {
-    return historyEnabled;
-  }
-  
-  public void setHistoryEnabled(boolean historyEnabled) {
-    this.historyEnabled = historyEnabled;
-  }
-
   protected ClientExecution getExecution(Environment environment, String executionId) {
     DbSession dbSession = environment.get(DbSession.class);
     ClientExecution execution = dbSession.findExecutionById(executionId);

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java	2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java	2010-06-10 18:43:18 UTC (rev 6402)
@@ -99,7 +99,7 @@
   }
 
   protected Variable createVariableObject(String key, Object value, String typeName, boolean isHistoryEnabled) {
-    log.debug("create variable '"+key+"' in '"+this+"' with value '"+value+"' history enabled " + isHistoryEnabled);
+    log.debug("create variable '"+key+"' in '"+this+"' with value '"+value+"'");
     
     Type type = null;
     
@@ -144,7 +144,6 @@
     variable.setHistoryEnabled(isHistoryEnabled);
     variable.setValue(value, this);
     
-    
     long dbid = DbidGenerator.getDbidGenerator().getNextId();
     variable.setDbid(dbid);
 
@@ -152,15 +151,10 @@
       HistoryEvent.fire(new VariableCreate(variable));
     }
     
-
     return variable;
   }
-  
-  public void setVariable(String key, Object value) {
-    setVariable(key, value, false);
-  }
 
-  public void setVariable(String key, Object value, boolean historyEnabled) {
+  public void setVariable(String key, Object value) {
     if (key==null) {
       throw new JbpmException("variableName is null");
     }
@@ -179,22 +173,17 @@
     if (variable!=null) {
       log.debug("updating variable '"+key+"' in '"+this+"' to value '"+value+"'");
       variable.setValue(value, this);
-
     } else if (getParentVariableScope()==null) {
-      createVariable(key, value, null, historyEnabled);
-
+      createVariable(key, value, null, false);
     } else {
-      getParentVariableScope().setVariable(key,value, historyEnabled);
+      getParentVariableScope().setVariable(key,value);
     }
   }
+
   public void setVariables(Map<String, ?> variables) {
-    setVariables(variables, false);
-  }
-  
-  public void setVariables(Map<String, ?> variables, boolean historyEnabled) {
     if (variables!=null) {
       for (Map.Entry<String, ?> entry : variables.entrySet()) {
-        setVariable(entry.getKey(), entry.getValue(), historyEnabled);
+        setVariable(entry.getKey(), entry.getValue());
       }
     }
   }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java	2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java	2010-06-10 18:43:18 UTC (rev 6402)
@@ -152,17 +152,15 @@
     commandService.execute(cmd);
   }
   
-  public void setVariable(String executionId, String name, Object value, boolean historyEnabled) {
-    SetExecutionVariablesCmd cmd = new SetExecutionVariablesCmd(executionId);
+  public void createVariable(String executionId, String name, Object value, boolean historyEnabled) {
+    CreateExecutionVariablesCmd cmd = new CreateExecutionVariablesCmd(executionId, historyEnabled);
     cmd.addVariable(name, value);
-    cmd.setHistoryEnabled(historyEnabled);
     commandService.execute(cmd);
   }
 
-  public void setVariables(String executionId, Map<String, ?> variables, boolean historyEnabled) {
-    SetExecutionVariablesCmd cmd = new SetExecutionVariablesCmd(executionId);
+  public void createVariables(String executionId, Map<String, ?> variables, boolean historyEnabled) {
+    CreateExecutionVariablesCmd cmd = new CreateExecutionVariablesCmd(executionId, historyEnabled);
     cmd.setVariables(variables);
-    cmd.setHistoryEnabled(historyEnabled);
     commandService.execute(cmd);
   }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java	2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java	2010-06-10 18:43:18 UTC (rev 6402)
@@ -81,21 +81,19 @@
     query.setCommandService(commandService);
     return query;
   }
-  
+
   public Set<String> getVariableNames(String processInstanceId) {
     return commandService.execute(new GetHistoryVariableNamesCmd(processInstanceId));
   }
-  
+
   public Object getVariable(String processInstanceId, String variableName) {
     Set<String> variableNames = new HashSet<String>();
     variableNames.add(variableName);
     Map<String, Object> variables = commandService.execute(new GetHistoryVariablesCmd(processInstanceId, variableNames));
     return variables.get(variableName);
   }
-  
-  public Map<String, Object> getVariables(String processInstanceId, Set<String> variableNames) {
 
+  public Map<String, Object> getVariables(String processInstanceId, Set<String> variableNames) {
     return commandService.execute(new GetHistoryVariablesCmd(processInstanceId, variableNames));
-    
   }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java	2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java	2010-06-10 18:43:18 UTC (rev 6402)
@@ -79,29 +79,25 @@
 
   public void setValue(Object value, ScopeInstanceImpl scopeInstance) {
     if (converter!=null) {
-      if (! converter.supports(value, scopeInstance, this)) {
+      if (!converter.supports(value, scopeInstance, this)) {
         throw new JbpmException("the converter '"+converter.getClass().getName()+"' in variable instance '"+this.getClass().getName()+"' does not support values of type '"+value.getClass().getName()+"'.  to change the type of a variable, you have to delete it first");
       }
       value = converter.convert(value, scopeInstance, this);
     }
-    if ( (value!=null)
-         && (! this.isStorable(value)) ) {
-      throw new JbpmException("variable instance '"+this.getClass().getName()+"' does not support values of type '"+value.getClass().getName()+"'.  to change the type of a variable, you have to delete it first");
+    if (value!=null && !isStorable(value)) {
+      throw new JbpmException("variable instance '"+getClass().getName()+"' does not support values of type '"+value.getClass().getName()+"'.  to change the type of a variable, you have to delete it first");
     }
     setObject(value);
     
     HistorySession historySession = EnvironmentImpl.getFromCurrent(HistorySession.class, false);
-    if ( isHistoryEnabled 
-         && (historySession!=null) && (this.getDbid() != -1)
-       ) {
+    if (isHistoryEnabled && historySession!=null && getDbid()!=-1) {
       HistoryEvent.fire(new VariableUpdate(this));
     }
   }
 
   public Object getValue(ScopeInstanceImpl scopeInstance) {
     Object value = getObject();
-    if ( (value!=null)
-         && (converter!=null) ) {
+    if (value!=null && converter!=null) {
       value = converter.revert(value, scopeInstance, this);
     }
     return value;

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java	2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java	2010-06-10 18:43:18 UTC (rev 6402)
@@ -65,8 +65,7 @@
   public void setValue(Object value, ScopeInstanceImpl scopeInstance) {
     super.setValue(value, scopeInstance);
     cachedValue = value;
-    this.textValue = value.toString();
-    
+    textValue = value.toString();
   }
 
   public Lob getLob() {

Deleted: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariable.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariable.java	2010-06-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariable.java	2010-06-10 18:43:18 UTC (rev 6402)
@@ -1,33 +0,0 @@
-package org.jbpm.test.variables;
-
-import java.io.Serializable;
-
-
-public class HistoryVariable implements Serializable {
-  /**
-   * 
-   */
-  private static final long serialVersionUID = 1L;
-  
-  private String name;
-  
-  
-  public String getName() {
-    return name;
-  }
-
-  
-  public void setName(String name) {
-    this.name = name;
-  }
-
-  public HistoryVariable() {
-    this.name = "Poul";
-  }
-
-
-  @Override
-  public String toString() {
-   return "my name is Poul";
-  }
-}
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-10 16:58:19 UTC (rev 6401)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/HistoryVariableTest.java	2010-06-10 18:43:18 UTC (rev 6402)
@@ -1,232 +1,202 @@
-package org.jbpm.test.variables;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.jbpm.test.JbpmTestCase;
-
-
-public class HistoryVariableTest extends JbpmTestCase {
-
-  public void testDeclaredVariableWithHistory() {
-    deployJpdlXmlString(
-      "<process name='var'>" +
-      " <variable name='test' type='string' init-expr='test value' history='true'/>"+
-      "  <start name='a'>" +
-      "    <transition to='b' />" +
-      "  </start>" +
-      "  <state name='b'/>" +
-      "</process>"
-    );
-    
-    executionService.startProcessInstanceByKey("var", "one");
-    
-    Set<String> variableNames = executionService.getVariableNames("var.one");
-    String testVariableValue = (String) executionService.getVariable("var.one", "test");
-    assertNotNull(variableNames);
-    assertEquals(1, variableNames.size());
-    assertEquals("test", variableNames.iterator().next());
-    assertEquals("test value", testVariableValue);
!
 -    
-    Set<String> historyVariables = historyService.getVariableNames("var.one");
-    assertEquals(1, historyVariables.size());
-    assertEquals("test", historyVariables.iterator().next());
-    
-    
-    String value = (String) historyService.getVariable("var.one", "test");
-    assertEquals("test value", value);
-
-  }
-  
-  public void testSetVariableViaAPIwithHistory() {
-    deployJpdlXmlString(
-            "<process name='var'>" +
-            "  <start name='a'>" + 
-            "    <transition to='b' />" +
-            "  </start>" +
-            "  <state name='b'/>" +
-            "</process>");
-
-    executionService.startProcessInstanceByKey("var", "one");
-
-    executionService.setVariable("var.one", "test2", "test3", true);
-
-    Set<String> variableNames = executionService.getVariableNames("var.one");
-    String testVariableValue = (String) executionService.getVariable("var.one", "test2");
-    assertNotNull(variableNames);
-    assertEquals(1,!
  variableNames.size());
-    assertEquals("test2", variableNam!
 es.itera
tor().next());
-    assertEquals("test3", testVariableValue);
-
-    Set<String> historyVariables = historyService.getVariableNames("var.one");
-    assertEquals(1, historyVariables.size());
-    assertEquals("test2", historyVariables.iterator().next());
-
-    String value = (String) historyService.getVariable("var.one", "test2");
-    assertEquals("test3", value);
-  }
-  
-  public void testSetVariablesViaAPIwithHistory() {
-    deployJpdlXmlString(
-            "<process name='var'>" +
-            "  <start name='a'>" + 
-            "    <transition to='b' />" +
-            "  </start>" +
-            "  <state name='b'/>" +
-            "</process>");
-
-    executionService.startProcessInstanceByKey("var", "one");
-    
-    Map<String, String> simpleVariables = new HashMap<String, String>();
-    simpleVariables.put("simple-var", "hello history");
-    simpleVariables.put("test-var", "good day");
-    simpleVariables.put("my-var", "cheers");
-
-    executionService!
 .setVariables("var.one", simpleVariables, true);
-
-    Set<String> variableNames = executionService.getVariableNames("var.one");
-    
-    assertNotNull(variableNames);
-    assertEquals(3, variableNames.size());
-    
-    String testVariableValue = (String) executionService.getVariable("var.one", "test-var");
-    assertEquals("good day", testVariableValue);
-
-    Set<String> historyVariables = historyService.getVariableNames("var.one");
-    assertEquals(3, historyVariables.size());
-
-    String value = (String) historyService.getVariable("var.one", "simple-var");
-    assertEquals("hello history", value);
-  }
-  
-  public void testDeclaredVariablesWithHistory() {
-    deployJpdlXmlString(
-      "<process name='var'>" +
-      " <variable name='test' type='string' init-expr='test value' history='true'/>"+
-      " <variable name='real' type='string' init-expr='real value' history='true'/>"+
-      "  <start name='a'>" +
-      "    <transition to='b' />" +
-      !
 "  </start>" +
-      "  <state name='b'/>" +
-      "</proces!
 s>"
-   
 );
-    
-    executionService.startProcessInstanceByKey("var", "one");
-    
-    Set<String> variableNames = executionService.getVariableNames("var.one");
-    
-    assertNotNull(variableNames);
-    assertEquals(2, variableNames.size());
-    
-    String testVariableValue = (String) executionService.getVariable("var.one", "test");
-    assertEquals("test value", testVariableValue);
-    
-    Set<String> historyVariables = historyService.getVariableNames("var.one");
-    assertEquals(2, historyVariables.size());
-    
-    
-    String value = (String) historyService.getVariable("var.one", "real");
-    assertEquals("real value", value);
-
-  }
-  
-  public void testDeclaredVariablesMixed() {
-    deployJpdlXmlString(
-      "<process name='var'>" +
-      " <variable name='test' type='string' init-expr='test value' history='true'/>"+
-      " <variable name='real' type='string' init-expr='real value' history='false'/>"+
-      "  <start name='a'>" +
-      "    <tran!
 sition to='b' />" +
-      "  </start>" +
-      "  <state name='b'/>" +
-      "</process>"
-    );
-    
-    executionService.startProcessInstanceByKey("var", "one");
-    
-    Set<String> variableNames = executionService.getVariableNames("var.one");
-    
-    assertNotNull(variableNames);
-    assertEquals(2, variableNames.size());
-    
-    String testVariableValue = (String) executionService.getVariable("var.one", "test");
-    assertEquals("test value", testVariableValue);
-    
-    Set<String> historyVariables = historyService.getVariableNames("var.one");
-    assertEquals(1, historyVariables.size());
-    
-    
-    String value = (String) historyService.getVariable("var.one", "test");
-    assertEquals("test value", value);
-    
-    assertNull(historyService.getVariable("var.one", "real"));
-
-  }
-  
-  public void testDeclaredELVariableWithHistory() {
-    deployJpdlXmlString(
-      "<process name='var'>" +
-      " <variable name='test' type='integer' i!
 nit-expr='#{testV}' history='true'/>"+
-      "  <start name='!
 a'>" +
-
      "    <transition to='b' />" +
-      "  </start>" +
-      "  <state name='b'/>" +
-      "</process>"
-    );
-    HashMap<String, Integer> vars = new HashMap<String, Integer>();
-    vars.put("testV", 35);
-    executionService.startProcessInstanceByKey("var", vars, "one");
-    
-    Set<String> variableNames = executionService.getVariableNames("var.one");
-    Integer testVariableValue = (Integer) executionService.getVariable("var.one", "test");
-    assertNotNull(variableNames);
-    assertEquals(2, variableNames.size());
-    assertEquals("test", variableNames.iterator().next());
-    assertTrue(35 == testVariableValue);
-    
-    Set<String> historyVariables = historyService.getVariableNames("var.one");
-    assertEquals(1, historyVariables.size());
-    assertEquals("test", historyVariables.iterator().next());
-    
-    
-    String value = (String) historyService.getVariable("var.one", "test");
-    assertEquals("35", value);
-
-  }
-  
-  public void testDe!
 claredSerializableVariableWithHistory() {
-    deployJpdlXmlString(
-      "<process name='var'>" +
-      " <variable name='test' type='serializable' history='true'>" +
-      "  <object class='org.jbpm.test.variables.HistoryVariable' />" +
-      " </variable>"+
-      "  <start name='a'>" +
-      "    <transition to='b' />" +
-      "  </start>" +
-      "  <state name='b'/>" +
-      "</process>"
-    );
-    
-    executionService.startProcessInstanceByKey("var", "one");
-    
-    Set<String> variableNames = executionService.getVariableNames("var.one");
-    HistoryVariable testVariableValue = (HistoryVariable) executionService.getVariable("var.one", "test");
-    assertNotNull(variableNames);
-    assertEquals(1, variableNames.size());
-    assertEquals("test", variableNames.iterator().next());
-    assertNotNull(testVariableValue);
-    assertEquals("Poul", testVariableValue.getName());
-    
-    Set<String> historyVariables = historyService.getVariableNames("var.!
 one");
-    assertEquals(1, historyVariables.size());
-    ass!
 ertEqual
s("test", historyVariables.iterator().next());
-    
-    
-    String value = (String) historyService.getVariable("var.one", "test");
-    assertEquals("my name is Poul", value);
-
-  }
-}
-
-
+package org.jbpm.test.variables;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jbpm.test.JbpmTestCase;
+
+public class HistoryVariableTest extends JbpmTestCase {
+
+  public void testDeclaredVariableWithHistory() {
+    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 historyValue = (String) historyService.getVariable("var.one", "test");
+    assertEquals("history", historyValue);
+  }
+
+  public void testDeclaredVariablesWithHistory() {
+    deployJpdlXmlString("<process name='var'>"
+      + " <variable name='test' type='string' init-expr='test value' history='true'/>"
+      + " <variable name='real' type='string' init-expr='real value' 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(2, variableNames.size());
+
+    String executionValue = (String) executionService.getVariable("var.one", "test");
+    assertEquals("test value", executionValue);
+
+    Set<String> historyVariables = historyService.getVariableNames("var.one");
+    assertEquals(2, historyVariables.size());
+
+    String historyValue = (String) historyService.getVariable("var.one", "real");
+    assertEquals("real value", historyValue);
+  }
+
+  public void testCreateVariableWithHistory() {
+    deployJpdlXmlString("<process name='var'>"
+      + "  <start name='a'>"
+      + "    <transition to='b' />"
+      + "  </start>"
+      + "  <state name='b'/>"
+      + "</process>");
+
+    executionService.startProcessInstanceByKey("var", "one");
+    executionService.createVariable("var.one", "test2", "test3", true);
+
+    Set<String> variableNames = executionService.getVariableNames("var.one");
+    assertEquals(1, variableNames.size());
+    assertEquals("test2", variableNames.iterator().next());
+
+    String executionValue = (String) executionService.getVariable("var.one", "test2");
+    assertEquals("test3", executionValue);
+
+    Set<String> historyVariables = historyService.getVariableNames("var.one");
+    assertEquals(1, historyVariables.size());
+    assertEquals("test2", historyVariables.iterator().next());
+
+    String historyValue = (String) historyService.getVariable("var.one", "test2");
+    assertEquals("test3", historyValue);
+  }
+
+  public void testCreateVariablesWithHistory() {
+    deployJpdlXmlString("<process name='var'>"
+      + "  <start name='a'>"
+      + "    <transition to='b' />"
+      + "  </start>"
+      + "  <state name='b'/>"
+      + "</process>");
+
+    executionService.startProcessInstanceByKey("var", "one");
+
+    Map<String, String> variables = new HashMap<String, String>();
+    variables.put("simple-var", "hello history");
+    variables.put("test-var", "good day");
+    variables.put("my-var", "cheers");
+    executionService.createVariables("var.one", variables, true);
+
+    Set<String> variableNames = executionService.getVariableNames("var.one");
+    assertEquals(3, variableNames.size());
+
+    String executionValue = (String) executionService.getVariable("var.one", "test-var");
+    assertEquals("good day", executionValue);
+
+    Set<String> historyVariables = historyService.getVariableNames("var.one");
+    assertEquals(3, historyVariables.size());
+
+    String historyValue = (String) historyService.getVariable("var.one", "simple-var");
+    assertEquals("hello history", historyValue);
+  }
+
+  public void testDeclaredVariablesMixed() {
+    deployJpdlXmlString("<process name='var'>"
+      + " <variable name='test' type='string' init-expr='test value' history='true'/>"
+      + " <variable name='real' type='string' init-expr='real value' history='false'/>"
+      + "  <start name='a'>"
+      + "    <transition to='b' />"
+      + "  </start>"
+      + "  <state name='b'/>"
+      + "</process>");
+
+    executionService.startProcessInstanceByKey("var", "one");
+
+    Set<String> variableNames = executionService.getVariableNames("var.one");
+    assertEquals(2, variableNames.size());
+
+    String executionValue = (String) executionService.getVariable("var.one", "test");
+    assertEquals("test value", executionValue);
+
+    Set<String> historyVariables = historyService.getVariableNames("var.one");
+    assertEquals(1, historyVariables.size());
+
+    String historyValue = (String) historyService.getVariable("var.one", "test");
+    assertEquals("test value", historyValue);
+
+    assertNull(historyService.getVariable("var.one", "real"));
+  }
+
+  public void testDeclaredIntegerVariableWithHistory() {
+    deployJpdlXmlString("<process name='var'>"
+      + " <variable name='test' type='integer' init-expr='#{testV}' history='true'/>"
+      + "  <start name='a'>"
+      + "    <transition to='b' />"
+      + "  </start>"
+      + "  <state name='b'/>"
+      + "</process>");
+
+    Map<String, ?> vars = Collections.singletonMap("testV", 35);
+    executionService.startProcessInstanceByKey("var", vars, "one");
+
+    Set<String> variableNames = executionService.getVariableNames("var.one");
+    assertEquals(2, variableNames.size());
+    assertEquals("test", variableNames.iterator().next());
+
+    Integer executionValue = (Integer) executionService.getVariable("var.one", "test");
+    assertEquals(35, executionValue.intValue());
+
+    Set<String> historyVariables = historyService.getVariableNames("var.one");
+    assertEquals(1, historyVariables.size());
+    assertEquals("test", historyVariables.iterator().next());
+
+    String historyValue = (String) historyService.getVariable("var.one", "test");
+    assertEquals("35", historyValue);
+  }
+
+  public void testDeclaredSerializableVariableWithHistory() {
+    deployJpdlXmlString("<process name='var'>"
+      + "  <variable name='test' type='serializable' history='true'>"
+      + "    <object class='java.util.Date'>"
+      + "      <constructor><arg><long value='1276086573250'/></arg></constructor>"
+      + "    </object>"
+      + "  </variable>"
+      + "  <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());
+
+    Date variableValue = (Date) executionService.getVariable("var.one", "test");
+    assertEquals(1276086573250L, variableValue.getTime());
+
+    Set<String> historyVariables = historyService.getVariableNames("var.one");
+    assertEquals(1, historyVariables.size());
+    assertEquals("test", historyVariables.iterator().next());
+
+    String historyValue = (String) historyService.getVariable("var.one", "test");
+    assertEquals(variableValue.toString(), historyValue);
+  }
+}



More information about the jbpm-commits mailing list