[jbpm-commits] JBoss JBPM SVN: r3971 - in jbpm4/trunk/modules: api/src/main/java/org/jbpm/history and 10 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Feb 20 05:14:21 EST 2009


Author: tom.baeyens at jboss.com
Date: 2009-02-20 05:14:21 -0500 (Fri, 20 Feb 2009)
New Revision: 3971

Added:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/EndProcessInstance.java
   jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/EndProcessInstanceTest.java
Modified:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/Execution.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionQuery.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstanceQuery.java
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/session/PvmDbSession.java
   jbpm4/trunk/modules/examples/src/test/resources/jbpm.cfg.xml
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessInstance.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ActivityStart.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ProcessInstanceEnd.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ExecutionQueryImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java
   jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.execution.hbm.xml
   jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.history.hbm.xml
   jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java
Log:
added ending of process instances

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/Execution.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/Execution.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/Execution.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -107,8 +107,17 @@
   
   /** indicates that this execution is doing an asynchronous continuation. */
   String STATE_ASYNC = "async";
-  
 
+  /** this execution has been cancelled before it came to completion.
+   * Only history executions might expose this state.  This state can be 
+   * passed in {@link ExecutionService#endProcessInstance(String, String)}.
+   * Make sure that comparisons are 
+   * done with .equals and not with '==' because if executions are 
+   * loaded from persistent storage, a new string is created instead 
+   * of the constants. */
+  String STATE_CANCELLED = "cancelled";
+
+
   long getDbid();
   /** the externally given name or id of this execution. The id of a main 
    * path of execution is null.   Can be used to differentiate concurrent 

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionQuery.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionQuery.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -43,4 +43,5 @@
   ExecutionQuery page(int firstResult, int maxResults);
 
   List<Execution> execute();
+  Execution executeUniqueResult();
 }

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/ExecutionService.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -134,6 +134,9 @@
 
   /** retrieves a map of variables */
   Map<String, Object> getVariables(String executionId, Set<String> variableNames);
+  
+  /** end a process instance */
+  void endProcessInstance(String processInstanceId, String state);
 
   /** delete a process instance */
   void deleteProcessInstance(String processInstanceId);

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstanceQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstanceQuery.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/history/HistoryProcessInstanceQuery.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -36,6 +36,7 @@
   String PROPERTY_STATE = "state";
   String PROPERTY_DURATION = "duration";
 
+  HistoryProcessInstanceQuery processInstanceId(String processInstanceId);
   HistoryProcessInstanceQuery processDefinitionId(String processDefinitionId);
   HistoryProcessInstanceQuery state(String state);
 
@@ -45,4 +46,5 @@
   HistoryProcessInstanceQuery page(int firstResult, int maxResults);
 
   List<HistoryProcessInstance> execute();
+  HistoryProcessInstance executeUniqueResult();
 }

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/session/PvmDbSession.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/session/PvmDbSession.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/session/PvmDbSession.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -23,7 +23,6 @@
 
 import java.util.List;
 
-import org.jbpm.Execution;
 import org.jbpm.client.ClientExecution;
 import org.jbpm.client.ClientProcessDefinition;
 import org.jbpm.job.Job;
@@ -66,10 +65,13 @@
   /** the execution uniquely identified by the given executionKey. */ 
   ClientExecution findExecutionById(String executionId);
 
+  /** the process instance uniquely identified by the given executionKey. */ 
+  ClientExecution findProcessInstanceById(String processInstanceId);
+
   /** the execution uniquely identified by the given processDefinition name 
    * and the execution key. */
-  Execution findExecutionByKey(String processDefinitionName, String executionKey);
-
+  ClientExecution findExecutionByKey(String processDefinitionName, String executionKey);
+  
   /* find ids for all process instances for a given process definition. */
   List<String> findProcessInstanceIds(String processDefinitionId);
 

Modified: jbpm4/trunk/modules/examples/src/test/resources/jbpm.cfg.xml
===================================================================
--- jbpm4/trunk/modules/examples/src/test/resources/jbpm.cfg.xml	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/examples/src/test/resources/jbpm.cfg.xml	2009-02-20 10:14:21 UTC (rev 3971)
@@ -16,6 +16,7 @@
     
     <process-service />
     <execution-service />
+    <history-service />
     <management-service />
     <task-service />
   
@@ -25,7 +26,10 @@
       <standard-transaction-interceptor />
     </command-service>
     
-    <hibernate-configuration resource="examples-hibernate.cfg.xml"/>      
+    <hibernate-configuration resource="examples-hibernate.cfg.xml">      
+      <cache-configuration resource="jbpm.pvm.cache.xml" 
+                           usage="nonstrict-read-write" />
+    </hibernate-configuration>
     
     <hibernate-session-factory />
     
@@ -61,6 +65,7 @@
     <task-db-session />
     <message-session />
     <timer-session />
+    <history-session />
   </transaction-context>
 
 </jbpm-configuration>

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessInstance.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessInstance.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/DeleteProcessInstance.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -40,7 +40,8 @@
   }
 
   public Void execute(Environment environment) throws Exception {
-    Environment.getFromCurrent(PvmDbSession.class).deleteProcessInstance(processInstanceId);
+    PvmDbSession pvmDbSession = Environment.getFromCurrent(PvmDbSession.class);
+    pvmDbSession.deleteProcessInstance(processInstanceId);
     return null;
   }
 

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/EndProcessInstance.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/EndProcessInstance.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/EndProcessInstance.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -0,0 +1,52 @@
+/*
+ * 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.cmd.Command;
+import org.jbpm.env.Environment;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.session.PvmDbSession;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class EndProcessInstance implements Command<Object> {
+
+  private static final long serialVersionUID = 1L;
+  
+  protected String processInstanceId;
+  protected String state;
+  
+  public EndProcessInstance(String processInstanceId, String state) {
+    super();
+    this.processInstanceId = processInstanceId;
+    this.state = state;
+  }
+
+  public Object execute(Environment environment) throws Exception {
+    PvmDbSession pvmDbSession = Environment.getFromCurrent(PvmDbSession.class);
+    ExecutionImpl processInstance = (ExecutionImpl) pvmDbSession.findProcessInstanceById(processInstanceId);
+    processInstance.end(state);
+    return null;
+  }
+}


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

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/HibernatePvmDbSession.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -162,7 +162,7 @@
     return (ClientExecution) query.uniqueResult();
   }
 
-  public Execution findExecutionByKey(String processDefinitionName, String executionKey) {
+  public ClientExecution findExecutionByKey(String processDefinitionName, String executionKey) {
     // query definition can be found at the bottom of resource jbpm.pvm.execution.hbm.xml
     Query query = session.getNamedQuery("findExecutionByKey");
     query.setString("processDefinitionName", processDefinitionName);
@@ -170,6 +170,14 @@
     query.setMaxResults(1);
     return (ClientExecution) query.uniqueResult();
   }
+  
+  public ClientExecution findProcessInstanceById(String processInstanceId) {
+    // query definition can be found at the bottom of resource jbpm.pvm.execution.hbm.xml
+    Query query = session.getNamedQuery("findProcessInstanceById");
+    query.setString("processInstanceId", processInstanceId);
+    query.setMaxResults(1);
+    return (ClientExecution) query.uniqueResult();
+  }
 
   public List<Timer> findTimers(int firstResult, int maxResults) {
     // query definition can be found at the bottom of resource jbpm.pvm.job.hbm.xml

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ActivityStart.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ActivityStart.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ActivityStart.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -39,8 +39,10 @@
   public void process() {
     Session session = Environment.getFromCurrent(Session.class);
 
+    String processInstanceId = execution.getProcessInstance().getId();
+
     HistoryProcessInstance historyProcessInstanceImpl = (HistoryProcessInstance) 
-        session.load(HistoryProcessInstanceImpl.class, execution.getId());
+        session.load(HistoryProcessInstanceImpl.class, processInstanceId);
     
     HistoryActivityInstanceImpl historyActivityInstanceImpl = 
         createHistoryActivityInstance(historyProcessInstanceImpl);

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ProcessInstanceEnd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ProcessInstanceEnd.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/events/ProcessInstanceEnd.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -39,5 +39,7 @@
     HistoryProcessInstanceImpl historyProcessInstanceImpl = (HistoryProcessInstanceImpl) 
         session.load(HistoryProcessInstanceImpl.class, execution.getId());
     historyProcessInstanceImpl.setEndTime(Clock.getCurrentTime());
+    historyProcessInstanceImpl.setState(execution.getState());
+    historyProcessInstanceImpl.setEndActivityName(execution.getActivityName());
   }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/history/model/HistoryProcessInstanceImpl.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -43,10 +43,11 @@
   protected String processInstanceId;
   protected String key;
   protected String state;
+  protected String endActivityName;
   protected Date startTime;
   protected Date endTime;
   protected long duration;
-
+  
   /** only here to get hibernate cascade deletes */
   protected Set<HistoryActivityInstanceImpl> historyActivityInstances;
   
@@ -96,4 +97,13 @@
   public String getProcessDefinitionId() {
     return processDefinitionId;
   }
+  public void setState(String state) {
+    this.state = state;
+  }
+  public String getEndActivityName() {
+    return endActivityName;
+  }
+  public void setEndActivityName(String endActivityName) {
+    this.endActivityName = endActivityName;
+  }
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ExecutionQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ExecutionQueryImpl.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ExecutionQueryImpl.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -26,6 +26,7 @@
 import org.hibernate.Query;
 import org.jbpm.Execution;
 import org.jbpm.ExecutionQuery;
+import org.jbpm.JbpmException;
 import org.jbpm.cmd.CommandService;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
 
@@ -48,6 +49,17 @@
     this.onlyProcessInstances = onlyProcessInstances;
   }
 
+  public Execution executeUniqueResult() {
+    List<Execution> executions = execute();
+    if (executions.isEmpty()) {
+      throw new JbpmException("no execution with these criteria");
+    }
+    if (executions.size()>1) {
+      throw new JbpmException("more then 1 execution with these criteria");
+    }
+    return executions.get(0);
+  }
+
   public List<Execution> execute() {
     return (List<Execution>) commandService.execute(this);
   }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -24,7 +24,10 @@
 import java.util.List;
 
 import org.hibernate.Query;
+import org.jbpm.Execution;
+import org.jbpm.JbpmException;
 import org.jbpm.cmd.CommandService;
+import org.jbpm.history.HistoryProcessInstance;
 import org.jbpm.history.HistoryProcessInstanceQuery;
 import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
 
@@ -38,6 +41,7 @@
   
   protected String processDefinitionId;
   protected String state;
+  protected String processInstanceId;
 
   public HistoryProcessInstanceQueryImpl(CommandService commandService) {
     super(commandService);
@@ -50,6 +54,10 @@
     hql.append(HistoryProcessInstanceImpl.class.getName());
     hql.append(" as hpi ");
     
+    if (processInstanceId!=null) {
+      appendWhereClause(" hpi.id = '"+processInstanceId+"' ", hql);
+    }
+    
     if (processDefinitionId!=null) {
       appendWhereClause(" hpi.processDefinitionId = '"+processDefinitionId+"' ", hql);
     }
@@ -64,10 +72,26 @@
   protected void applyParameters(Query query) {
   }
 
-  public List<org.jbpm.history.HistoryProcessInstance> execute() {
+  public List<HistoryProcessInstance> execute() {
     return (List) commandService.execute(this);
   }
 
+  public HistoryProcessInstance executeUniqueResult() {
+    List<HistoryProcessInstance> historyProcessInstances = execute();
+    if (historyProcessInstances.isEmpty()) {
+      throw new JbpmException("no history process instance with these criteria");
+    }
+    if (historyProcessInstances.size()>1) {
+      throw new JbpmException("more then 1 history process instance with these criteria");
+    }
+    return historyProcessInstances.get(0);
+  }
+
+  public HistoryProcessInstanceQuery processInstanceId(String processInstanceId) {
+    this.processInstanceId = processInstanceId;
+    return this;
+  }
+
   public HistoryProcessInstanceQuery orderAsc(String property) {
     addOrderByClause("hpi."+property+" asc");
     return this;

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	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/ExecutionServiceImpl.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -33,6 +33,7 @@
 import org.jbpm.history.HistoryActivityInstanceQuery;
 import org.jbpm.history.HistoryProcessInstanceQuery;
 import org.jbpm.pvm.internal.cmd.DeleteProcessInstance;
+import org.jbpm.pvm.internal.cmd.EndProcessInstance;
 import org.jbpm.pvm.internal.cmd.FindExecutionsCmd;
 import org.jbpm.pvm.internal.cmd.FindExecutionCmd;
 import org.jbpm.pvm.internal.cmd.GetVariableNamesCmd;
@@ -144,6 +145,10 @@
     return new ExecutionQueryImpl(commandService, true);
   }
 
+  public void endProcessInstance(String processInstanceId, String state) {
+    commandService.execute(new EndProcessInstance(processInstanceId, state));
+  }
+
   public void deleteProcessInstance(String processInstanceId) {
     commandService.execute(new DeleteProcessInstance(processInstanceId));
   }

Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.execution.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.execution.hbm.xml	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.execution.hbm.xml	2009-02-20 10:14:21 UTC (rev 3971)
@@ -118,6 +118,15 @@
     ]]>
   </query>
 
+  <query name="findProcessInstanceById">
+    <![CDATA[
+     select processInstance
+     from org.jbpm.pvm.internal.model.ExecutionImpl as processInstance
+     where processInstance.id = :processInstanceId
+       and processInstance.parent is null
+    ]]>
+  </query>
+
   <query name="findExecutionByKey">
     <![CDATA[
      select execution

Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.history.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.history.hbm.xml	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.pvm.history.hbm.xml	2009-02-20 10:14:21 UTC (rev 3971)
@@ -16,6 +16,7 @@
     <property name="endTime" column="END_" type="timestamp" />
     <property name="duration" column="DURATION_" />
     <property name="state" column="STATE_" />
+    <property name="endActivityName" column="ENDACTIVITY_" />
 
     <many-to-one name="processDefinition" 
                  class="org.jbpm.pvm.internal.model.ProcessDefinitionImpl" 

Added: jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/EndProcessInstanceTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/EndProcessInstanceTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/EndProcessInstanceTest.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -0,0 +1,65 @@
+/*
+ * 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.test.history;
+
+import java.util.List;
+
+import org.jbpm.Execution;
+import org.jbpm.history.HistoryProcessInstance;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class EndProcessInstanceTest extends JbpmTestCase {
+
+  public void testCancelProcessInstance() {
+    deployJpdlXmlString(
+      "<process name='Insurance claim' key='ICL'>" +
+      "  <start>" +
+      "    <transition to='wait' />" +
+      "  </start>" +
+      "  <state name='wait'>" +
+      "    <transition to='end' />" +
+      "  </state>" +
+      "  <end name='end' />" +
+      "</process>"
+    );
+
+    Execution execution = executionService.startProcessInstanceByKey("ICL");
+    String processInstanceId = execution.getId();
+    executionService.endProcessInstance(processInstanceId, Execution.STATE_CANCELLED);
+
+    List<Execution> executions = executionService.createExecutionQuery()
+        .processInstanceId(processInstanceId)
+        .execute();
+    assertEquals(0, executions.size());
+
+    HistoryProcessInstance historyProcessInstance = historyService.createHistoryProcessInstanceQuery()
+      .processInstanceId(processInstanceId)
+      .executeUniqueResult();
+
+    assertNotNull(historyProcessInstance.getEndTime());
+    assertEquals(Execution.STATE_CANCELLED, historyProcessInstance.getState());
+  }
+}


Property changes on: jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/EndProcessInstanceTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java	2009-02-20 10:01:37 UTC (rev 3970)
+++ jbpm4/trunk/modules/test-db/src/main/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java	2009-02-20 10:14:21 UTC (rev 3971)
@@ -23,6 +23,7 @@
 
 import java.util.List;
 
+import org.jbpm.Execution;
 import org.jbpm.history.HistoryProcessInstance;
 import org.jbpm.history.HistoryProcessInstanceQuery;
 import org.jbpm.test.JbpmTestCase;
@@ -61,5 +62,14 @@
       assertNotNull(historyProcessInstance.getStartTime());
       assertNotNull(historyProcessInstance.getEndTime());
     }
+    
+    // also check that the ended process instances have been removed from the 
+    // runtime database
+    List<Execution> executions = executionService
+      .createExecutionQuery()
+      .processDefinitionId("ICL:1")
+      .execute();
+
+    assertEquals(0, executions.size());
   }
 }




More information about the jbpm-commits mailing list