[jbpm-commits] JBoss JBPM SVN: r5745 - in jbpm4/trunk/modules: test-cactus/src/test/java/org/jbpm/test and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Oct 15 10:09:10 EDT 2009


Author: tom.baeyens at jboss.com
Date: 2009-10-15 10:09:10 -0400 (Thu, 15 Oct 2009)
New Revision: 5745

Added:
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/usertx/
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/usertx/UserTransactionTest.java
Modified:
   jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch02-Incubation.xml
   jbpm4/trunk/modules/test-cactus/src/test/java/org/jbpm/test/AllIntegrationTests.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/HistoryTaskAssigneeTest.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java
Log:
JBPM-2524 enable user domain integration

Modified: jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch02-Incubation.xml
===================================================================
--- jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch02-Incubation.xml	2009-10-15 07:43:28 UTC (rev 5744)
+++ jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch02-Incubation.xml	2009-10-15 14:09:10 UTC (rev 5745)
@@ -708,4 +708,38 @@
     </para>
   </section>
   
+  <section>
+    <title>Transactions</title>
+    <section>
+      <title>Standalone transactions</title>
+      <para>TODO</para>
+    </section>
+    <section>
+      <title>JTA transactions</title>
+      <para>TODO</para>
+    </section>
+    <section>
+      <title>User transactions</title>
+      <para>In your project you might have user domain objects 
+      like e.g. an Order or Claim object in your project mapped with hibernate.
+      This section explains how to combine updates to user domain objects 
+      with jBPM operations in a single transaction.
+      </para>
+      <para>Here's an example of a user command:</para>
+      <programlisting>public class MyUserCommand implements Command&lt;Void&gt; {
+  public Void execute(Environment environment) throws Exception {
+    // your user domain objects
+    
+    // an example jBPM operation
+    ExecutionService executionService = environment.get(ExecutionService.class);
+    executionService.signalExecutionById(executionId);
+    
+    return null;
+  }
+}</programlisting>
+      <para>Then such commands can be executed by the ProcessEngine:</para>
+      <programlisting>processEngine.execute(new MyUserCommand());</programlisting>
+    </section>    
+  </section>
+  
 </chapter>

Modified: jbpm4/trunk/modules/test-cactus/src/test/java/org/jbpm/test/AllIntegrationTests.java
===================================================================
--- jbpm4/trunk/modules/test-cactus/src/test/java/org/jbpm/test/AllIntegrationTests.java	2009-10-15 07:43:28 UTC (rev 5744)
+++ jbpm4/trunk/modules/test-cactus/src/test/java/org/jbpm/test/AllIntegrationTests.java	2009-10-15 14:09:10 UTC (rev 5745)
@@ -116,6 +116,7 @@
     suite.addTestSuite(org.jbpm.test.task.TaskVariablesTest.class);
     suite.addTestSuite(org.jbpm.test.timer.TaskTimerTaskTest.class);
     suite.addTestSuite(org.jbpm.test.timer.TimerTest.class);
+    suite.addTestSuite(org.jbpm.test.usertx.UserTransactionTest.class);
     suite.addTestSuite(org.jbpm.test.variables.BasicVariablesTest.class);
     suite.addTestSuite(org.jbpm.test.variables.VariableBasicTypesTest.class);
     suite.addTestSuite(org.jbpm.test.variables.VariableExpressionTest.class);

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/HistoryTaskAssigneeTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/HistoryTaskAssigneeTest.java	2009-10-15 07:43:28 UTC (rev 5744)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/HistoryTaskAssigneeTest.java	2009-10-15 14:09:10 UTC (rev 5745)
@@ -21,7 +21,6 @@
  */
 package org.jbpm.test.history;
 
-import org.jbpm.api.Execution;
 import org.jbpm.api.history.HistoryActivityInstance;
 import org.jbpm.test.JbpmTestCase;
 

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java	2009-10-15 07:43:28 UTC (rev 5744)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/history/ProcessInstanceHistoryTest.java	2009-10-15 14:09:10 UTC (rev 5745)
@@ -23,11 +23,9 @@
 
 import java.util.List;
 
-import org.jbpm.api.JbpmException;
 import org.jbpm.api.ProcessInstance;
 import org.jbpm.api.history.HistoryProcessInstance;
 import org.jbpm.api.history.HistoryProcessInstanceQuery;
-import org.jbpm.api.task.Task;
 import org.jbpm.test.JbpmTestCase;
 
 

Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/usertx/UserTransactionTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/usertx/UserTransactionTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/usertx/UserTransactionTest.java	2009-10-15 14:09:10 UTC (rev 5745)
@@ -0,0 +1,256 @@
+/*
+ * 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.usertx;
+
+import java.util.List;
+
+import org.jbpm.api.ExecutionService;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.TaskService;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.cmd.Environment;
+import org.jbpm.api.listener.EventListener;
+import org.jbpm.api.listener.EventListenerExecution;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class UserTransactionTest extends JbpmTestCase {
+  
+  public static class TaskSignalCmd implements Command<Void> {
+    private static final long serialVersionUID = 1L;
+    String executionId;
+    public TaskSignalCmd(String executionId) {
+      this.executionId = executionId;
+    }
+    public Void execute(Environment environment) throws Exception {
+      TaskService taskService = environment.get(TaskService.class);
+      Task task = taskService.newTask();
+      taskService.saveTask(task);
+      
+      ExecutionService executionService = environment.get(ExecutionService.class);
+      executionService.signalExecutionById(executionId);
+      
+      return null;
+    }
+  }
+
+  public void testUserTransaction() {
+    deployJpdlXmlString(
+      "<process name='UserTransaction'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a'>" +
+      "    <transition to='b' />" +
+      "  </state>" +
+      "  <state name='b' />" +
+      "</process>"
+    );
+
+    processEngine.execute(new Command<Void>() {
+      private static final long serialVersionUID = 1L;
+      public Void execute(Environment environment) throws Exception {
+        TaskService taskService = environment.get(TaskService.class);
+        Task task = taskService.newTask();
+        taskService.saveTask(task);
+        
+        ExecutionService executionService = environment.get(ExecutionService.class);
+        executionService.startProcessInstanceByKey("UserTransaction");
+        
+        return null;
+      }
+    });
+
+    List<Task> taskList = taskService.createTaskQuery().list();
+    assertEquals(1, taskList.size());
+    
+    List<ProcessInstance> processInstanceList = executionService.createProcessInstanceQuery().list();
+    assertEquals(1, processInstanceList.size());
+    
+    ProcessInstance processInstance = processInstanceList.get(0);
+    assertTrue(processInstance.isActive("a"));
+
+    processEngine.execute(new TaskSignalCmd(processInstance.getId()));
+
+    taskList = taskService.createTaskQuery().list();
+    assertEquals(2, taskList.size());
+    
+    processInstanceList = executionService.createProcessInstanceQuery().list();
+    assertEquals(1, processInstanceList.size());
+
+    processInstance = processInstanceList.get(0);
+    assertTrue(processInstance.isActive("b"));
+
+    // delete tasks
+    for (Task task: taskService.createTaskQuery().list()) {
+      taskService.deleteTaskCascade(task.getId());
+    }
+  }
+  
+  public static class Thrower implements EventListener {
+    private static final long serialVersionUID = 1L;
+    public void notify(EventListenerExecution execution) throws Exception {
+      throw new Exception("regards from inside process execution");
+    }
+  }
+  
+  public void testUserTransactionWithProcessException() {
+    deployJpdlXmlString(
+      "<process name='UserTransactionWithProcessException'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a'>" +
+      "    <transition to='b'>" +
+      "      <event-listener class='"+Thrower.class.getName()+"' />" +
+      "    </transition>" +
+      "  </state>" +
+      "  <state name='b' />" +
+      "</process>"
+    );
+
+    processEngine.execute(new Command<Void>() {
+      private static final long serialVersionUID = 1L;
+      public Void execute(Environment environment) throws Exception {
+        TaskService taskService = environment.get(TaskService.class);
+        Task task = taskService.newTask();
+        taskService.saveTask(task);
+        
+        ExecutionService executionService = environment.get(ExecutionService.class);
+        executionService.startProcessInstanceByKey("UserTransactionWithProcessException");
+        
+        return null;
+      }
+    });
+
+    List<Task> taskList = taskService.createTaskQuery().list();
+    assertEquals(1, taskList.size());
+    
+    List<ProcessInstance> processInstanceList = executionService.createProcessInstanceQuery().list();
+    assertEquals(1, processInstanceList.size());
+    
+    ProcessInstance processInstance = processInstanceList.get(0);
+    assertTrue(processInstance.isActive("a"));
+
+    try {
+      processEngine.execute(new TaskSignalCmd(processInstance.getId()));
+      fail("expected exception");
+    } catch (Exception e) {
+      // OK
+    }
+
+    taskList = taskService.createTaskQuery().list();
+    assertEquals(1, taskList.size());
+    
+    processInstanceList = executionService.createProcessInstanceQuery().list();
+    assertEquals(1, processInstanceList.size());
+
+    processInstance = processInstanceList.get(0);
+    assertTrue(processInstance.isActive("a"));
+
+    // delete tasks
+    for (Task task: taskService.createTaskQuery().list()) {
+      taskService.deleteTaskCascade(task.getId());
+    }
+  }
+
+  public static class SignalWithUserExceptionCmd implements Command<Void> {
+    private static final long serialVersionUID = 1L;
+    String executionId;
+    public SignalWithUserExceptionCmd(String executionId) {
+      this.executionId = executionId;
+    }
+    public Void execute(Environment environment) throws Exception {
+      TaskService taskService = environment.get(TaskService.class);
+      Task task = taskService.newTask();
+      taskService.saveTask(task);
+      
+      ExecutionService executionService = environment.get(ExecutionService.class);
+      executionService.signalExecutionById(executionId);
+      
+      throw new RuntimeException("regards from inside user command"); 
+    }
+  }
+
+  public void testUserTransactionWithUserException() {
+    deployJpdlXmlString(
+      "<process name='UserTransaction'>" +
+      "  <start>" +
+      "    <transition to='a' />" +
+      "  </start>" +
+      "  <state name='a'>" +
+      "    <transition to='b' />" +
+      "  </state>" +
+      "  <state name='b' />" +
+      "</process>"
+    );
+
+    processEngine.execute(new Command<Void>() {
+      private static final long serialVersionUID = 1L;
+      public Void execute(Environment environment) throws Exception {
+        TaskService taskService = environment.get(TaskService.class);
+        Task task = taskService.newTask();
+        taskService.saveTask(task);
+        
+        ExecutionService executionService = environment.get(ExecutionService.class);
+        executionService.startProcessInstanceByKey("UserTransaction");
+        
+        return null;
+      }
+    });
+
+    List<Task> taskList = taskService.createTaskQuery().list();
+    assertEquals(1, taskList.size());
+    
+    List<ProcessInstance> processInstanceList = executionService.createProcessInstanceQuery().list();
+    assertEquals(1, processInstanceList.size());
+    
+    ProcessInstance processInstance = processInstanceList.get(0);
+    assertTrue(processInstance.isActive("a"));
+
+    try {
+      processEngine.execute(new SignalWithUserExceptionCmd(processInstance.getId()));
+      fail("expected exception");
+    } catch (Exception e) {
+      // OK
+    }
+
+    taskList = taskService.createTaskQuery().list();
+    assertEquals(1, taskList.size());
+    
+    processInstanceList = executionService.createProcessInstanceQuery().list();
+    assertEquals(1, processInstanceList.size());
+
+    processInstance = processInstanceList.get(0);
+    assertTrue(processInstance.isActive("a"));
+
+    // delete tasks
+    for (Task task: taskService.createTaskQuery().list()) {
+      taskService.deleteTaskCascade(task.getId());
+    }
+  }
+
+}


Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/usertx/UserTransactionTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the jbpm-commits mailing list