[jbpm-commits] JBoss JBPM SVN: r1848 - in jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db: basicfeatures and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Aug 7 07:50:52 EDT 2008
Author: porcherg
Date: 2008-08-07 07:50:51 -0400 (Thu, 07 Aug 2008)
New Revision: 1848
Added:
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/AutomaticDecisionDbTest.java
jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/BasicExecutionFlowDbTest.java
Log:
api db tests (tests from basicfeatures)
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/AutomaticDecisionDbTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/AutomaticDecisionDbTest.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/AutomaticDecisionDbTest.java 2008-08-07 11:50:51 UTC (rev 1848)
@@ -0,0 +1,105 @@
+/**
+ * Copyright (C) 2007 Bull S. A. S.
+ * Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
+ * This library 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
+ * version 2.1 of the License.
+ * This library 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
+ * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+ * Floor, Boston, MA 02110-1301, USA.
+ **/
+package org.jbpm.pvm.api.db.basicfeatures;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.pvm.Execution;
+import org.jbpm.pvm.activity.Activity;
+import org.jbpm.pvm.activity.ActivityExecution;
+import org.jbpm.pvm.activity.ExternalActivity;
+import org.jbpm.pvm.client.ClientProcessDefinition;
+import org.jbpm.pvm.model.ProcessDefinition;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.pvm.test.base.DbTestCase;
+
+
+/**
+ * @author Guillaume Porcher
+ *
+ */
+public class AutomaticDecisionDbTest extends DbTestCase {
+
+ public static class AutomaticCreditRating implements Activity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ int creditRate = (Integer) execution.getVariable("creditRate");
+
+ if (creditRate > 5) {
+ execution.take("good");
+
+ } else if (creditRate < -5) {
+ execution.take("bad");
+
+ } else {
+ execution.take("average");
+ }
+ }
+ }
+
+ 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) {
+ execution.take(signalName);
+ }
+ }
+
+ public static ClientProcessDefinition createCreditProcess() {
+ return ProcessFactory.build("creditProcess")
+ .node("creditRate?").initial().behaviour(AutomaticCreditRating.class)
+ .transition("good").to("priority delivery")
+ .transition("average").to("bulk delivery")
+ .transition("bad").to("payment upfront")
+ .node("priority delivery").behaviour(WaitState.class)
+ .node("bulk delivery").behaviour(WaitState.class)
+ .node("payment upfront").behaviour(WaitState.class)
+ .done();
+ }
+
+ public void testGoodRating() {
+ ProcessDefinition processDefinition = processService.deploy(createCreditProcess());
+
+ Map<String, Object> variables = new HashMap<String, Object>();
+ variables.put("creditRate", 7);
+
+ Execution execution = executionService.startExecution(processDefinition.getDbid(), variables);
+
+ assertEquals("priority delivery", execution.getNodeName());
+ }
+
+/* public void testAverageRating() {
+ ClientProcessDefinition processDefinition = createCreditProcess();
+
+ ClientProcessInstance execution = processDefinition.createProcessInstance();
+ execution.setVariable("creditRate", 2);
+ execution.begin();
+
+ assertEquals("bulk delivery", execution.getNode().getName());
+ }
+
+ public void testBadRating() {
+ ClientProcessDefinition processDefinition = createCreditProcess();
+
+ ClientProcessInstance execution = processDefinition.createProcessInstance();
+ execution.setVariable("creditRate", -7);
+ execution.begin();
+
+ assertEquals("payment upfront", execution.getNode().getName());
+ }
+*/
+}
Property changes on: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/AutomaticDecisionDbTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/BasicExecutionFlowDbTest.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/BasicExecutionFlowDbTest.java (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/BasicExecutionFlowDbTest.java 2008-08-07 11:50:51 UTC (rev 1848)
@@ -0,0 +1,135 @@
+/**
+ * Copyright (C) 2007 Bull S. A. S.
+ * Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
+ * This library 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
+ * version 2.1 of the License.
+ * This library 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
+ * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+ * Floor, Boston, MA 02110-1301, USA.
+ **/
+package org.jbpm.pvm.api.db.basicfeatures;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.pvm.Execution;
+import org.jbpm.pvm.activity.Activity;
+import org.jbpm.pvm.activity.ActivityExecution;
+import org.jbpm.pvm.activity.ExternalActivity;
+import org.jbpm.pvm.client.ClientProcessDefinition;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.pvm.test.base.DbTestCase;
+
+
+/**
+ * @author Guillaume Porcher
+ *
+ */
+public class BasicExecutionFlowDbTest extends DbTestCase {
+
+ // automatic activity will log an event in a given list
+ public static List<String> recordedEvents;
+
+ public static class AutomaticActivity implements Activity {
+ private static final long serialVersionUID = 1L;
+
+ public void execute(ActivityExecution execution) {
+ recordedEvents.add("execute["+execution.getNodeName()+"]");
+ }
+ }
+
+ public static class WaitState implements ExternalActivity {
+ private static final long serialVersionUID = 1L;
+
+ public void execute(ActivityExecution execution) {
+ recordedEvents.add("execute["+execution.getNodeName()+"]");
+ execution.waitForSignal();
+ }
+ public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
+ recordedEvents.add("signal["+execution.getNodeName()+"]");
+ execution.take(signalName);
+ }
+ }
+
+ public void testChainOfAutomaticActivitiesAndWaitStates() {
+ recordedEvents = new ArrayList<String>();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("myProcess")
+ .node("a").initial().behaviour(new ObjectDescriptor(AutomaticActivity.class))
+ .transition().to("b")
+ .node("b").behaviour(AutomaticActivity.class)
+ .transition().to("c")
+ .node("c").behaviour(WaitState.class)
+ .transition().to("d")
+ .node("d").behaviour(WaitState.class)
+ .transition().to("e")
+ .node("e").behaviour(AutomaticActivity.class)
+ .transition().to("f")
+ .node("f").behaviour(AutomaticActivity.class)
+ .done();
+
+ processService.deploy(processDefinition);
+
+ Execution processInstance = executionService.startExecution(processDefinition.getDbid());
+
+ List<String> expectedEvents = new ArrayList<String>();
+
+ expectedEvents.add("execute[a]");
+ expectedEvents.add("execute[b]");
+ expectedEvents.add("execute[c]");
+
+ assertEquals("c", processInstance.getNodeName());
+ assertFalse(processInstance.isEnded());
+ assertEquals(expectedEvents, recordedEvents);
+
+ processInstance = executionService.signalExecution(processInstance.getDbid());
+
+ expectedEvents.add("signal[c]");
+ expectedEvents.add("execute[d]");
+
+ assertEquals("d", processInstance.getNodeName());
+ assertFalse(processInstance.isEnded());
+ assertEquals(expectedEvents, recordedEvents);
+
+ processInstance = executionService.signalExecution(processInstance.getDbid());
+
+ expectedEvents.add("signal[d]");
+ expectedEvents.add("execute[e]");
+ expectedEvents.add("execute[f]");
+
+ assertEquals("f", processInstance.getNodeName());
+ assertTrue(processInstance.isEnded());
+ assertEquals(expectedEvents, recordedEvents);
+ }
+/*
+ public void testDelayedBegin() {
+ recordedEvents = new ArrayList<String>();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("delayedBegin")
+ .node("a").initial().behaviour(WaitState.class)
+ .done();
+
+ processService.deploy(processDefinition);
+
+ Execution processInstance = executionService.startExecution(processDefinition.getDbid());
+
+ // here, inbetween create and begin of a process instance, the variables can be initialized
+ // or subprocessinstance-superprocessinstance relation can be set up
+
+ // so we verify that the process execution didn't start yet
+ List<String> expectedEvents = new ArrayList<String>();
+ assertEquals(expectedEvents, recordedEvents);
+
+ processInstance.begin();
+
+ expectedEvents.add("execute[a]");
+ assertEquals(expectedEvents, recordedEvents);
+ }
+*/
+}
Property changes on: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/db/basicfeatures/BasicExecutionFlowDbTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the jbpm-commits
mailing list