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

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Aug 29 11:01:00 EDT 2008


Author: tom.baeyens at jboss.com
Date: 2008-08-29 11:01:00 -0400 (Fri, 29 Aug 2008)
New Revision: 2052

Added:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/CheckVersion.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/CheckVersionBinding.java
Removed:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/VerifyVersion.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/VerifyVersionBinding.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/samples/pvm.cfg.xml
Modified:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/CreateId.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ProcessDefinitionImpl.java
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/model/ProcessFactory.java
   jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/pvm.wire.bindings.xml
   jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/wire.xsd
   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/samples/ExamplesConfiguration.java
   jbpm4/pvm/trunk/modules/core/src/test/resources/environment.cfg.xml
   jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/svc/environment.cfg.xml
   jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/timer/environment.cfg.xml
   jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/internal/db/langext/environment.cfg.xml
Log:
id and key api rollout in the api.db.svc tests

Copied: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/CheckVersion.java (from rev 1997, jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/VerifyVersion.java)
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/CheckVersion.java	                        (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/CheckVersion.java	2008-08-29 15:01:00 UTC (rev 2052)
@@ -0,0 +1,83 @@
+/*
+ * 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.deploy;
+
+import org.jbpm.pvm.Deployment;
+import org.jbpm.pvm.PvmException;
+import org.jbpm.pvm.client.ClientProcessDefinition;
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
+import org.jbpm.pvm.session.PvmDbSession;
+
+import clover.org.jfree.util.Log;
+
+/**
+ * @author Tom Baeyens
+ */
+public class CheckVersion implements Deployer {
+  
+  protected boolean assign = true;
+
+  public void deploy(Deployment deployment) {
+    ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl) deployment.getProcessDefinition();
+    
+    String name = processDefinition.getName();
+    if (name == null) {
+      throw new PvmException("process must have a name to deploy it");
+    }
+
+    int version = processDefinition.getVersion();
+    if ( (version==ProcessDefinitionImpl.UNASSIGNED_VERSION)
+         && ! assign
+       ) {
+      throw new PvmException("no version specified in process definition "+name);
+    }
+      
+    Environment environment = Environment.getCurrent();
+    if (environment==null) {
+      throw new PvmException("environment is required by deployer check-version");
+    }
+
+    PvmDbSession pvmDbSession = environment.get(PvmDbSession.class);
+    if (pvmDbSession==null) {
+      throw new PvmException(PvmDbSession.class.getName()+" is required in the environment by "+getClass().getName());
+    }
+
+    if ( (version==ProcessDefinitionImpl.UNASSIGNED_VERSION)
+        && assign
+       ) {
+      ClientProcessDefinition latestDeployedVersion = pvmDbSession.findLatestProcessDefinitionByName(name);
+      if (latestDeployedVersion!=null) {
+        version = latestDeployedVersion.getVersion() + 1;
+      } else {
+        version = 1;
+      }
+      Log.debug("assigning version "+version+" to process definition "+name);
+      processDefinition.setVersion(version);
+
+    } else {
+      if (pvmDbSession.findProcessDefinitionByName(name, version) != null) {
+        throw new PvmException("process '" + name + "' version " + version + " already exists");
+      }
+    }
+  }
+}


Property changes on: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/CheckVersion.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + LF

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/CreateId.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/CreateId.java	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/CreateId.java	2008-08-29 15:01:00 UTC (rev 2052)
@@ -22,6 +22,7 @@
 package org.jbpm.pvm.internal.deploy;
 
 import org.jbpm.pvm.Deployment;
+import org.jbpm.pvm.internal.log.Log;
 import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
 
 
@@ -29,20 +30,25 @@
  * @author Tom Baeyens
  */
 public class CreateId implements Deployer {
+  
+  private static final Log log = Log.getLog(CreateId.class.getName());
 
   public void deploy(Deployment deployment) {
     ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl) deployment.getProcessDefinition();
-    
-    String key = processDefinition.getKey();
-    if (key==null) {
-      key = processDefinition.getName();
+
+    if (processDefinition.getId()==null) {
+      String key = processDefinition.getKey();
+      if (key==null) {
+        key = processDefinition.getName();
+      }
+      
+      // replace any non-word character with an underscore
+      key = key.replaceAll("\\W", "_");
+
+      String id = key+":"+processDefinition.getVersion();
+      
+      log.trace("created id '"+id+"' for "+processDefinition);
+      processDefinition.setId(id);
     }
-    
-    // replace any non-word character with an underscore
-    key = key.replaceAll("\\W", "_");
-
-    String id = key+":"+processDefinition.getVersion();
-    
-    processDefinition.setId(id);
   }
 }

Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/VerifyVersion.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/VerifyVersion.java	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/deploy/VerifyVersion.java	2008-08-29 15:01:00 UTC (rev 2052)
@@ -1,61 +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.deploy;
-
-import org.jbpm.pvm.Deployment;
-import org.jbpm.pvm.ProcessDefinition;
-import org.jbpm.pvm.PvmException;
-import org.jbpm.pvm.env.Environment;
-import org.jbpm.pvm.session.PvmDbSession;
-
-
-/**
- * @author Tom Baeyens
- */
-public class VerifyVersion implements Deployer {
-
-  public void deploy(Deployment deployment) {
-    ProcessDefinition processDefinition = deployment.getProcessDefinition();
-    
-    String name = processDefinition.getName();
-    if (name == null) {
-      throw new PvmException("process must have a name to deploy it");
-    }
-
-    int version = processDefinition.getVersion();
-
-    Environment environment = Environment.getCurrent();
-    if (environment==null) {
-      throw new PvmException("environment is required by "+getClass().getName());
-    }
-
-    PvmDbSession pvmDbSession = environment.get(PvmDbSession.class);
-    if (pvmDbSession==null) {
-      throw new PvmException(PvmDbSession.class.getName()+" is required in the environment by "+getClass().getName());
-    }
-    
-    if (pvmDbSession.findProcessDefinitionByName(name, version) != null) {
-      throw new PvmException("process [" + name + "|" + version + "] already exists");
-    }
-  }
-
-}

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ProcessDefinitionImpl.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ProcessDefinitionImpl.java	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/model/ProcessDefinitionImpl.java	2008-08-29 15:01:00 UTC (rev 2052)
@@ -42,6 +42,8 @@
 
   private static final long serialVersionUID = 1L;
   private static final Log log = Log.getLog(ProcessDefinitionImpl.class.getName());
+  
+  public static final int UNASSIGNED_VERSION = -1;
 
   /** user provided short reference for the process definition that 
    * has the same scope as the name.  Multiple versions of the same 
@@ -54,7 +56,7 @@
   protected String id;
 
   /** the version number of the process definitions with the same name.*/
-  protected int version;
+  protected int version = UNASSIGNED_VERSION;
   
   /** optional package name similar to the Java package name. */
   protected String packageName;

Copied: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/CheckVersionBinding.java (from rev 1992, jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/VerifyVersionBinding.java)
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/CheckVersionBinding.java	                        (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/CheckVersionBinding.java	2008-08-29 15:01:00 UTC (rev 2052)
@@ -0,0 +1,63 @@
+/*
+ * 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.wire.binding;
+
+import org.jbpm.pvm.internal.deploy.CheckVersion;
+import org.jbpm.pvm.internal.util.XmlUtil;
+import org.jbpm.pvm.internal.wire.Descriptor;
+import org.jbpm.pvm.internal.wire.descriptor.FalseDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.TrueDescriptor;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+
+/** parses a descriptor creating a {@link CheckVersion version verification deployer}.
+ * 
+ * See schema docs for more details.
+ *
+ * @author Tom Baeyens
+ */
+public class CheckVersionBinding extends WireDescriptorBinding {
+
+  public CheckVersionBinding() {
+    super("check-version");
+  }
+
+  public Object parse(Element element, Parse parse, Parser parser) {
+    ObjectDescriptor objectDescriptor = new ObjectDescriptor(CheckVersion.class.getName());
+    
+    Boolean assign = XmlUtil.attributeBoolean(element, "assign", false, parse, null);
+    if (assign!=null) {
+      Descriptor valueDescriptor = null;
+      if (assign) {
+        valueDescriptor = new TrueDescriptor();
+      } else {
+        valueDescriptor = new FalseDescriptor();
+      }
+      objectDescriptor.addInjection("assign", valueDescriptor);
+    }
+
+    return objectDescriptor;
+  }
+}


Property changes on: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/CheckVersionBinding.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + LF

Deleted: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/VerifyVersionBinding.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/VerifyVersionBinding.java	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/binding/VerifyVersionBinding.java	2008-08-29 15:01:00 UTC (rev 2052)
@@ -1,46 +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.wire.binding;
-
-import org.jbpm.pvm.internal.deploy.VerifyVersion;
-import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
-import org.jbpm.pvm.internal.xml.Parse;
-import org.jbpm.pvm.internal.xml.Parser;
-import org.w3c.dom.Element;
-
-
-/** parses a descriptor creating a {@link VerifyVersion version verification deployer}.
- * 
- * See schema docs for more details.
- *
- * @author Tom Baeyens
- */
-public class VerifyVersionBinding extends WireDescriptorBinding {
-
-  public VerifyVersionBinding() {
-    super("verify-version");
-  }
-
-  public Object parse(Element element, Parse parse, Parser parser) {
-    return new ObjectDescriptor(VerifyVersion.class.getName());
-  }
-}

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/model/ProcessFactory.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/model/ProcessFactory.java	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/model/ProcessFactory.java	2008-08-29 15:01:00 UTC (rev 2052)
@@ -26,6 +26,7 @@
 import java.util.List;
 import java.util.Stack;
 
+import org.jbpm.pvm.ProcessDefinition;
 import org.jbpm.pvm.PvmException;
 import org.jbpm.pvm.activity.Activity;
 import org.jbpm.pvm.client.ClientProcessDefinition;
@@ -661,7 +662,19 @@
     }
     return processDefinition;
   }
-  
+
+  /** sets the {@link ProcessDefinition#getVersion() version} of the process definition explicitely */
+  public ProcessFactory version(int version) {
+    processDefinition.setVersion(version);
+    return this;
+  }
+
+  /** sets the {@link ProcessDefinition#getKey() key} of the process definition explicitely */
+  public ProcessFactory key(String key) {
+    processDefinition.setKey(key);
+    return this;
+  }
+
   private void resolveDestinations() {
     if (destinationReferences!=null) {
       for (DestinationReference destinationReference : destinationReferences) {

Modified: jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/pvm.wire.bindings.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/pvm.wire.bindings.xml	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/pvm.wire.bindings.xml	2008-08-29 15:01:00 UTC (rev 2052)
@@ -59,7 +59,7 @@
   <!-- deployers -->
   <binding class="org.jbpm.pvm.internal.wire.binding.DeployerManagerBinding" />
   <binding class="org.jbpm.pvm.internal.wire.binding.CreateProcessBinding" />
-  <binding class="org.jbpm.pvm.internal.wire.binding.VerifyVersionBinding" />
+  <binding class="org.jbpm.pvm.internal.wire.binding.CheckVersionBinding" />
   <binding class="org.jbpm.pvm.internal.wire.binding.SaveProcessBinding" />
   <binding class="org.jbpm.pvm.internal.wire.binding.CreateIdBinding" />
 

Modified: jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/wire.xsd
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/wire.xsd	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/wire.xsd	2008-08-29 15:01:00 UTC (rev 2052)
@@ -1228,15 +1228,36 @@
 	  	    <attribute name="class" type="string" use="required"/>
 		    </complexType>
       </element>
-      <element name="save-process">
-        <annotation><documentation>Deployer that saves the process with
-        the PvmDbSession. 
-	      </documentation></annotation>
+      <element name="check-version">
+        <annotation><documentation>Deployer checks if the version of the 
+        deployed process is exactly 1 more then the last version of the same 
+        process.   If a version already exists, it is left untouched.  
+        If no version exists, by default, this deployer will assign 
+        a version to the process definition that is 1 higher then the 
+        highest deployed version in the DB for that process name.  This 
+        default can be overridden by the 'assign' attribute. 
+        </documentation></annotation>
+        <complexType>
+          <attribute name="assign" default="true">
+            <annotation><documentation>In case there the process definition 
+            has not be given a version explicitely, this attribute specifies 
+            if this deployer should assign a version.  The assigned version 
+            will be 1 higher then the highest version in the db for processes
+            with the same name.  Starting with 1 if no similarly named procses 
+            definitions are found.  
+            </documentation></annotation>
+          </attribute>
+        </complexType>
       </element>
-      <element name="verify-version">
+      <element name="create-id">
         <annotation><documentation>Deployer verifies if the version of the 
         deployed process is exactly 1 more then the last version of the same 
         process. 
+        </documentation></annotation>
+      </element>
+      <element name="save-process">
+        <annotation><documentation>Deployer that saves the process with
+        the PvmDbSession. 
 	      </documentation></annotation>
       </element>
     </choice>

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-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ExecutionServiceTest.java	2008-08-29 15:01:00 UTC (rev 2052)
@@ -29,9 +29,12 @@
 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.activity.ActivityExecution;
+import org.jbpm.pvm.activity.ExternalActivity;
+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;
 
 
@@ -39,10 +42,101 @@
  * @author Tom Baeyens
  */
 public class ExecutionServiceTest extends DbTestCase {
+  
+  public static class WaitState implements ExternalActivity {
+    private static final long serialVersionUID = 1L;
+    public void execute(ActivityExecution execution) {
+      execution.waitForSignal();
+    }
+    public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) {
+      throw new UnsupportedOperationException();
+    }
+  }
 
-  public void testStartExecutionByName() {
+  public void testStartExecutionById() {
     ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
 
+    ClientProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion")
+      .version(1)
+      .key("NCLFU")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+
+    Deployment deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+    
+    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
+
+    Execution execution = executionService.startExecution("NCLFU:1");
+    assertNotNull(execution);
+
+    // checking the state
+    assertEquals("initial", execution.getNodeName());
+
+    // checking the generated id
+    assertNull(execution.getName());
+    assertNull(execution.getKey());
+    // if there is no user defined name or key specified in the execution,
+    // the default id generator will create a unique id like this: processDefinitionId/execution.dbid
+    assertEquals("NCLFU:1/", execution.getId().substring(0,8));
+    Long.parseLong(execution.getId().substring(8));
+  }
+
+  public void testStartExecutionByIdWithKey() {
+    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+  
+    ClientProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion")
+      .version(1)
+      .key("NCLFU")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+  
+    Deployment deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+  
+    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
+  
+    Execution execution = executionService.startExecution("NCLFU:1", "TheFirstTime");
+    assertNotNull(execution);
+  
+    // checking the state
+    assertEquals("initial", execution.getNodeName());
+  
+    // checking the generated id
+    assertNull(execution.getName());
+    assertEquals("TheFirstTime", execution.getKey());
+    // if there is a user provided key in the execution, the default 
+    // id generator will take that to create the id
+    assertEquals("NCLFU:1/TheFirstTime", execution.getId());
+  }
+
+  public void testStartExecutionByIdWithVariables() {
+    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+  
+    ClientProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion")
+      .version(1)
+      .key("NCLFU")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+  
+    processService.deploy(new Deployment(processDefinition));
+  
+    Map<String, Object> variables = new HashMap<String, Object>();
+    variables.put("a", new Integer(1));
+    variables.put("b", "text");
+  
+    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
+  
+    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"));
+  }
+
+  public void testStartExecutionInLatest() {
+    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+
     ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
     processDefinition.setName("nuclear fusion");
     processDefinition.setVersion(1);
@@ -72,35 +166,8 @@
 
     Execution execution = executionService.startExecutionInLatest("nuclear fusion");
     assertNotNull(execution);
-    
-    // TODO fix after refactoring
-    // assertEquals("nuclear fusion", execution.getProcessDefinition().getName());
-    // assertEquals(3, execution.getProcessDefinition().getVersion());
   }
 
-  public void testStartExecutionByKey() {
-    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
-
-    ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("nuclear fusion");
-    processDefinition.setVersion(1);
-    Deployment deployment = new Deployment(processDefinition);
-    processDefinition.setKey("NCLFU");
-    processService.deploy(deployment);
-    
-    ProcessDefinition deployed = processService.findProcessDefinition("nuclear fusion", 1);
-    String processDefinitionId = deployed.getId();
-
-    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
-
-    Execution execution = executionService.startExecution(processDefinitionId);
-    assertNotNull(execution);
-
-    // TODO fix after refactoring
-    // assertEquals("nuclear fusion", execution.getProcessDefinition().getName());
-    // assertEquals(1, execution.getProcessDefinition().getVersion());
-  }
-
   public void testStartExecutionByNameWithVariables() {
     ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
 
@@ -122,64 +189,22 @@
     assertEquals("text", executionService.getVariable(executionDbid, "b"));
   }
   
-  public void testStartExecutionByDbidWithVariables() {
+  public void testStartExecutionByNameWithKey() {
     ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
 
     ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
     processDefinition.setName("nuclear fusion");
     processDefinition.setVersion(1);
     processService.deploy(new Deployment(processDefinition));
-
-    ProcessDefinition deployed = processService.findProcessDefinition("nuclear fusion", 1);
-    String processDefinitionId = deployed.getId();
-
-    Map<String, Object> variables = new HashMap<String, Object>();
-    variables.put("a", new Integer(1));
-    variables.put("b", "text");
-
-    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
-
-    Execution execution = executionService.startExecution(processDefinitionId, variables);
-
-    long executionDbid = execution.getDbid();
-    assertEquals(new Integer(1), executionService.getVariable(executionDbid, "a"));
-    assertEquals("text", executionService.getVariable(executionDbid, "b"));
-  }
-  
-  public void testStartExecutionByNameWithKey() {
-    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
-
-    ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("NuclearFusion");
-    processDefinition.setVersion(1);
-    processService.deploy(new Deployment(processDefinition));
     
     ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
 
-    Execution execution = executionService.startExecutionInLatest("NuclearFusion", "TheFirstTime");
-    assertEquals("NuclearFusion:1/TheFirstTime", execution.getId());
-    assertNotNull(executionService.findExecution("NuclearFusion:1/TheFirstTime"));
+    Execution execution = executionService.startExecutionInLatest("nuclear fusion", "TheFirstTime");
+    assertNotNull(execution);
+    assertEquals("TheFirstTime", execution.getKey());
+    assertEquals("nuclear_fusion:1/TheFirstTime", execution.getId());
   }
   
-  public void testStartExecutionByDbidWithKey() {
-    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
-
-    ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("NuclearFusion");
-    processDefinition.setVersion(1);
-    Deployment deployment = new Deployment(processDefinition);
-    processService.deploy(deployment);
-
-    ProcessDefinition deployed = processService.findProcessDefinition("NuclearFusion", 1);
-    String processDefinitionId = deployed.getId();
-
-    ExecutionService executionService = getEnvironmentFactory().get(ExecutionService.class);
-
-    executionService.startExecution(processDefinitionId, null, "the first time");
-
-    assertNotNull(executionService.findExecution("NuclearFusion", "the first time"));
-  }
-
   public void testFindExecution() {
     ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
 

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-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/svc/ProcessServiceTest.java	2008-08-29 15:01:00 UTC (rev 2052)
@@ -28,7 +28,9 @@
 import org.jbpm.pvm.ProcessDefinition;
 import org.jbpm.pvm.ProcessService;
 import org.jbpm.pvm.PvmException;
+import org.jbpm.pvm.api.db.svc.ExecutionServiceTest.WaitState;
 import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
+import org.jbpm.pvm.model.ProcessFactory;
 import org.jbpm.pvm.test.base.DbTestCase;
 
 /**
@@ -36,24 +38,167 @@
  */
 public class ProcessServiceTest extends DbTestCase {
   
+  public void testSimplestDeployment() {
+    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
 
+    // create the simplest possible process
+    ProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+  
+    // deploy it
+    Deployment deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+    
+    // fetch it back from the process service
+    List<ProcessDefinition> processDefinitions = processService.findProcessDefinitions("nuclear fusion");
+    assertNotNull(processDefinitions);
+    
+    // verify there is only one
+    assertEquals(processDefinitions.toString(), 1, processDefinitions.size());
+    processDefinition = processDefinitions.get(0);
+
+    // verify that it is the right one
+    assertEquals("nuclear fusion", processDefinition.getName());
+  }
+
+  public void testAutomaticVersioning() {
+    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+
+    // create first process and only give it a name
+    ProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+  
+    // deploy it
+    Deployment deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+    
+    // look it up again
+    List<ProcessDefinition> processDefinitions = processService.findProcessDefinitions("nuclear fusion");
+    assertNotNull(processDefinitions);
+    
+    // verify that there is only one
+    assertEquals(processDefinitions.toString(), 1, processDefinitions.size());
+    processDefinition = processDefinitions.get(0);
+    // and check that automatically assigned version starts with 1
+    assertEquals(1, processDefinition.getVersion());
+
+    // create a second process with the same name
+    processDefinition = ProcessFactory.build("nuclear fusion")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+  
+    // deploy the second process
+    deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+    
+    // verify that there now are 2 process definitions with that name
+    processDefinitions = processService.findProcessDefinitions("nuclear fusion");
+    assertNotNull(processDefinitions);
+    assertEquals(processDefinitions.toString(), 2, processDefinitions.size());
+    // the process definitions are ordered by version in descending order
+    // so the first one
+    processDefinition = processDefinitions.get(0);
+    // is the one that is last deployed
+    // and hence it should have the version number 2
+    assertEquals(2, processDefinition.getVersion());
+  }
+
+  public void testUserProvidedVersion() {
+    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+
+    // create a process with a user specified version
+    ProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion")
+      .version(35)
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+
+    // deploy it
+    Deployment deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+    
+    // load it
+    List<ProcessDefinition> processDefinitions = processService.findProcessDefinitions("nuclear fusion");
+    assertNotNull(processDefinitions);
+    assertEquals(processDefinitions.toString(), 1, processDefinitions.size());
+    processDefinition = processDefinitions.get(0);
+    
+    // verify that the user specified version was used 
+    // (and not overwritten by an automatically assigned versioning)
+    assertEquals(35, processDefinition.getVersion());
+  }
+
+  public void testIdGenerationFromName() {
+    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+
+    // specify only a name, no key or version in the process
+    ProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+  
+    Deployment deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+    
+    List<ProcessDefinition> processDefinitions = processService.findProcessDefinitions("nuclear fusion");
+    assertNotNull(processDefinitions);
+    assertEquals(processDefinitions.toString(), 1, processDefinitions.size());
+    processDefinition = processDefinitions.get(0);
+    assertEquals("nuclear fusion", processDefinition.getName());
+    
+    // now check that the generated id.  the id generator always replaces all non-word 
+    // chars [a-zA-Z_0-9] with underscores 
+    assertEquals("nuclear_fusion:1", processDefinition.getId());
+    assertNull(processDefinition.getKey());
+  }
+
+  public void testIdGenerationFromKey() {
+    ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
+
+    // now we specify a name and a key
+    ProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion")
+      .key("NCF")
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+  
+    Deployment deployment = new Deployment(processDefinition);
+    processService.deploy(deployment);
+    
+    List<ProcessDefinition> processDefinitions = processService.findProcessDefinitions("nuclear fusion");
+    assertNotNull(processDefinitions);
+    assertEquals(processDefinitions.toString(), 1, processDefinitions.size());
+    processDefinition = processDefinitions.get(0);
+    assertEquals("nuclear fusion", processDefinition.getName());
+
+    // and we check that the id is based on the key (and not on the name)
+    assertEquals("NCF:1", processDefinition.getId());
+    assertEquals("NCF", processDefinition.getKey());
+  }
+
   public void testDuplicateDeployment() {
     ProcessService processService = getEnvironmentFactory().get(ProcessService.class);
 
-    ProcessDefinitionImpl processDefinition = new ProcessDefinitionImpl();
-    
-    processDefinition.setName("nuclear fusion");
-    processDefinition.setVersion(1);
+    // we create a simple process definition
+    ProcessDefinition processDefinition = ProcessFactory.build("nuclear fusion")
+      .version(1)
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+
+    // deploy it
     processService.deploy(new Deployment(processDefinition));
     
-    processDefinition = new ProcessDefinitionImpl();
-    processDefinition.setName("nuclear fusion");
-    processDefinition.setVersion(1);
+    // then we create a process definition with the same name and version
+    processDefinition = ProcessFactory.build("nuclear fusion")
+      .version(1)
+      .node("initial").initial().behaviour(WaitState.class)
+    .done();
+    
     try {
+      // and then we verify that the deployment fails
       processService.deploy(new Deployment(processDefinition));
       fail("expected exception");
     } catch (PvmException e) {
-      assertTextPresent(e.getMessage(), "process [nuclear fusion|1] already exists");
+      assertTextPresent(e.getMessage(), "process 'nuclear fusion' version 1 already exists");
     }
   }
 

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/samples/ExamplesConfiguration.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/samples/ExamplesConfiguration.java	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/samples/ExamplesConfiguration.java	2008-08-29 15:01:00 UTC (rev 2052)
@@ -62,7 +62,7 @@
   private synchronized static void initialize() {
     if (!isInitialized) {
       isInitialized = true;
-      environmentFactory = new PvmEnvironmentFactory("org/jbpm/pvm/samples/pvm.cfg.xml");
+      environmentFactory = new PvmEnvironmentFactory("environment.cfg.xml");
       processService = environmentFactory.get(ProcessService.class);
       executionService = environmentFactory.get(ExecutionService.class);
       managementService = environmentFactory.get(ManagementService.class);

Deleted: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/samples/pvm.cfg.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/samples/pvm.cfg.xml	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/samples/pvm.cfg.xml	2008-08-29 15:01:00 UTC (rev 2052)
@@ -1,56 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<contexts xmlns="http://jbpm.org/pvm/1.0/wire">
-
-  <environment-factory>    
-    <process-service />
-    <execution-service />
-    <management-service />
-    
-    <job-executor threads="1" auto-start="false" />
-    
-    
-    <command-service>
-      <retry-interceptor />
-      <environment-interceptor />
-      <standard-transaction-interceptor />
-    </command-service>
-
-    <job-test-helper />
-
-    <deployer-manager resource="pvm.language.deployers.xml">
-      <language name="api">
-        <verify-version />
-        <save-process />
-      </language>
-    </deployer-manager>
-  
-    <hibernate-configuration>
-      <properties resource="hibernate.properties" />
-      <mappings resource="org/jbpm/pvm/pvm.hibernate.mappings.xml" />
-      <cache-configuration resource="org/jbpm/pvm/pvm.cache.xml" usage="nonstrict-read-write" />
-    </hibernate-configuration>
-    <hibernate-session-factory />
-
-    <variable-types resource="org/jbpm/pvm/pvm.types.xml" />
-    
-    <business-calendar>
-      <monday    hours="9:00-12:00 and 12:30-17:00"/>
-      <tuesday   hours="9:00-12:00 and 12:30-17:00"/>
-      <wednesday hours="9:00-12:00 and 12:30-17:00"/>
-      <thursday  hours="9:00-12:00 and 12:30-17:00"/>
-      <friday    hours="9:00-12:00 and 12:30-17:00"/>
-      <holiday period="01/07/2008 - 31/08/2008"/>
-    </business-calendar>
-    
-  </environment-factory>
-
-  <environment>
-    <transaction />
-    <hibernate-session />
-    <pvm-db-session />
-    <message-session />
-    <timer-session />
-  </environment>
-
-</contexts>

Modified: jbpm4/pvm/trunk/modules/core/src/test/resources/environment.cfg.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/resources/environment.cfg.xml	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/test/resources/environment.cfg.xml	2008-08-29 15:01:00 UTC (rev 2052)
@@ -4,9 +4,9 @@
 
   <environment-factory>
   
-    <deployer-manager resource="pvm.language.deployers.xml">
+    <deployer-manager>
       <language name="api">
-        <verify-version />
+        <check-version />
         <create-id />
         <save-process />
       </language>

Modified: jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/svc/environment.cfg.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/svc/environment.cfg.xml	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/db/svc/environment.cfg.xml	2008-08-29 15:01:00 UTC (rev 2052)
@@ -6,7 +6,8 @@
   
     <deployer-manager resource="pvm.language.deployers.xml">
       <language name="api">
-        <verify-version />
+        <check-version />
+        <create-id />
         <save-process />
       </language>
     </deployer-manager>

Modified: jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/timer/environment.cfg.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/timer/environment.cfg.xml	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/api/timer/environment.cfg.xml	2008-08-29 15:01:00 UTC (rev 2052)
@@ -18,7 +18,8 @@
 
     <deployer-manager resource="pvm.language.deployers.xml">
       <language name="api">
-        <verify-version />
+        <check-version />
+        <create-id />
         <save-process />
       </language>
     </deployer-manager>

Modified: jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/internal/db/langext/environment.cfg.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/internal/db/langext/environment.cfg.xml	2008-08-29 14:36:00 UTC (rev 2051)
+++ jbpm4/pvm/trunk/modules/core/src/test/resources/org/jbpm/pvm/internal/db/langext/environment.cfg.xml	2008-08-29 15:01:00 UTC (rev 2052)
@@ -6,7 +6,8 @@
   
     <deployer-manager resource="pvm.language.deployers.xml">
       <language name="api">
-        <verify-version />
+        <check-version />
+        <create-id />
         <save-process />
       </language>
     </deployer-manager>




More information about the jbpm-commits mailing list