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

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Sep 3 18:37:46 EDT 2008


Author: tom.baeyens at jboss.com
Date: 2008-09-03 18:37:46 -0400 (Wed, 03 Sep 2008)
New Revision: 2097

Removed:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/cmd/GetVariableCmd.java
Modified:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/ExecutionService.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/cmd/GetVariablesCmd.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/cmd/SignalCmd.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/CommandExecutionService.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/BasicExecutionFlowDbTest.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ExecutionServiceTest.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ProcessServiceTest.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/timer/TimerIntegrationTest.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/enterprise/TimerTest.java
Log:
introducing the id

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/ExecutionService.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/ExecutionService.java	2008-09-03 22:24:06 UTC (rev 2096)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/ExecutionService.java	2008-09-03 22:37:46 UTC (rev 2097)
@@ -58,14 +58,18 @@
   Execution startExecutionInLatest(String processDefinitionName);
 
   /** starts a new execution in the latest version of the given processDefinitionName.
-   * @param processDefinitionName is the name of the process definition for which the latest version will be taken. 
-   * @param executionKey is a user provided reference for the new execution that must be unique over all 
-   *    process versions with the same name. */
+   * @param processDefinitionName is the name of the process definition 
+   *   for which the latest version will be taken. 
+   * @param executionKey is a user provided reference for the new execution 
+   *   that must be unique over all process versions with the same name. */
   Execution startExecutionInLatest(String processDefinitionName, String executionKey);
 
   /** starts a new execution in the latest version of the given processDefinitionName. 
-   * @param processDefinitionName is the name of the process definition for which the latest version will be taken. 
-   * @param variables are the initial values of the process variables that will be set before the execution starts. */
+   * @param processDefinitionName is the name of the process definition 
+   *   for which the latest version will be taken. 
+   * @param variables are the initial values of the process variables that 
+   *   will be set before the execution starts (read: before the initial 
+   *   node is executed). */
   Execution startExecutionInLatest(String processDefinitionName, Map<String, Object> variables);
 
   /** starts a new execution in the latest version of the given processDefinitionName. 
@@ -75,40 +79,13 @@
    *    process versions with the same name. */
   Execution startExecutionInLatest(String processDefinitionName, Map<String, Object> variables, String executionKey);
 
-  /** the execution with the given database primary key */
-  // TODO REMOVE
-  Execution findExecution(long executionDbid);
-
   /** the execution that is uniquely defined by the process definition and the business key. */
   Execution findExecution(String processDefinitionName, String executionKey);
 
   /** the execution that is uniquely defined by the process definition and the business key. */
   Execution findExecution(String executionId);
 
-  /** provides an external trigger to an execution. */
-  // TODO REMOVE
-  Execution signalExecution(long executionDbid);
   
-  /** provides a named external trigger to an execution. */
-  // TODO REMOVE
-  Execution signalExecution(long executionDbid, String signalName);
-  
-  /** provides a named external trigger to an execution with parameters. */
-  // TODO REMOVE
-  Execution signalExecution(long executionDbid, String signalName, Map<String, Object> parameters);
-
-  /** provides a external trigger to an execution with parameters. */
-  // TODO REMOVE
-  Execution signalExecution(long executionDbid, Map<String, Object> parameters);
-
-  
-  /** provides a named external trigger to an execution. */
-  Execution signalExecution(String processDefinitionName, String executionKey, String signalName);
-  
-  /** provides a named external trigger to an execution with parameters. */
-  Execution signalExecution(String processDefinitionName, String executionKey, String signalName, Map<String, Object> parameters);
-
-  
   /** provides an external trigger to an execution. */
   Execution signalExecution(String executionId);
   
@@ -121,23 +98,20 @@
   /** provides a external trigger to an execution with parameters. */
   Execution signalExecution(String executionId, Map<String, Object> parameters);
   
-
-  /** creates or overwrites a variable value on the referenced execution 
-   * TODO REMOVE */ 
-  Execution setVariable(long executionDbid, String name, Object value);
   
-  /** creates or overwrites the variable values on the referenced execution 
-   * TODO REMOVE */ 
-  Execution setVariables(long executionDbid, Map<String, Object> variables);
+  /** provides a named external trigger to an execution. */
+  Execution signalExecutionByKey(String processDefinitionName, String executionKey);
   
-  /** retrieves a variable 
-   * TODO REMOVE */  
-  Object getVariable(long executionDbid, String variableName);
+  /** provides a named external trigger to an execution. */
+  Execution signalExecutionByKey(String processDefinitionName, String executionKey, String signalName);
   
-  /** retrieves a map of variables 
-   * TODO REMOVE */  
-  Map<String, Object> getVariables(long executionDbid, List<String> variableNames);
+  /** provides a named external trigger to an execution with parameters. */
+  Execution signalExecutionByKey(String processDefinitionName, String executionKey, Map<String, Object> parameters);
 
+  /** provides a named external trigger to an execution with parameters. */
+  Execution signalExecutionByKey(String processDefinitionName, String executionKey, String signalName, Map<String, Object> parameters);
+
+  
   /** creates or overwrites a variable value on the referenced execution */ 
   Execution setVariable(String executionId, String name, Object value);
   
@@ -149,5 +123,4 @@
   
   /** retrieves a map of variables */ 
   Map<String, Object> getVariables(String executionId, List<String> variableNames);
-
 }

Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/cmd/GetVariableCmd.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/cmd/GetVariableCmd.java	2008-09-03 22:24:06 UTC (rev 2096)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/cmd/GetVariableCmd.java	2008-09-03 22:37:46 UTC (rev 2097)
@@ -1,52 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jbpm.pvm.internal.cmd;
-
-import org.jbpm.pvm.Execution;
-import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
-import org.jbpm.pvm.session.PvmDbSession;
-
-/**
- * @author Tom Baeyens
- */
-public class GetVariableCmd implements Command<Object> {
-
-  private static final long serialVersionUID = 1L;
-
-  protected long executionDbid;
-  protected String variableName;
-
-  public GetVariableCmd(long executionDbid, String variableName) {
-    this.executionDbid = executionDbid;
-    this.variableName = variableName;
-  }
-
-  public Object execute(Environment environment) throws Exception {
-    ExecutionImpl execution = environment.get(PvmDbSession.class).get(ExecutionImpl.class, executionDbid);
-    return execution.getVariable(variableName);
-  }
-
-  public String toString() {
-    return GetVariableCmd.class.getSimpleName() + '(' + executionDbid + ',' + variableName + ')';
-  }
-}

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/cmd/GetVariablesCmd.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/cmd/GetVariablesCmd.java	2008-09-03 22:24:06 UTC (rev 2096)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/cmd/GetVariablesCmd.java	2008-09-03 22:37:46 UTC (rev 2097)
@@ -54,7 +54,6 @@
   public Map<String, Object> execute(Environment environment) throws Exception {
     PvmDbSession pvmDbSession = environment.get(PvmDbSession.class);
     
-    
     ClientExecution execution = null;
     
     if (executionId!=null) {

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/cmd/SignalCmd.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/cmd/SignalCmd.java	2008-09-03 22:24:06 UTC (rev 2096)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/cmd/SignalCmd.java	2008-09-03 22:37:46 UTC (rev 2097)
@@ -38,6 +38,7 @@
   private static final long serialVersionUID = 1L;
 
   protected Long executionDbid;
+  protected String executionId;
   protected String processDefinitionName;
   protected String executionKey;
   protected String signalName;
@@ -72,6 +73,10 @@
     this.parameters = parameters;
   }
 
+  public SignalCmd(String executionId) {
+    // TODO Auto-generated constructor stub
+  }
+
   public Execution execute(Environment environment) throws Exception {
     ClientExecution execution = null;
     

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/CommandExecutionService.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/CommandExecutionService.java	2008-09-03 22:24:06 UTC (rev 2096)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/svc/CommandExecutionService.java	2008-09-03 22:37:46 UTC (rev 2097)
@@ -31,7 +31,6 @@
 import org.jbpm.pvm.internal.cmd.ActivityInstanceCmd;
 import org.jbpm.pvm.internal.cmd.CommandService;
 import org.jbpm.pvm.internal.cmd.FindExecutionCmd;
-import org.jbpm.pvm.internal.cmd.GetVariableCmd;
 import org.jbpm.pvm.internal.cmd.GetVariablesCmd;
 import org.jbpm.pvm.internal.cmd.SetVariablesCmd;
 import org.jbpm.pvm.internal.cmd.SignalCmd;
@@ -80,11 +79,19 @@
 
   
   public Execution signalExecution(String executionId) {
-    return null;
+    return commandService.execute(new SignalCmd(executionId, null, null));
   }
 
+  public Execution signalExecution(String executionId, String signalName) {
+    return commandService.execute(new SignalCmd(executionId, signalName, null));
+  }
+
+  public Execution signalExecution(String executionId, String signalName, Map<String, Object> parameters) {
+    return commandService.execute(new SignalCmd(executionId, signalName, parameters));
+  }
+
   public Execution signalExecution(String executionId, Map<String, Object> parameters) {
-    return null;
+    return commandService.execute(new SignalCmd(executionId, null, parameters));
   }
 
   
@@ -104,19 +111,19 @@
     return commandService.execute(new SignalCmd(executionDbid, null, parameters));
   }
 
-  public Execution signalExecution(String processDefinitionName, String executionKey) {
+  public Execution signalExecutionByKey(String processDefinitionName, String executionKey) {
     return commandService.execute(new SignalCmd(processDefinitionName, executionKey, null, null));
   }
 
-  public Execution signalExecution(String processDefinitionName, String executionKey, String signalName) {
+  public Execution signalExecutionByKey(String processDefinitionName, String executionKey, String signalName) {
     return commandService.execute(new SignalCmd(processDefinitionName, executionKey, signalName, null));
   }
 
-  public Execution signalExecution(String processDefinitionName, String executionKey, String signalName, Map<String, Object> parameters) {
+  public Execution signalExecutionByKey(String processDefinitionName, String executionKey, String signalName, Map<String, Object> parameters) {
     return commandService.execute(new SignalCmd(processDefinitionName, executionKey, signalName, parameters));
   }
 
-  public Execution signalExecution(String processDefinitionName, String executionKey, Map<String, Object> parameters) {
+  public Execution signalExecutionByKey(String processDefinitionName, String executionKey, Map<String, Object> parameters) {
     return commandService.execute(new SignalCmd(processDefinitionName, executionKey, null, parameters));
   }
 
@@ -149,11 +156,6 @@
   }
 
   // TODO: REMOVE
-  public Object getVariable(long executionDbid, String variableName) {
-    return commandService.execute(new GetVariableCmd(executionDbid, variableName));
-  }
-
-  // TODO: REMOVE
   public Map<String, Object> getVariables(long executionDbid, List<String> variableNames) {
     return commandService.execute(new GetVariablesCmd(executionDbid, variableNames));
   }
@@ -176,7 +178,8 @@
   public Object getVariable(String executionId, String variableName) {
     List<String> variableNames = new ArrayList<String>();
     variableNames.add(variableName);
-    return commandService.execute(new GetVariablesCmd(executionId, variableNames));
+    Map<String, Object> variables = commandService.execute(new GetVariablesCmd(executionId, variableNames));
+    return variables.get(variableName);
   }
 
   public Map<String, Object> getVariables(String executionId, List<String> variableNames) {

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/BasicExecutionFlowDbTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/BasicExecutionFlowDbTest.java	2008-09-03 22:24:06 UTC (rev 2096)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/BasicExecutionFlowDbTest.java	2008-09-03 22:37:46 UTC (rev 2097)
@@ -90,7 +90,7 @@
     assertFalse(processInstance.isEnded());
     assertEquals(expectedEvents, recordedEvents);
 
-    processInstance = executionService.signalExecution(processInstance.getDbid());
+    processInstance = executionService.signalExecution(processInstance.getId());
 
     expectedEvents.add("signal[c]");
     expectedEvents.add("execute[d]");
@@ -99,7 +99,7 @@
     assertFalse(processInstance.isEnded());
     assertEquals(expectedEvents, recordedEvents);
 
-    processInstance = executionService.signalExecution(processInstance.getDbid());
+    processInstance = executionService.signalExecution(processInstance.getId());
 
     expectedEvents.add("signal[d]");
     expectedEvents.add("execute[e]");

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ExecutionServiceTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ExecutionServiceTest.java	2008-09-03 22:24:06 UTC (rev 2096)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ExecutionServiceTest.java	2008-09-03 22:37:46 UTC (rev 2097)
@@ -29,9 +29,9 @@
 import org.jbpm.pvm.Deployment;
 import org.jbpm.pvm.Execution;
 import org.jbpm.pvm.ExecutionService;
+import org.jbpm.pvm.ProcessDefinition;
 import org.jbpm.pvm.ProcessService;
 import org.jbpm.pvm.client.ClientProcessDefinition;
-import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
 import org.jbpm.pvm.model.ProcessFactory;
 import org.jbpm.pvm.test.base.DbTestCase;
 
@@ -123,133 +123,114 @@
   
     // provide the variables in the start execution method
     Execution execution = executionService.startExecution("NCLFU:1", variables);
-  
-    long executionDbid = execution.getDbid();
-    assertEquals(new Integer(1), executionService.getVariable(executionDbid, "a"));
-    assertEquals("text", executionService.getVariable(executionDbid, "b"));
+    String executionId = execution.getId();
+
+    assertEquals(new Integer(1), executionService.getVariable(executionId, "a"));
+    assertEquals("text", executionService.getVariable(executionId, "b"));
   }
 
   public void testStartExecutionInLatest() {
-    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
-
-    ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("nuclear fusion");
-    processDefinition.setVersion(1);
-    processService.deploy(new Deployment(processDefinition));
+    // deploy following processes
+    //  'nuclear fusion' with id NFU:1
+    //  'ultimate seduction' with id USD:1
+    //  'ultimate seduction' with id USD:2
+    //  'nuclear fusion' with id NFU:2
+    //  'publish book' with id PBO:1
+    //  'nuclear fusion' with id NFU:3
+    deployMultipleVersionsOfProcesses();
     
-    processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("nuclear fusion");
-    processDefinition.setVersion(2);
-    processService.deploy(new Deployment(processDefinition));
-
-    processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("ultimate seduction");
-    processDefinition.setVersion(1);
-    processService.deploy(new Deployment(processDefinition));
-    
-    processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("publish book");
-    processDefinition.setVersion(1);
-    processService.deploy(new Deployment(processDefinition));
-    
-    processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("nuclear fusion");
-    processDefinition.setVersion(3);
-    processService.deploy(new Deployment(processDefinition));
-    
     ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
 
+    // start a nuclear fusion in the latest version of 
+    // the process definition with name 'nuclear fusion'
     Execution execution = executionService.startExecutionInLatest("nuclear fusion");
     assertNotNull(execution);
+
+    // in the generated id, we can see if the right process definition version was taken
+    assertTrue("the execution id shows that the execution is not started in the latest version of the process: "+execution.getId(), 
+               execution.getId().startsWith("NFU:3/"));
   }
 
-  public void testStartExecutionByNameWithVariables() {
-    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+  public void testStartExecutionInLatestByNameWithVariables() {
+    // deploy following processes
+    //  'nuclear fusion' with id NFU:1
+    //  'ultimate seduction' with id USD:1
+    //  'ultimate seduction' with id USD:2
+    //  'nuclear fusion' with id NFU:2
+    //  'publish book' with id PBO:1
+    //  'nuclear fusion' with id NFU:3
+    deployMultipleVersionsOfProcesses();
+    
+    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
 
-    ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("nuclear fusion");
-    processDefinition.setVersion(1);
-    processService.deploy(new Deployment(processDefinition));
-    
+    // create variables that are fed into the process before it starts executing
     Map<String, Object> variables = new HashMap<String, Object>();
     variables.put("a", new Integer(1));
     variables.put("b", "text");
     
-    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
+    // feed the variables in
+    Execution execution = executionService.startExecutionInLatest("nuclear fusion", variables);
+    String executionId = execution.getId();
 
-    Execution execution = executionService.startExecutionInLatest("nuclear fusion", variables);
-    
-    long executionDbid = execution.getDbid();
-    assertEquals(new Integer(1), executionService.getVariable(executionDbid, "a"));
-    assertEquals("text", executionService.getVariable(executionDbid, "b"));
+    // verify that the variables are actually set
+    assertEquals(new Integer(1), executionService.getVariable(executionId, "a"));
+    assertEquals("text", executionService.getVariable(executionId, "b"));
+
+    // in the generated id, we can see if the right process definition version was taken
+    assertTrue("the execution id shows that the execution is not started in the latest version of the process: "+execution.getId(), 
+               execution.getId().startsWith("NFU:3/"));
   }
   
   public void testStartExecutionByNameWithKey() {
-    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+    // deploy following processes
+    //  'nuclear fusion' with id NFU:1
+    //  'ultimate seduction' with id USD:1
+    //  'ultimate seduction' with id USD:2
+    //  'nuclear fusion' with id NFU:2
+    //  'publish book' with id PBO:1
+    //  'nuclear fusion' with id NFU:3
+    deployMultipleVersionsOfProcesses();
 
-    ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("nuclear fusion");
-    processDefinition.setVersion(1);
-    processService.deploy(new Deployment(processDefinition));
-    
     ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
 
     Execution execution = executionService.startExecutionInLatest("nuclear fusion", "TheFirstTime");
     assertNotNull(execution);
     assertEquals("TheFirstTime", execution.getKey());
-    assertEquals("nuclear_fusion:1/TheFirstTime", execution.getId());
+    assertEquals("NFU:3/TheFirstTime", execution.getId());
   }
   
   public void testFindExecution() {
-    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
-
-    ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("nuclear fusion");
-    processDefinition.setVersion(1);
-    processService.deploy(new Deployment(processDefinition));
-
-    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
-
-    Execution execution = executionService.startExecutionInLatest("nuclear fusion");
-    
-    execution = executionService.findExecution(execution.getDbid());
-    
+    // create an arbitrary execution
+    Execution execution = startExecution();
+    // take the id and see if the execution service can still find it back
+    execution = executionService.findExecution(execution.getId());
     assertNotNull(execution);
   }
-
+  
   public void testSetVariable() {
-    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+    Execution execution = startExecution();
 
-    ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("nuclear fusion");
-    processDefinition.setVersion(1);
-    processService.deploy(new Deployment(processDefinition));
+    String executionId = execution.getId();
+    // set variable a to value text
+    executionService.setVariable(executionId, "a", "text");
+    // check if we can read that value back
+    assertEquals("text", executionService.getVariable(executionId, "a") );
 
-    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
-
-    Execution execution = executionService.startExecutionInLatest("nuclear fusion");
-
-    executionService.setVariable(execution.getDbid(), "a", "text");
-    assertEquals("text", executionService.getVariable(execution.getDbid(), "a") );
+    // overwrite the value of variable a with another text
+    executionService.setVariable(executionId, "a", "another text");
+    // see if we can read another text back from the variable
+    assertEquals("another text", executionService.getVariable(executionId, "a") );
   }
 
   public void testSetVariables() {
-    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+    Execution execution = startExecution();
 
-    ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("nuclear fusion");
-    processDefinition.setVersion(1);
-    processService.deploy(new Deployment(processDefinition));
-
-    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
-
-    Execution execution = executionService.startExecutionInLatest("nuclear fusion");
-
     Map<String, Object> variables = new HashMap<String, Object>();
     variables.put("a", new Integer(1));
     variables.put("b", "text");
 
-    executionService.setVariables(execution.getDbid(), variables);
+    // set variables in bulk by providing a map
+    executionService.setVariables(execution.getId(), variables);
     
     Map<String, Object> expected = new HashMap<String, Object>(variables);
     
@@ -257,7 +238,89 @@
     variableNames.add("a");
     variableNames.add("b");
     
-    assertEquals(expected, executionService.getVariables(execution.getDbid(), variableNames));
+    // read the variables back and compare
+    assertEquals(expected, executionService.getVariables(execution.getId(), variableNames));
+
+    // now set variables b and c with a map
+    variables = new HashMap<String, Object>();
+    variables.put("b", new Integer(99));
+    variables.put("c", "another text");
+
+    // this should leave a untouched, overwrite b and create c
+    executionService.setVariables(execution.getId(), variables);
+
+    // update the expected map
+    expected.put("b", new Integer(99));
+    expected.put("c", "another text");
+
+    // add c to the variable names that should be collected
+    variableNames.add("c");
+    
+    // read the variables back and compare
+    assertEquals(expected, executionService.getVariables(execution.getId(), variableNames));
   }
 
+  // helper methods ///////////////////////////////////////////////////////////
+  
+  /** deploys 3 versions of process with name 'nuclear fusion', 2 versions 
+   * of the processes 'ultimate seduction' and 'publish book' */
+  void deployMultipleVersionsOfProcesses() {
+    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+    
+    ProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion")
+      .key("NFU")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+    Deployment deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+    
+    processDefinition = ProcessFactory.build("ultimate seduction")
+      .key("USD")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+    deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+  
+    processDefinition = ProcessFactory.build("ultimate seduction")
+      .key("USD")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+    deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+  
+    processDefinition = ProcessFactory.build("nuclear fusion")
+      .key("NFU")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+    deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+    
+    processDefinition = ProcessFactory.build("publish book")
+      .key("PBO")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+    deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+  
+    processDefinition = ProcessFactory.build("nuclear fusion")
+      .key("NFU")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+    deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+  }
+
+  Execution startExecution() {
+    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+
+    ProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+    Deployment deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+    
+    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
+
+    return executionService.startExecutionInLatest("nuclear fusion");
+  }
 }

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ProcessServiceTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ProcessServiceTest.java	2008-09-03 22:24:06 UTC (rev 2096)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ProcessServiceTest.java	2008-09-03 22:37:46 UTC (rev 2097)
@@ -280,7 +280,7 @@
   }
   
 
-  /** deploys 3 versions of process with name 'nuclear fusion', and one version 
+  /** deploys 3 versions of process with name 'nuclear fusion', 2 versions 
    * of the processes 'ultimate seduction' and 'publish book' */
   void deployMultipleVersionsOfProcesses() {
     ProcessService processService = getEnvironmentFactory().get(ProcessService.class);

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/timer/TimerIntegrationTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/timer/TimerIntegrationTest.java	2008-09-03 22:24:06 UTC (rev 2096)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/timer/TimerIntegrationTest.java	2008-09-03 22:37:46 UTC (rev 2097)
@@ -96,7 +96,7 @@
     Execution execution = processInstance;
     assertEquals("request", execution.getNodeName());
     // first node is a wait state with no timer
-    execution = getExecutionService().signalExecution(execution.getDbid());
+    execution = getExecutionService().signalExecution(execution.getId());
     assertEquals("decide", execution.getNodeName());
 
     assertTrue(execution instanceof OpenExecution);
@@ -177,7 +177,7 @@
 
     // signal child execution
     Execution child = ((OpenExecution)execution).getExecutions().iterator().next();
-    execution = getExecutionService().signalExecution(child.getDbid());
+    execution = getExecutionService().signalExecution(child.getId());
     assertEquals(Execution.STATE_ENDED, execution.getState());
 
     // check that the subExecution was deleted

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/enterprise/TimerTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/enterprise/TimerTest.java	2008-09-03 22:24:06 UTC (rev 2096)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/enterprise/TimerTest.java	2008-09-03 22:37:46 UTC (rev 2097)
@@ -21,20 +21,21 @@
  */
 package org.jbpm.pvm.enterprise;
 
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 
 import javax.ejb.CreateException;
 import javax.naming.InitialContext;
 
 import org.apache.cactus.ServletTestCase;
-
 import org.jbpm.pvm.Deployment;
 import org.jbpm.pvm.enterprise.custom.HappyActivity;
 import org.jbpm.pvm.enterprise.custom.NoisyActivity;
 import org.jbpm.pvm.env.Environment;
 import org.jbpm.pvm.internal.cmd.Command;
 import org.jbpm.pvm.internal.cmd.DeployCmd;
-import org.jbpm.pvm.internal.cmd.GetVariableCmd;
+import org.jbpm.pvm.internal.cmd.GetVariablesCmd;
 import org.jbpm.pvm.internal.cmd.StartExecutionCmd;
 import org.jbpm.pvm.internal.ejb.LocalCommandExecutor;
 import org.jbpm.pvm.internal.ejb.LocalCommandExecutorHome;
@@ -154,7 +155,9 @@
     Date executionDate = NoisyActivity.waitFor();
     assertTrue(dueDate.compareTo(executionDate) <= 0);
 
-    Object variableValue = commandExecutor.execute(new GetVariableCmd(execution.getDbid(), "executionDate"));
+    List<String> variableNames = new ArrayList<String>();
+    variableNames.add("executionDate");
+    Object variableValue = commandExecutor.execute(new GetVariablesCmd(execution.getId(), variableNames));
     assertNull(variableValue);
   }
 




More information about the jbpm-commits mailing list