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

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Jan 8 09:17:35 EST 2010


Author: jbarrez
Date: 2010-01-08 09:17:34 -0500 (Fri, 08 Jan 2010)
New Revision: 6065

Added:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/DeleteProcessInstanceTest.java
Modified:
   jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
Log:
JBPM-2679: throw exception when deleting a process instance with an unexisting id

Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java	2010-01-08 13:21:14 UTC (rev 6064)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/ExecutionService.java	2010-01-08 14:17:34 UTC (rev 6065)
@@ -119,10 +119,11 @@
   /** end a process instance */
   void endProcessInstance(String processInstanceId, String state);
 
-  /** delete a process instance.  The history information will still be 
-   * in the database. */
+  /** delete a process instance.  The history information will still be in the database. 
+   * @throws JbpmException if the given processInstanceId doesn't exist*/
   void deleteProcessInstance(String processInstanceId);
 
-  /** delete a process instance, including the history information. */
+  /** delete a process instance, including the history information.
+   *  @throws JbpmException if the given processInstanceId doesn't exist */
   void deleteProcessInstanceCascade(String processInstanceId);
 }

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java	2010-01-08 13:21:14 UTC (rev 6064)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java	2010-01-08 14:17:34 UTC (rev 6065)
@@ -268,10 +268,13 @@
       }
 
       if (log.isDebugEnabled()) {
-        log.debug("deleting process instance "+processInstanceId);
+        log.debug("Deleting process instance " + processInstanceId);
       }
-
       session.delete(processInstance);
+      
+    } else {
+    	throw new JbpmException("Can't delete processInstance " + processInstanceId 
+    			+ ": no processInstance found for the given id");
     }
   }
 

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/DeleteProcessInstanceTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/DeleteProcessInstanceTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/process/DeleteProcessInstanceTest.java	2010-01-08 14:17:34 UTC (rev 6065)
@@ -0,0 +1,93 @@
+/*
+ * 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.process;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.ProcessInstanceQuery;
+import org.jbpm.api.history.HistoryProcessInstanceQuery;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author jorambarrez
+ */
+public class DeleteProcessInstanceTest extends JbpmTestCase {
+
+  private static final String SIMPLE_PROCESS = 
+    "<process name='simpleProcess'>" + 
+    "  <start >" +
+    "    <transition to='wait' />" +
+    "  </start>" +
+    "  <state name='wait' >" +
+    "    <transition to='theEnd' />" +
+    "  </state>" +
+    "  <end name='theEnd' />" +
+    "</process>";
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+    deployJpdlXmlString(SIMPLE_PROCESS);
+  }
+
+  public void testDeleteExistingProcess() {
+    String id = executionService.startProcessInstanceByKey("simpleProcess").getId();
+    ProcessInstanceQuery query = executionService.createProcessInstanceQuery().processInstanceId(id);
+    assertNotNull(query.uniqueResult());
+    
+    executionService.deleteProcessInstance(id);
+    assertNull(query.uniqueResult());
+    
+    HistoryProcessInstanceQuery historyQuery = historyService.createHistoryProcessInstanceQuery().processInstanceId(id);
+    assertNotNull(historyQuery.uniqueResult());
+  }
+  
+  public void testDeleteCascadeExistingProcess() {
+    String id = executionService.startProcessInstanceByKey("simpleProcess").getId();
+    ProcessInstanceQuery query = executionService.createProcessInstanceQuery().processInstanceId(id);
+    assertNotNull(query.uniqueResult());
+    
+    executionService.deleteProcessInstanceCascade(id);
+    assertNull(query.uniqueResult());
+    
+    HistoryProcessInstanceQuery historyQuery = historyService.createHistoryProcessInstanceQuery().processInstanceId(id);
+    assertNull(historyQuery.uniqueResult());
+  }
+  
+  public void testDeleteUnexistingProcessInstance() {
+    try {
+      executionService.deleteProcessInstance("-1");
+      fail("Expected exception");
+    } catch (JbpmException e) {
+      // Exception should've been thrown
+    }
+  }
+  
+  public void testDeleteCascadeUnexistingProcessInstance() {
+    try {
+      executionService.deleteProcessInstanceCascade("-1");
+      fail("Expected exception");
+    } catch (JbpmException e) {
+      // Exception should've been thrown
+    }
+  }
+
+}



More information about the jbpm-commits mailing list