[jbpm-commits] JBoss JBPM SVN: r3560 - in jbpm4/trunk/modules: test-pojo and 8 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Sat Dec 27 08:20:00 EST 2008
Author: tom.baeyens at jboss.com
Date: 2008-12-27 08:20:00 -0500 (Sat, 27 Dec 2008)
New Revision: 3560
Added:
jbpm4/trunk/modules/test-pojo/src/main/
jbpm4/trunk/modules/test-pojo/src/main/java/
jbpm4/trunk/modules/test-pojo/src/main/java/org/
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/AutomaticActivity.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/AutomaticDecisionTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/BasicExecutionFlowTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/EventPropagationTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/EventTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ExceptionHandlerTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ExecutionStateTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ExternalDecisionTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/FunctionalActivityTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/LoopingTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ScopeStateTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ScopeVariableDeclarationTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ScopeVariableTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/SubProcessTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/TransitionAsWaitStateTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/TransitionBasedConcurrencyTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/TransitionEventsTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/VariableTest.java
jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/WaitState.java
jbpm4/trunk/modules/test-pojo/src/main/resources/
jbpm4/trunk/modules/test-pojo/src/main/resources/logging.properties
Removed:
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/AutomaticDecisionTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/BasicExecutionFlowTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/EventPropagationTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/EventTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExceptionHandlerTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExecutionStateTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExternalDecisionTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/FunctionalActivityTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/LoopingTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeStateTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeVariableDeclarationTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeVariableTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/SubProcessTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionAsWaitStateTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionBasedConcurrencyTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionEventsTest.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/VariableTest.java
jbpm4/trunk/modules/test-pojo/src/test/
Modified:
jbpm4/trunk/modules/test-pojo/.classpath
jbpm4/trunk/modules/test-pojo/pom.xml
Log:
fixed test-pojo classpath. moved first pojo tests from pvm to test-pojo module
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/AutomaticDecisionTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/AutomaticDecisionTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/AutomaticDecisionTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,109 +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.api.basicfeatures;
-
-import java.util.Map;
-
-import org.jbpm.activity.Activity;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.client.ClientProcessInstance;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-
-/** shows an automatic decision.
- *
- * @author Tom Baeyens
- */
-public class AutomaticDecisionTest extends JbpmTestCase {
-
- 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()
- .node("creditRate?").initial().behaviour(new AutomaticCreditRating())
- .transition("good").to("priority delivery")
- .transition("average").to("bulk delivery")
- .transition("bad").to("payment upfront")
- .node("priority delivery").behaviour(new WaitState())
- .node("bulk delivery").behaviour(new WaitState())
- .node("payment upfront").behaviour(new WaitState())
- .done();
- }
-
- public void testGoodRating() {
- ClientProcessDefinition processDefinition = createCreditProcess();
-
- ClientProcessInstance execution = processDefinition.createProcessInstance();
- execution.setVariable("creditRate", 7);
- execution.start();
-
- assertEquals("priority delivery", execution.getNode().getName());
- }
-
- public void testAverageRating() {
- ClientProcessDefinition processDefinition = createCreditProcess();
-
- ClientProcessInstance execution = processDefinition.createProcessInstance();
- execution.setVariable("creditRate", 2);
- execution.start();
-
- assertEquals("bulk delivery", execution.getNode().getName());
- }
-
- public void testBadRating() {
- ClientProcessDefinition processDefinition = createCreditProcess();
-
- ClientProcessInstance execution = processDefinition.createProcessInstance();
- execution.setVariable("creditRate", -7);
- execution.start();
-
- assertEquals("payment upfront", execution.getNode().getName());
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/BasicExecutionFlowTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/BasicExecutionFlowTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/BasicExecutionFlowTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,157 +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.api.basicfeatures;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.jbpm.activity.Activity;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.client.ClientProcessInstance;
-import org.jbpm.pvm.example03.AutomaticActivity;
-import org.jbpm.pvm.example03.WaitState;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-/** shows wait states and automatic activities in a simple
- * sequence based on transitions.
- *
- * @author Tom Baeyens
- */
-public class BasicExecutionFlowTest extends JbpmTestCase {
-
- // automatic activity will log an event in a given list
-
- public static class AutomaticActivity implements Activity {
- private static final long serialVersionUID = 1L;
- List<String> events;
- public AutomaticActivity(List<String> events) {
- this.events = events;
- }
- public void execute(ActivityExecution execution) {
- events.add("execute["+execution.getNodeName()+"]");
- }
- }
-
- public static class WaitState implements ExternalActivity {
- private static final long serialVersionUID = 1L;
- List<String> events;
- public WaitState(List<String> events) {
- this.events = events;
- }
- public void execute(ActivityExecution execution) {
- events.add("execute["+execution.getNodeName()+"]");
- execution.waitForSignal();
- }
- public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
- events.add("signal["+execution.getNodeName()+"]");
- execution.take(signalName);
- }
- }
-
- public void testChainOfAutomaticActivitiesAndWaitStates() {
- List<String> recordedEvents = new ArrayList<String>();
- AutomaticActivity automaticActivity = new AutomaticActivity(recordedEvents);
- WaitState waitState = new WaitState(recordedEvents);
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("loan")
- .node("submit loan request").initial().behaviour(automaticActivity)
- .transition().to("evaluate")
- .node("evaluate").behaviour(waitState)
- .transition("approve").to("wire money")
- .transition("reject").to("end")
- .node("wire money").behaviour(automaticActivity)
- .transition().to("archive")
- .node("archive").behaviour(waitState)
- .transition().to("end")
- .node("end").behaviour(waitState)
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- List<String> expectedEvents = new ArrayList<String>();
-
- expectedEvents.add("execute[submit loan request]");
- expectedEvents.add("execute[evaluate]");
-
- assertEquals("evaluate", execution.getNodeName());
- assertEquals(expectedEvents, recordedEvents);
-
- execution.signal("approve");
-
- expectedEvents.add("signal[evaluate]");
- expectedEvents.add("execute[wire money]");
- expectedEvents.add("execute[archive]");
-
- assertEquals("archive", execution.getNodeName());
- assertEquals(expectedEvents, recordedEvents);
-
- execution.signal();
-
- expectedEvents.add("signal[archive]");
- expectedEvents.add("execute[end]");
-
- assertEquals("end", execution.getNodeName());
- assertEquals(expectedEvents, recordedEvents);
- }
-
- public void testDelayedBegin() {
- List<String> recordedEvents = new ArrayList<String>();
- AutomaticActivity automaticActivity = new AutomaticActivity(recordedEvents);
- WaitState waitState = new WaitState(recordedEvents);
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("loan")
- .node("submit loan request").initial().behaviour(automaticActivity)
- .transition().to("evaluate")
- .node("evaluate").behaviour(waitState)
- .transition("approve").to("wire money")
- .transition("reject").to("end")
- .node("wire money").behaviour(automaticActivity)
- .transition().to("archive")
- .node("archive").behaviour(waitState)
- .transition().to("end")
- .node("end").behaviour(waitState)
- .done();
-
-
- ClientProcessInstance processInstance = processDefinition.createProcessInstance();
-
- // here, inbetween create and start 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.start();
-
- expectedEvents.add("execute[submit loan request]");
- expectedEvents.add("execute[evaluate]");
-
- assertEquals("evaluate", processInstance.getNodeName());
- assertEquals(expectedEvents, recordedEvents);
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/EventPropagationTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/EventPropagationTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/EventPropagationTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,358 +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.api.basicfeatures;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.jbpm.activity.Activity;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.listener.EventListener;
-import org.jbpm.listener.EventListenerExecution;
-import org.jbpm.model.Event;
-import org.jbpm.model.Node;
-import org.jbpm.model.ObservableElement;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-/**
- * @author Tom Baeyens
- */
-public class EventPropagationTest extends JbpmTestCase
-{
-
- public class Recorder implements EventListener {
- private static final long serialVersionUID = 1L;
- public List<Object> events = new ArrayList<Object>();
- public void notify(EventListenerExecution execution) {
- ObservableElement element = execution.getEventSource();
- String elementName = element.getName();
- events.add(execution.getEvent()+" on "+(elementName!=null ? elementName : element));
- }
- }
-
- public static class FireableState 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.fire(signalName, execution.getNode());
- }
- }
-
- public static class AutomaticActivity implements Activity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- }
- }
-
- 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){
- }
- }
-
- public void testListenToNodeLeaveOnProcessForProcessNodes(){
- Recorder recorder = new Recorder();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
- .event(Event.NODE_END)
- .listener(recorder)
- .node("initial").initial().behaviour(new WaitState())
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
- execution.signal();
-
- assertEquals("event(node-end) on initial", recorder.events.get(0));
- assertEquals(1, recorder.events.size());
- }
-
- public void testListenToNodeEnterOnProcessForProcessNodes(){
- Recorder recorder = new Recorder();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
- .event(Event.NODE_BEGIN)
- .listener(recorder)
- .node("initial").initial().behaviour(new WaitState())
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
- execution.signal();
-
- assertEquals("event(node-begin) on end", recorder.events.get(0));
- assertEquals(1, recorder.events.size());
- }
-
- public void testListenToTransitionOnProcessForTransitionBetweenProcessNodes(){
- Recorder recorder = new Recorder();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
- .event(Event.TRANSITION_TAKE)
- .listener(recorder)
- .node("initial").initial().behaviour(new WaitState())
- .transition("go").to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
- execution.signal();
-
- assertEquals("event(transition-take) on go", recorder.events.get(0));
- assertEquals(1, recorder.events.size());
- }
-
- // propagation of process elements in composite nodes ///////////////////////
-
- public static class Sequence implements ExternalActivity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- List<Node> nodes = execution.getNode().getNodes();
- if ( (nodes!=null)
- && (!nodes.isEmpty())
- ) {
- execution.execute(nodes.get(0));
- }
- }
- public void signal(ActivityExecution execution, String signal, Map<String, Object> parameters) {
- Node previous = execution.getPreviousNode();
- List<Node> nodes = execution.getNode().getNodes();
- int index = nodes.indexOf(previous);
- index++;
- if (index < nodes.size()) {
- Node next = nodes.get(index);
- execution.execute(next);
- }
- }
- }
-
-
- public void testListenToNodeLeaveOnProcessForSequenceChildNodes(){
- Recorder recorder = new Recorder();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
- .event(Event.NODE_END)
- .listener(recorder)
- .compositeNode("sequence").initial().behaviour(new Sequence())
- .needsPrevious()
- .node("one").behaviour(new WaitState())
- .node("two").behaviour(new WaitState())
- .node("three").behaviour(new WaitState())
- .compositeEnd()
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
- assertEquals(0, recorder.events.size());
- execution.signal();
- assertEquals("event(node-end) on one", recorder.events.get(0));
- assertEquals(1, recorder.events.size());
- execution.signal();
- assertEquals("event(node-end) on two", recorder.events.get(1));
- assertEquals(2, recorder.events.size());
- execution.signal();
- assertEquals("event(node-end) on three", recorder.events.get(2));
- assertEquals(3, recorder.events.size());
- }
-
- public void testListenToNodeLeaveOnProcessForTransitionBetweenSequenceChildNodes(){
- Recorder recorder = new Recorder();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
- .event(Event.NODE_END)
- .listener(recorder)
- .compositeNode("sequence").initial().behaviour(new Sequence())
- .node("one").behaviour(new WaitState())
- .transition().to("two")
- .node("two").behaviour(new WaitState())
- .compositeEnd()
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals(0, recorder.events.size());
- execution.signal();
- assertEquals("event(node-end) on one", recorder.events.get(0));
- assertEquals(1, recorder.events.size());
- execution.signal();
- assertEquals("event(node-end) on two", recorder.events.get(1));
- assertEquals(2, recorder.events.size());
- }
-
-
- public void testListenToNodeEnterOnProcessForSequenceChildNodes(){
- Recorder recorder = new Recorder();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
- .event(Event.NODE_BEGIN)
- .listener(recorder)
- .compositeNode("sequence").initial().behaviour(new Sequence())
- .needsPrevious()
- .node("one").behaviour(new WaitState())
- .node("two").behaviour(new WaitState())
- .node("three").behaviour(new WaitState())
- .compositeEnd()
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
- assertEquals("event(node-begin) on one", recorder.events.get(0));
- assertEquals(1, recorder.events.size());
- execution.signal();
- assertEquals("event(node-begin) on two", recorder.events.get(1));
- assertEquals(2, recorder.events.size());
- execution.signal();
- assertEquals("event(node-begin) on three", recorder.events.get(2));
- assertEquals(3, recorder.events.size());
- }
-
- public void testListenToTransitionTakeOnProcessForTransitionBetweenSequenceChildNodes(){
- Recorder recorder = new Recorder();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
- .event(Event.TRANSITION_TAKE)
- .listener(recorder)
- .compositeNode("sequence").initial().behaviour(new Sequence())
- .node("one").behaviour(new WaitState())
- .transition("increment").to("two")
- .node("two").behaviour(new WaitState())
- .compositeEnd()
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals(0, recorder.events.size());
- execution.signal();
- assertEquals("event(transition-take) on increment", recorder.events.get(0));
- assertEquals(1, recorder.events.size());
- }
-
- public void testDeeplyNestedCustomEvent(){
- Recorder processRecorder = new Recorder();
- Recorder outerRecorder = new Recorder();
- Recorder middelRecorder = new Recorder();
- Recorder innerRecorder = new Recorder();
- Recorder nestedStateRecorder = new Recorder();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
- .event("hello")
- .listener(processRecorder)
- .compositeNode("outer").initial().behaviour(new Sequence())
- .event("hello")
- .listener(outerRecorder)
- .compositeNode("middel").behaviour(new Sequence())
- .event("hello")
- .listener(middelRecorder)
- .compositeNode("inner").behaviour(new Sequence())
- .event("hello")
- .listener(innerRecorder)
- .node("nested state").behaviour(new FireableState())
- .event("hello")
- .listener(nestedStateRecorder)
- .compositeEnd()
- .compositeEnd()
- .compositeEnd()
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals(0, processRecorder.events.size());
- execution.signal("hello");
-
- assertEquals("event(hello) on nested state", processRecorder.events.get(0));
- assertEquals(1, processRecorder.events.size());
-
- assertEquals("event(hello) on nested state", outerRecorder.events.get(0));
- assertEquals(1, outerRecorder.events.size());
-
- assertEquals("event(hello) on nested state", middelRecorder.events.get(0));
- assertEquals(1, middelRecorder.events.size());
-
- assertEquals("event(hello) on nested state", innerRecorder.events.get(0));
- assertEquals(1, innerRecorder.events.size());
-
- assertEquals("event(hello) on nested state", nestedStateRecorder.events.get(0));
- assertEquals(1, nestedStateRecorder.events.size());
- }
-
- public void testPropagatedEventsDisabled(){
- Recorder processRecorder = new Recorder();
- Recorder outerRecorder = new Recorder();
- Recorder middleRecorder = new Recorder();
- Recorder innerRecorder = new Recorder();
- Recorder nestedStateRecorder = new Recorder();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
- .event("hello")
- .listener(processRecorder)
- .compositeNode("outer").initial().behaviour(new Sequence())
- .event("hello")
- .listener(outerRecorder)
- .compositeNode("middle").behaviour(new Sequence())
- .event("hello")
- .listener(middleRecorder)
- .propagationDisabled()
- .compositeNode("inner").behaviour(new Sequence())
- .event("hello")
- .listener(innerRecorder)
- .node("nested state").behaviour(new FireableState())
- .event("hello")
- .listener(nestedStateRecorder)
- .compositeEnd()
- .compositeEnd()
- .compositeEnd()
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- // the middle action should not be executed for an event that was propagated from the nested state
- execution.signal("hello");
-
- assertEquals("event(hello) on nested state", processRecorder.events.get(0));
- assertEquals(1, processRecorder.events.size());
-
- assertEquals("event(hello) on nested state", outerRecorder.events.get(0));
- assertEquals(1, outerRecorder.events.size());
-
- assertEquals(0, middleRecorder.events.size());
-
- assertEquals("event(hello) on nested state", innerRecorder.events.get(0));
- assertEquals(1, innerRecorder.events.size());
-
- assertEquals("event(hello) on nested state", nestedStateRecorder.events.get(0));
- assertEquals(1, nestedStateRecorder.events.size());
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/EventTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/EventTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/EventTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,266 +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.api.basicfeatures;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.jbpm.activity.Activity;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.listener.EventListener;
-import org.jbpm.listener.EventListenerExecution;
-import org.jbpm.model.Event;
-import org.jbpm.model.Node;
-import org.jbpm.model.ObservableElement;
-import org.jbpm.pvm.internal.model.ExecutionImpl;
-import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-/** shows how actions are listeners to following processDefinition events:
- * <ul>
- * <li>node-leave</li>
- * <li>transition</li>
- * <li>node-enter</li>
- * <li>custom event</li>
- * </ul>
- *
- * @author Tom Baeyens
- */
-public class EventTest extends JbpmTestCase {
-
- public static class AutomaticActivity implements Activity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- }
- }
-
- 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);
- }
- }
-
-
- // node leave action ////////////////////////////////////////////////////////
-
- public static class NodeLeaveAction implements EventListener {
- private static final long serialVersionUID = 1L;
- public void notify(EventListenerExecution execution) {
- execution.setVariable("msg", "Kilroy was here");
-
- assertEquals("initial", execution.getNode().getName());
- assertEquals("initial", execution.getEventSource().getName());
- assertEquals("leave node action test", execution.getProcessDefinition().getName());
- assertEquals("end", execution.getTransition().getDestination().getName());
- }
- }
-
- public void testEventListenerOnNodeEnd() {
- NodeLeaveAction nodeLeaveAction = new NodeLeaveAction();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("leave node action test")
- .node("initial").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(nodeLeaveAction)
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("initial", execution.getNode().getName());
- execution.signal();
- assertEquals("Kilroy was here", execution.getVariable("msg"));
- }
-
- // transition action ////////////////////////////////////////////////////////
-
- public static class TransitionAction implements EventListener {
- private static final long serialVersionUID = 1L;
- public void notify(EventListenerExecution execution) throws Exception {
- execution.setVariable("msg", "Kilroy was here");
-
- assertNull(execution.getNode());
- assertEquals("t", execution.getEventSource().getName());
- assertEquals("transition action test", execution.getProcessDefinition().getName());
- assertEquals("end", execution.getTransition().getDestination().getName());
- }
- }
-
- public void testEventListenerOnTransition() {
- TransitionAction transitionAction = new TransitionAction();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("transition action test")
- .node("initial").initial().behaviour(new WaitState())
- .transition("t").to("end")
- .listener(transitionAction)
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("initial", execution.getNode().getName());
- execution.signal("t");
- assertEquals("Kilroy was here", execution.getVariable("msg"));
- }
-
- // node enter action ////////////////////////////////////////////////////////
-
- public static class NodeBeginAction implements EventListener {
- private static final long serialVersionUID = 1L;
- public void notify(EventListenerExecution execution) throws Exception {
- execution.setVariable("msg", "Kilroy was here");
-
- assertEquals("end", execution.getNode().getName());
- assertEquals("end", execution.getEventSource().getName());
- assertEquals("enter node action test", execution.getProcessDefinition().getName());
- assertEquals("end", execution.getTransition().getDestination().getName());
- }
- }
-
- public void testEventListenerOnNodeBegin() {
- NodeBeginAction nodeBeginAction = new NodeBeginAction();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("enter node action test")
- .node("initial").initial().behaviour(new WaitState())
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .event(Event.NODE_BEGIN)
- .listener(nodeBeginAction)
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("initial", execution.getNode().getName());
- execution.signal();
- assertEquals("Kilroy was here", execution.getVariable("msg"));
- }
-
- // custom event ////////////////////////////////////////////////////////////
-
- public static class WaitStateWithCustomEvent implements ExternalActivity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) throws Exception {
- execution.waitForSignal();
- }
- public void signal(ActivityExecution execution, String signal, Map<String, Object> parameters) throws Exception {
- Node node = execution.getNode();
- if ( (signal!=null)
- && (node!=null)
- && (node.hasEvent(signal))
- ) {
- execution.fire(signal, node);
- execution.waitForSignal();
- }
- }
- }
-
- public static class CheckRivetsAction implements EventListener {
- private static final long serialVersionUID = 1L;
- public void notify(EventListenerExecution execution) throws Exception {
- execution.setVariable("msg", "Kilroy was here");
-
- assertEquals("initial", execution.getNode().getName());
- assertEquals("initial", execution.getEventSource().getName());
- assertEquals("custom node action test", execution.getProcessDefinition().getName());
- assertNull(execution.getTransition());
- }
- }
-
- public void testCustomEventInNode() {
- CheckRivetsAction checkRivetsAction = new CheckRivetsAction();
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("custom node action test")
- .node("initial").initial().behaviour(new WaitStateWithCustomEvent())
- .event("end of riveter shift") // http://en.wikipedia.org/wiki/Kilroy_was_here
- .listener(checkRivetsAction)
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("initial", execution.getNode().getName());
- assertNull(execution.getVariable("msg"));
-
- execution.signal("end of riveter shift");
-
- assertEquals("initial", execution.getNode().getName());
- assertEquals("Kilroy was here", execution.getVariable("msg"));
-
- execution.signal();
-
- assertEquals("end", execution.getNode().getName());
- }
-
- public static class EndState implements Activity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) throws Exception {
- execution.end();
- }
- }
-
- public static class RecordingProcessDefinition extends ProcessDefinitionImpl {
- private static final long serialVersionUID = 1L;
- protected ExecutionImpl newProcessInstance() {
- return new RecordingExecution();
- }
- }
-
- public static class RecordingExecution extends ExecutionImpl {
- private static final long serialVersionUID = 1L;
- List<String> events = new ArrayList<String>();
- public void fire(String eventName, ObservableElement eventSource) {
- events.add(eventName+" on "+eventSource);
- }
- }
-
- public void testBasicEventSequence() {
- ClientProcessDefinition processDefinition = ProcessFactory.build("basic", new RecordingProcessDefinition())
- .node("initial").initial().behaviour(new AutomaticActivity())
- .transition().to("end")
- .node("end").behaviour(new EndState())
- .done();
-
- RecordingExecution execution = (RecordingExecution) processDefinition.startProcessInstance();
-
- int index = 0;
- assertEquals("process-begin on processDefinition(basic)", execution.events.get(index));
- index++;
- assertEquals("node-end on node(initial)", execution.events.get(index));
- index++;
- assertEquals("transition-take on (initial)-->(end)", execution.events.get(index));
- index++;
- assertEquals("node-begin on node(end)", execution.events.get(index));
- index++;
- assertEquals("process-end on processDefinition(basic)", execution.events.get(index));
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExceptionHandlerTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExceptionHandlerTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExceptionHandlerTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,325 +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.api.basicfeatures;
-
-import java.util.Map;
-
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.listener.EventListener;
-import org.jbpm.listener.EventListenerExecution;
-import org.jbpm.model.Event;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-/**
- * @author Tom Baeyens
- */
-public class ExceptionHandlerTest extends JbpmTestCase
-{
-
- 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){
- }
- }
-
- public static class Catcher implements EventListener {
- private static final long serialVersionUID = 1L;
- int timesInvoked = 0;
- public void notify(EventListenerExecution execution) {
- timesInvoked++;
- }
- }
-
- public static class Batter implements EventListener {
- private static final long serialVersionUID = 1L;
- public void notify(EventListenerExecution execution) {
- throw new RuntimeException("catch me");
- }
- }
-
- public void testExceptionHandlerOnProcessDefinition() {
- Catcher catcher = new Catcher();
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .exceptionHandler(RuntimeException.class)
- .listener(catcher)
- .exceptionHandlerEnd()
- .node("initial").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(new Batter())
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("initial", execution.getNode().getName());
- assertEquals(0, catcher.timesInvoked);
- execution.signal();
- assertEquals(1, catcher.timesInvoked);
- assertEquals("end", execution.getNode().getName());
- }
-
- public void testExceptionHandlerOnEvent() {
- Catcher catcher = new Catcher();
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("initial").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .exceptionHandler(RuntimeException.class)
- .listener(catcher)
- .exceptionHandlerEnd()
- .listener(new Batter())
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("initial", execution.getNode().getName());
- assertEquals(0, catcher.timesInvoked);
- execution.signal();
- assertEquals(1, catcher.timesInvoked);
- assertEquals("end", execution.getNode().getName());
- }
-
- public void testExceptionHandlerOnAction() {
- Catcher catcher = new Catcher();
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("initial").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(new Batter())
- .exceptionHandler(RuntimeException.class)
- .listener(catcher)
- .exceptionHandlerEnd()
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("initial", execution.getNode().getName());
- assertEquals(0, catcher.timesInvoked);
- execution.signal();
- assertEquals(1, catcher.timesInvoked);
- assertEquals("end", execution.getNode().getName());
- }
-
- public void testExceptionHandlerOnOtherNode() {
- Catcher catcher = new Catcher();
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("initial").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(new Batter())
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .exceptionHandler(RuntimeException.class)
- .listener(catcher)
- .exceptionHandlerEnd()
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("initial", execution.getNode().getName());
- assertEquals(0, catcher.timesInvoked);
- try {
- execution.signal();
- fail("expected exception");
- } catch (RuntimeException e) {
- // OK
- }
- }
-
- public void testExceptionHandlerOnOtherEvent() {
- Catcher catcher = new Catcher();
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("initial").initial().behaviour(new WaitState())
- .event("other")
- .exceptionHandler(RuntimeException.class)
- .listener(catcher)
- .exceptionHandlerEnd()
- .event(Event.NODE_END)
- .listener(new Batter())
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("initial", execution.getNode().getName());
- try {
- execution.signal();
- fail("expected exception");
- } catch (RuntimeException e) {
- // OK
- }
- }
-
- public static class BehavedAction implements EventListener {
- private static final long serialVersionUID = 1L;
- public void notify(EventListenerExecution execution) {
- // behaving. not throwing any exception
- }
- }
-
- public void testExceptionHandlerOnOtherAction() {
- Catcher catcher = new Catcher();
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("initial").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(new BehavedAction())
- .exceptionHandler(RuntimeException.class)
- .listener(catcher)
- .exceptionHandlerEnd()
- .listener(new Batter())
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("initial", execution.getNode().getName());
- try {
- execution.signal();
- fail("expected exception");
- } catch (RuntimeException e) {
- // OK
- }
- }
-
- public void testUnmatchedExceptionHandlerOnAction() {
- Catcher catcher = new Catcher();
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("initial").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(new Batter())
- .exceptionHandler(NullPointerException.class)
- .listener(catcher)
- .exceptionHandlerEnd()
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("initial", execution.getNode().getName());
- try {
- execution.signal();
- fail("expected exception");
- } catch (RuntimeException e) {
- // OK
- }
- }
-
- public static class RethrowingCatcher implements EventListener {
- private static final long serialVersionUID = 1L;
- public void notify(EventListenerExecution execution) {
- // this exception handler will itself throw an exception
- throw new RuntimeException("greetz from the retrhowing catcher");
- }
- }
-
-
- public void testRethrowingExceptionHandler() {
- RethrowingCatcher rethrowingCatcher = new RethrowingCatcher();
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("initial").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(new Batter())
- .exceptionHandler(RuntimeException.class)
- .listener(rethrowingCatcher)
- .exceptionHandlerEnd()
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- try {
- execution.signal();
- fail("expected exception");
- } catch (RuntimeException e) {
- assertTextPresent("greetz from the retrhowing catcher", e.getMessage());
- }
- }
-
- public void testRethrowingExceptionHandlerCaughtByTheOuterExceptionHandler() {
-
- // just like in java, when an exception handler rethrows, the search
- // for a matching exception handler will continue in the outer scope
- // (=the surrounding process element)
-
- RethrowingCatcher rethrowingCatcher = new RethrowingCatcher();
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("initial").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .exceptionHandler(RuntimeException.class)
- .listener(new Catcher())
- .exceptionHandlerEnd()
- .listener(new Batter())
- .exceptionHandler(RuntimeException.class)
- .listener(rethrowingCatcher)
- .exceptionHandlerEnd()
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("initial", execution.getNode().getName());
- execution.signal();
- }
-
- public void testRethrowingExceptionHandlerIgnoredByTheSubsequentExceptionHandlerInTheSameScope() {
-
- // just like in java, subsequent exception handlers will be skipped when the
- // an exception handler rethrows
-
- RethrowingCatcher rethrowingCatcher = new RethrowingCatcher();
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("initial").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(new Batter())
- .exceptionHandler(RuntimeException.class)
- .listener(rethrowingCatcher)
- .exceptionHandlerEnd()
- .exceptionHandler(RuntimeException.class)
- .listener(new Catcher())
- .exceptionHandlerEnd()
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
- try {
- execution.signal();
- fail("expected exception");
- } catch (RuntimeException e) {
- assertTextPresent("greetz from the retrhowing catcher", e.getMessage());
- }
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExecutionStateTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExecutionStateTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExecutionStateTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,197 +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.api.basicfeatures;
-
-import java.util.Map;
-
-import org.jbpm.Execution;
-import org.jbpm.JbpmException;
-import org.jbpm.activity.Activity;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.client.ClientProcessInstance;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-/** shows the basics of the state property on the execution.
- *
- * The state is automatically managed by the execution.
- * An execution can only receive external triggers in case it is in
- * the active state.
- *
- * Nested executions can occur in case of scoped executions
- * and in case of concurrent executions. In both cases, only
- * leave executions in the execution hierarchy are active.
- *
- * Executions are either locked or active. So in any state which
- * is not active, the execution is locked and cannot accept external
- * signals. Executions can be ended in 3 ways:
- *
- * 1) with execution.end() : then the state will be set to 'ended'
- * 2) with execution.cancel() : then the state will be set to 'cancelled'
- * 3) with execution.end(String) : then the state will be set to the
- * given state string. An exception will be raised if the given
- * state maches any of the known states.
- *
- * @author Tom Baeyens
- */
-public class ExecutionStateTest extends JbpmTestCase {
-
- public static class AutomaticActivity implements Activity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- assertEquals(Execution.STATE_ACTIVE, execution.getState());
- }
- }
-
- public static class WaitState implements ExternalActivity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- assertEquals(Execution.STATE_ACTIVE, execution.getState());
- execution.waitForSignal();
- }
- public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) {
- assertEquals(Execution.STATE_ACTIVE, execution.getState());
- execution.take(signalName);
- }
- }
-
- public void testBasicState() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new AutomaticActivity())
- .transition().to("b")
- .node("b").behaviour(new WaitState())
- .transition().to("c")
- .node("c").behaviour(new AutomaticActivity())
- .done();
-
- ClientProcessInstance processInstance = processDefinition.createProcessInstance();
-
- assertEquals(Execution.STATE_CREATED, processInstance.getState());
-
- processInstance.start();
-
- assertEquals(Execution.STATE_ACTIVE, processInstance.getState());
-
- processInstance.signal();
-
- assertEquals(Execution.STATE_ENDED, processInstance.getState());
- }
-
- public void testSignalOnInactiveExecution() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new AutomaticActivity())
- .transition().to("b")
- .node("b").behaviour(new WaitState())
- .scope()
- .transition().to("c")
- .node("c").behaviour(new AutomaticActivity())
- .done();
-
- ClientProcessInstance processInstance = processDefinition.createProcessInstance();
- processInstance.start();
-
- assertEquals(Execution.STATE_INACTIVE, processInstance.getState());
-
- try {
- processInstance.signal();
- fail("expected exception");
- } catch (JbpmException e) {
- // OK
- assertTextPresent("process-instance is not active: inactive", e.getMessage());
- }
- }
-
- public void testCustomEndState() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new AutomaticActivity())
- .transition().to("b")
- .node("b").behaviour(new WaitState())
- .transition().to("c")
- .node("c").behaviour(new AutomaticActivity())
- .done();
-
- ClientProcessInstance processInstance = processDefinition.createProcessInstance();
- processInstance.start();
- processInstance.end("error");
-
- assertEquals("error", processInstance.getState());
-
- try {
- processInstance.signal();
- fail("expected exception");
- } catch (JbpmException e) {
- // OK
- assertTextPresent("process-instance is not active: error", e.getMessage());
- }
- }
-
- public void testInvalidCustomStates() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new AutomaticActivity())
- .transition().to("b")
- .node("b").behaviour(new WaitState())
- .transition().to("c")
- .node("c").behaviour(new AutomaticActivity())
- .done();
-
- ClientProcessInstance processInstance = processDefinition.createProcessInstance();
- processInstance.start();
-
- try {
- processInstance.end("active");
- fail("expected exception");
- } catch (JbpmException e) {
- // OK
- assertTextPresent("invalid end state: active", e.getMessage());
- }
- try {
- processInstance.end("suspended");
- fail("expected exception");
- } catch (JbpmException e) {
- // OK
- assertTextPresent("invalid end state: suspended", e.getMessage());
- }
- try {
- processInstance.end("created");
- fail("expected exception");
- } catch (JbpmException e) {
- // OK
- assertTextPresent("invalid end state: created", e.getMessage());
- }
- try {
- processInstance.end("async");
- fail("expected exception");
- } catch (JbpmException e) {
- // OK
- assertTextPresent("invalid end state: async", e.getMessage());
- }
- try {
- processInstance.end("inactive");
- fail("expected exception");
- } catch (JbpmException e) {
- // OK
- assertTextPresent("invalid end state: inactive", e.getMessage());
- }
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExternalDecisionTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExternalDecisionTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExternalDecisionTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,101 +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.api.basicfeatures;
-
-import junit.framework.TestCase;
-
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.pvm.samples.activities.AutomaticActivity;
-import org.jbpm.pvm.samples.activities.WaitState;
-import org.jbpm.pvm.samples.ex04.Decision;
-import org.jbpm.pvm.model.ProcessFactory;
-
-import java.util.Map;
-
-
-/**
- * @author Tom Baeyens
- */
-public class ExternalDecisionTest extends TestCase {
-
- public static class ExternalDecision implements ExternalActivity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) throws Exception {
- execution.waitForSignal();
- }
- public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
- execution.take(signalName);
- }
- }
-
- 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()
- .node("creditRate?").initial().behaviour(new ExternalDecision())
- .transition("good").to("priority delivery")
- .transition("average").to("bulk delivery")
- .transition("bad").to("payment upfront")
- .node("priority delivery").behaviour(new WaitState())
- .node("bulk delivery").behaviour(new WaitState())
- .node("payment upfront").behaviour(new WaitState())
- .done();
- }
-
- public void testGoodRating() {
- ClientProcessDefinition processDefinition = createCreditProcess();
- ClientExecution execution = processDefinition.startProcessInstance();
-
- execution.signal("good");
-
- assertEquals("priority delivery", execution.getNode().getName());
- }
-
- public void testAverageRating() {
- ClientProcessDefinition processDefinition = createCreditProcess();
- ClientExecution execution = processDefinition.startProcessInstance();
-
- execution.signal("average");
-
- assertEquals("bulk delivery", execution.getNode().getName());
- }
-
- public void testBadRating() {
- ClientProcessDefinition processDefinition = createCreditProcess();
- ClientExecution execution = processDefinition.startProcessInstance();
-
- execution.signal("bad");
-
- assertEquals("payment upfront", execution.getNode().getName());
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/FunctionalActivityTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/FunctionalActivityTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/FunctionalActivityTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,157 +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.api.basicfeatures;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.jbpm.activity.Activity;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.client.ClientProcessInstance;
-import org.jbpm.listener.EventListener;
-import org.jbpm.listener.EventListenerExecution;
-import org.jbpm.model.Node;
-import org.jbpm.model.OpenExecution;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-
-/** shows how functional nodes (nodes that have a specific function
- * not related to control flow) can be implemented.
- *
- * Examples of functional nodes could be sending an email, doing a
- * SQL update on a database, generating a file and so on.
- *
- * Functional nodes can be used as node behaviour in a transition based
- * process, event listener and as node behaviour in nested node
- * execution.
- *
- * @author Tom Baeyens
- */
-public class FunctionalActivityTest extends JbpmTestCase {
-
- public static class FunctionalActivity implements Activity, EventListener {
- private static final long serialVersionUID = 1L;
- List<String> events;
- public FunctionalActivity(List<String> events) {
- this.events = events;
- }
- public void execute(ActivityExecution execution) {
- perform(execution);
- }
- public void notify(EventListenerExecution execution) {
- perform(execution);
- }
- void perform(OpenExecution execution) {
- events.add("performed automatic activity");
- }
- }
-
- public void testFunctionalActivityAsNodeBehaviourWithTransitions() {
- List<String> recordedEvents = new ArrayList<String>();
- FunctionalActivity functionalActivity = new FunctionalActivity(recordedEvents);
-
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(functionalActivity)
- .transition().to("b")
- .node("b").behaviour(functionalActivity)
- .transition().to("c")
- .node("c").behaviour(functionalActivity)
- .done();
-
- ClientProcessInstance processInstance = processDefinition.createProcessInstance();
-
- List<String> expectedEvents = new ArrayList<String>();
-
- assertEquals("a", processInstance.getNodeName());
- assertFalse(processInstance.isEnded());
- assertEquals(expectedEvents, recordedEvents);
-
- processInstance.start();
-
- expectedEvents.add("performed automatic activity");
- expectedEvents.add("performed automatic activity");
- expectedEvents.add("performed automatic activity");
-
- assertEquals(expectedEvents, recordedEvents);
- }
-
-
- public static class AutomaticActivity implements Activity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- }
- }
-
- public void testFunctionalActivityAsEventListener() {
- List<String> recordedEvents = new ArrayList<String>();
- FunctionalActivity functionalActivity = new FunctionalActivity(recordedEvents);
-
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new AutomaticActivity())
- .transition().to("b")
- .listener(functionalActivity)
- .node("b").behaviour(new AutomaticActivity())
- .done();
-
- ClientProcessInstance processInstance = processDefinition.createProcessInstance();
- processInstance.start();
-
- List<String> expectedEvents = new ArrayList<String>();
- expectedEvents.add("performed automatic activity");
-
- assertEquals(expectedEvents, recordedEvents);
- }
-
- public static class Composite implements ExternalActivity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- Node nestedNode = execution.getNode().getNodes().get(0);
- execution.execute(nestedNode);
- }
- public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) {
- }
- }
-
- public void testFunctionalActivityAsNestedNode() {
- List<String> recordedEvents = new ArrayList<String>();
- FunctionalActivity functionalActivity = new FunctionalActivity(recordedEvents);
-
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .compositeNode("a").initial().behaviour(new Composite())
- .node().behaviour(functionalActivity)
- .compositeEnd()
- .done();
-
- ClientProcessInstance processInstance = processDefinition.createProcessInstance();
- processInstance.start();
-
- List<String> expectedEvents = new ArrayList<String>();
- expectedEvents.add("performed automatic activity");
-
- assertEquals(expectedEvents, recordedEvents);
- }
-
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/LoopingTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/LoopingTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/LoopingTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,104 +0,0 @@
-package org.jbpm.pvm.api.basicfeatures;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.jbpm.activity.Activity;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-public class LoopingTest extends JbpmTestCase {
-
- public static class For implements ExternalActivity {
- private static final long serialVersionUID = 1L;
-
- int startIndex = 0;
- int loops;
- int increment = 1;
- String indexKey = "index";
-
- public For(int loops) {
- this.loops = loops;
- }
-
- public void execute(ActivityExecution execution) throws Exception {
- Integer index = (Integer) execution.getVariable(indexKey);
-
- if (index==null) {
- execution.setVariable(indexKey, startIndex);
- execution.take("loop");
-
- } else {
- index++;
- if (index<(startIndex+loops)){
- execution.setVariable(indexKey, index);
- execution.take("loop");
-
- } else {
- execution.removeVariable(indexKey);
- execution.take("done");
- }
- }
- }
- public void signal(ActivityExecution execution, String signal, Map<String, Object> parameters) throws Exception {
- throw new UnsupportedOperationException();
- }
-
- public void setStartIndex(int startIndex) {
- this.startIndex = startIndex;
- }
- public void setLoops(int loops) {
- this.loops = loops;
- }
- public void setIncrement(int increment) {
- this.increment = increment;
- }
- public void setIndexVariable(String indexVariable) {
- this.indexKey = indexVariable;
- }
- }
-
- static List<Object> recordedIndexes = new ArrayList<Object>();
-
- public static class Recorder implements Activity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) throws Exception {
- recordedIndexes.add(execution.getVariable("index"));
- }
- }
-
- 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){
- }
- }
-
- public void testWhile() {
- int loops = 20;
-
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("for").initial().behaviour(new For(loops))
- .transition("loop").to("recorder")
- .transition("done").to("end")
- .node("recorder").behaviour(new Recorder())
- .transition().to("for")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- List<Object> expectedIndexes = new ArrayList<Object>();
- for (int i=0; i<loops; i++) expectedIndexes.add(i);
-
- assertEquals(expectedIndexes, recordedIndexes);
- assertEquals("end", execution.getNode().getName());
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeStateTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeStateTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeStateTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,85 +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.api.basicfeatures;
-
-import java.util.Map;
-
-import org.jbpm.Execution;
-import org.jbpm.activity.Activity;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.client.ClientProcessInstance;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-/**
- * @author Tom Baeyens
- */
-public class ScopeStateTest extends JbpmTestCase
-{
-
- public static class AutomaticActivity implements Activity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- assertEquals(Execution.STATE_ACTIVE, execution.getState());
- }
- }
-
- public static class WaitState implements ExternalActivity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- assertEquals(Execution.STATE_ACTIVE, execution.getState());
- execution.waitForSignal();
- }
- public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
- assertEquals(Execution.STATE_ACTIVE, execution.getState());
- execution.take(signalName);
- }
- }
-
- public void testInactivationWhenCreatingNestedExecution() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new AutomaticActivity())
- .transition().to("b")
- .node("b").behaviour(new WaitState())
- .scope()
- .transition().to("c")
- .node("c").behaviour(new WaitState())
- .done();
-
- ClientProcessInstance processInstance = processDefinition.createProcessInstance();
-
- assertEquals(Execution.STATE_CREATED, processInstance.getState());
-
- processInstance.start();
- Execution scopeExecution = processInstance.getExecutions().iterator().next();
-
- assertEquals(Execution.STATE_INACTIVE, processInstance.getState());
- assertEquals(Execution.STATE_ACTIVE, scopeExecution.getState());
-
- processInstance.signal(scopeExecution);
-
- assertEquals(Execution.STATE_ENDED, scopeExecution.getState());
- assertEquals(Execution.STATE_ACTIVE, processInstance.getState());
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeVariableDeclarationTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeVariableDeclarationTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeVariableDeclarationTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,222 +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.api.basicfeatures;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.model.Node;
-import org.jbpm.model.OpenExecution;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-
-/**
- * @author Tom Baeyens
- */
-public class ScopeVariableDeclarationTest extends JbpmTestCase {
-
- 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 class Composite implements ExternalActivity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- Node child = execution.getNode().getNodes().get(0);
- execution.execute(child);
- }
- public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) {
- }
- }
-
- public void testProcessInstanceVariableDeclaration() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .variable("flight")
- .node("a").initial().behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- assertTrue(processInstance.hasVariable("flight"));
- assertNull(processInstance.getVariable("flight"));
- }
-
- public void testProcessInstanceVariableDeclarationWithInitialValue() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .variable("flight", "B52")
- .node("a").initial().behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- assertTrue(processInstance.hasVariable("flight"));
- assertEquals("B52", processInstance.getVariable("flight"));
- }
-
- public void testNestedScopeDeclarations() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .variable("flight", "B52")
- .compositeNode("outer").behaviour(new Composite())
- .variable("duration", "22 minutes")
- .compositeNode("middle").behaviour(new Composite())
- .variable("altitude", "31000 ft")
- .compositeNode("inner").behaviour(new Composite())
- .variable("passengers", "52")
- .compositeNode("start").initial().behaviour(new WaitState())
- .variable("fuel", "kerosine")
- .compositeEnd()
- .compositeEnd()
- .compositeEnd()
- .compositeEnd()
- .done();
-
- Map<String, Object> expectedVariables = new HashMap<String, Object>();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- expectedVariables.put("flight", "B52");
- assertEquals(expectedVariables, processInstance.getVariables());
-
- OpenExecution outerExecution = processInstance.getExecution("outer");
- expectedVariables.put("duration", "22 minutes");
- assertEquals(expectedVariables, outerExecution.getVariables());
-
- OpenExecution middleExecution = outerExecution.getExecution("middle");
- expectedVariables.put("altitude", "31000 ft");
- assertEquals(expectedVariables, middleExecution.getVariables());
-
- OpenExecution innerExecution = middleExecution.getExecution("inner");
- expectedVariables.put("passengers", "52");
- assertEquals(expectedVariables, innerExecution.getVariables());
-
- OpenExecution startExecution = innerExecution.getExecution("start");
- expectedVariables.put("fuel", "kerosine");
- assertEquals(expectedVariables, startExecution.getVariables());
- }
-
- public void testHiddenVariable() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .variable("flight", "B52")
- .compositeNode("c").behaviour(new Composite())
- .variable("flight", "U2")
- .node("i").initial().behaviour(new WaitState())
- .variable("flight", "C130")
- .compositeEnd()
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
- OpenExecution executionC = processInstance.getExecution("c");
- OpenExecution executionI = executionC.getExecution("i");
-
- assertEquals("B52", processInstance.getVariable("flight"));
- assertEquals("U2", executionC.getVariable("flight"));
- assertEquals("C130", executionI.getVariable("flight"));
- }
-
- public void testAutomaticScopeManagement() {
- /*
- process
- ${flight} = 'B52'
- +--------------------------------------------------------------------+
- | outer |
- | ${duration} = '22 minutes' |
- | +-------------------------------+ |
- | | left-middle | |
- | | ${altitude} = '31000 ft' | |
- | | +---------------------------+ | +----------------------------+ |
- | | | left-inner | | | right-middle | |
- | | | ${passengers} | | | ${customer} = 'coca cola' | |
- | | | +-----------------------+ | | | +--------------------+ | |
- | | | | left-start | -------> | right-inner | | |
- | | | | ${fuel} = 'kerosine' | | | | | ${date} = 'today' | | |
- | | | +-----------------------+ | | | +--------------------+ | |
- | | +---------------------------+ | +----------------------------+ |
- +--------------------------------------------------------------------+
- */
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .variable("flight", "B52")
- .compositeNode("outer").behaviour(new Composite())
- .variable("duration", "22 minutes")
- .compositeNode("left-middle").behaviour(new Composite())
- .variable("altitude", "31000 ft")
- .compositeNode("left-inner").behaviour(new Composite())
- .variable("passengers", "52")
- .compositeNode("left-start").initial().behaviour(new WaitState())
- .variable("fuel", "kerosine")
- .transition().to("right-inner")
- .compositeEnd()
- .compositeEnd()
- .compositeEnd()
- .compositeNode("right-middle").behaviour(new Composite())
- .variable("customer", "coca-cola")
- .compositeNode("right-inner").behaviour(new WaitState())
- .variable("date", "today")
- .compositeEnd()
- .compositeEnd()
- .compositeEnd()
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
- OpenExecution outerExecution = processInstance.getExecution("outer");
- OpenExecution leftMiddleExecution = outerExecution.getExecution("left-middle");
- OpenExecution leftInnerExecution = leftMiddleExecution.getExecution("left-inner");
- OpenExecution leftStartExecution = leftInnerExecution.getExecution("left-start");
-
- Map<String, Object> expectedVariables = new HashMap<String, Object>();
- expectedVariables.put("flight", "B52");
- expectedVariables.put("duration", "22 minutes");
- expectedVariables.put("altitude", "31000 ft");
- expectedVariables.put("passengers", "52");
- expectedVariables.put("fuel", "kerosine");
- assertEquals(expectedVariables, leftStartExecution.getVariables());
-
- processInstance.signal(leftStartExecution);
-
- OpenExecution rightMiddleExecution = outerExecution.getExecution("right-middle");
- OpenExecution rightInnerExecution = rightMiddleExecution.getExecution("right-inner");
-
- expectedVariables = new HashMap<String, Object>();
- expectedVariables.put("flight", "B52");
- expectedVariables.put("duration", "22 minutes");
-
- assertEquals(expectedVariables, outerExecution.getVariables());
-
- expectedVariables.put("customer", "coca-cola");
- assertEquals(expectedVariables, rightMiddleExecution.getVariables());
-
- expectedVariables.put("date", "today");
- assertEquals(expectedVariables, rightInnerExecution.getVariables());
- }
-
-
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeVariableTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeVariableTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeVariableTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,187 +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.api.basicfeatures;
-
-import java.util.Map;
-
-import org.jbpm.JbpmException;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.model.OpenExecution;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-/**
- *
- * +---+ +--------+ +---+
- * | a | | b | | c |
- * | | --> | | --> | |
- * | | | SCOPE! | | |
- * +---+ +--------+ +---+
- *
- * @author Tom Baeyens
- */
-public class ScopeVariableTest extends JbpmTestCase
-{
-
- 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 void testOuterscopeLookup() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .transition().to("b")
- .node("b").behaviour(new WaitState())
- .scope() // !!!!
- .transition().to("c")
- .node("c").behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
- processInstance.setVariable("destination", "anywhere");
-
- processInstance.signal();
-
- OpenExecution bScope = processInstance.getExecution("b");
-
- // check if the global vars are still visible within the scope for b.
- assertEquals("anywhere", bScope.getVariable("destination"));
-
- bScope.createVariable("temp", "23C");
- assertEquals("23C", bScope.getVariable("temp"));
- assertNull(processInstance.getVariable("temp"));
- }
-
- public void testLocalVariableLookup() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .transition().to("b")
- .node("b").behaviour(new WaitState())
- .scope() // !!!!
- .transition().to("c")
- .node("c").behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- processInstance.signal();
- OpenExecution bScope = processInstance.getExecution("b");
-
- bScope.createVariable("temp", "23C");
-
- assertEquals("23C", bScope.getVariable("temp"));
- assertNull(processInstance.getVariable("temp"));
-
- processInstance.signal(bScope);
-
- assertTrue(bScope.isEnded());
- assertNull(processInstance.getVariable("temp"));
- }
-
- public void testLocalVariableUpdate() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .transition().to("b")
- .node("b").behaviour(new WaitState())
- .scope() // !!!!
- .transition().to("c")
- .node("c").behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- processInstance.signal();
- OpenExecution bScope = processInstance.getExecution("b");
-
- bScope.createVariable("temp", "23C");
- bScope.setVariable("temp", "28C");
-
- assertEquals("28C", bScope.getVariable("temp"));
-
- processInstance.signal(bScope);
-
- assertTrue(bScope.isEnded());
- assertNull(processInstance.getVariable("temp"));
- }
-
- public void testDefaultCreationOnGlobalScope() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .transition().to("b")
- .node("b").behaviour(new WaitState())
- .scope() // !!!!
- .transition().to("c")
- .node("c").behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- processInstance.signal();
- OpenExecution bScope = processInstance.getExecution("b");
-
- bScope.setVariable("temp", "28C");
- assertEquals("28C", bScope.getVariable("temp"));
-
- processInstance.signal(bScope);
-
- assertTrue(bScope.isEnded());
- assertEquals("28C", processInstance.getVariable("temp"));
- }
-
- public void testVariableUpdatesOnEndedScope() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .transition().to("b")
- .node("b").behaviour(new WaitState())
- .scope() // !!!!
- .transition().to("c")
- .node("c").behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- processInstance.signal();
- OpenExecution bScope = processInstance.getExecution("b");
-
- bScope.createVariable("temp", "28C");
-
- processInstance.signal(bScope);
-
- try {
- bScope.setVariable("temp", "21C");
- fail("expected exception");
- } catch (JbpmException e) {
- // OK
- assertTextPresent("can't update variable 'temp' on execution[b]", e.getMessage());
- }
- }
-
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/SubProcessTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/SubProcessTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/SubProcessTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,108 +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.api.basicfeatures;
-
-import java.util.Map;
-
-import org.jbpm.activity.Activity;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-/**
- * @author Tom Baeyens
- */
-public class SubProcessTest extends JbpmTestCase
-{
-
- public static class SubProcess implements ExternalActivity {
- private static final long serialVersionUID = 1L;
- ClientProcessDefinition subProcess;
- public SubProcess(ClientProcessDefinition subProcess) {
- this.subProcess = subProcess;
- }
- public void execute(ActivityExecution execution) throws Exception {
- ClientExecution subProcessInstance = execution.beginSubProcessInstance(subProcess);
- if (!subProcessInstance.isEnded()) {
- execution.waitForSignal();
- }
- }
- public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
- }
- }
-
- public static class AutomaticActivity implements Activity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- }
- }
-
- 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){
- }
- }
-
- public static class EndState implements Activity {
- public void execute(ActivityExecution execution) throws Exception {
- execution.end();
- }
- }
-
- public void testSubProcess() {
- ClientProcessDefinition subProcess = ProcessFactory.build("sub")
- .node("sub1").initial().behaviour(new AutomaticActivity())
- .transition().to("sub2")
- .node("sub2").behaviour(new WaitState())
- .transition().to("sub3")
- .node("sub3").behaviour(new EndState())
- .done();
-
- ClientProcessDefinition superProcess = ProcessFactory.build("super")
- .node("super1").initial().behaviour(new AutomaticActivity())
- .transition().to("super2")
- .node("super2").behaviour(new SubProcess(subProcess))
- .transition().to("super3")
- .node("super3").behaviour(new WaitState())
- .done();
-
- ClientExecution superProcesInstance = superProcess.startProcessInstance();
- assertEquals("super2", superProcesInstance.getNode().getName());
-
- ClientExecution subProcessInstance = (ClientExecution) superProcesInstance.getSubProcessInstance();
- assertNotNull(subProcessInstance);
- assertEquals("sub2", subProcessInstance.getNode().getName());
-
- subProcessInstance.signal();
-
- assertEquals("sub3", subProcessInstance.getNode().getName());
- assertTrue(subProcessInstance.isEnded());
-
- assertEquals("super3", superProcesInstance.getNode().getName());
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionAsWaitStateTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionAsWaitStateTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionAsWaitStateTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,83 +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.api.basicfeatures;
-
-import java.util.Map;
-
-import org.jbpm.activity.Activity;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.model.Condition;
-import org.jbpm.model.OpenExecution;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-/** this test shows how to implement a transition that behaves as a
- * wait state.
- *
- * @author Tom Baeyens
- */
-public class TransitionAsWaitStateTest extends JbpmTestCase
-{
-
- public static class AlwaysTrue implements Condition {
- private static final long serialVersionUID = 1L;
- public boolean evaluate(OpenExecution execution) {
- return true;
- }
- };
-
- public static class AutomaticActivity implements Activity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- }
- }
-
- 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){
- }
- }
-
- public void testSmallAmount() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("make loss").initial().behaviour(new AutomaticActivity())
- .transition("use jbpm").to("make profit")
- .waitCondition(new AlwaysTrue())
- .node("make profit").behaviour(new WaitState())
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertNull(execution.getNode());
-
- execution.signal();
-
- assertEquals("make profit", execution.getNode().getName());
- }
-
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionBasedConcurrencyTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionBasedConcurrencyTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionBasedConcurrencyTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,177 +0,0 @@
-package org.jbpm.pvm.api.basicfeatures;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.jbpm.Execution;
-import org.jbpm.activity.Activity;
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.model.Node;
-import org.jbpm.model.OpenExecution;
-import org.jbpm.model.Transition;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-/**
- * concurrent execution where synchronization is done by checking if the
- * number of expected child executions arrived at the join.
- *
- * @author Tom Baeyens
- */
-public class TransitionBasedConcurrencyTest extends JbpmTestCase {
-
- public static class Fork implements Activity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- OpenExecution processInstance = execution.getProcessInstance();
-
- Node node = execution.getNode();
- List<Transition> outgoingTransitions = node.getOutgoingTransitions();
-
- // for each outgoing transition
- for (Transition outgoingTransition: outgoingTransitions) {
- // launch a concurrent path of execution
- String childExecutionName = outgoingTransition.getName();
- // creating the execution will cause the execution to become inactive
- Execution childExecution = execution.createExecution(childExecutionName, processInstance);
- execution.take(outgoingTransition, childExecution);
- }
-
- // if this was the first fork
- if (execution.isProcessInstance()) {
- execution.setNode(null);
- }
- }
- }
-
- public static class Join implements Activity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) throws Exception {
- // end the child execution execution
- // this will also remove the execution from it's parent
- execution.setState(Execution.STATE_INACTIVE);
- execution.waitForSignal();
-
- Node join = execution.getNode();
- List<OpenExecution> joinedExecutions = findJoinedExecutions(execution, join);
-
- if (isComplete(joinedExecutions, join)) {
- endJoinedExecutions(joinedExecutions, execution);
-
- OpenExecution processInstance = execution.getProcessInstance();
-
- Execution outgoingExecution = null;
- if ( processInstance.getExecutions()==null
- || processInstance.getExecutions().isEmpty()
- ) {
- outgoingExecution = processInstance;
- } else {
- outgoingExecution = execution.createExecution(processInstance);
- }
-
- execution.setNode(join, outgoingExecution);
- Transition transition = join.getDefaultTransition();
- execution.take(transition, outgoingExecution);
- }
- }
-
- List<OpenExecution> findJoinedExecutions(OpenExecution execution, Node join) {
- List<OpenExecution> joinedExecutions = new ArrayList<OpenExecution>();
- scanRecursive(execution.getProcessInstance(), join, joinedExecutions);
- return joinedExecutions;
- }
-
- void scanRecursive(OpenExecution execution, Node join, List<OpenExecution> joinedExecutions) {
- // if the execution is positioned in the join
- if (join.equals(execution.getNode())) {
- joinedExecutions.add(execution);
- }
- Collection<OpenExecution> childExecutions = execution.getExecutions();
- if (childExecutions!=null) {
- for (OpenExecution childExecution: childExecutions) {
- scanRecursive(childExecution, join, joinedExecutions);
- }
- }
- }
-
- boolean isComplete(List<OpenExecution> joinedExecutions, Node join) {
- int executionsToJoin = join.getIncomingTransitions().size();
- return (executionsToJoin==joinedExecutions.size());
- }
-
- void endJoinedExecutions(List<OpenExecution> joinedExecutions, ActivityExecution execution) {
- for (OpenExecution joinedExecution: joinedExecutions) {
- execution.end(joinedExecution);
- }
- }
- }
-
- 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 void testTransitionBasedConcurrency() {
-
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("fork").initial().behaviour(new Fork())
- .transition("billing").to("bill")
- .transition("shipping").to("ship")
- .node("bill").behaviour(new WaitState())
- .transition().to("join")
- .node("ship").behaviour(new WaitState())
- .transition().to("join")
- .node("join").behaviour(new Join())
- .transition().to("end")
- .node("end").behaviour(new WaitState())
- .done();
-
- ClientExecution main = processDefinition.startProcessInstance();
-
- assertNull("fork", main.getNode());
- assertEquals(Execution.STATE_INACTIVE, main.getState());
-
- Execution billing = main.getExecution("billing");
- assertNotNull(billing);
- assertEquals("bill", billing.getNodeName());
- assertFalse(billing.isEnded());
-
- Execution shipping = main.getExecution("shipping");
-
- assertNotNull(shipping);
- assertEquals("ship", shipping.getNodeName());
- assertFalse(shipping.isEnded());
- assertTrue(main.getExecutions().contains(billing));
- assertTrue(main.getExecutions().contains(shipping));
-
- main.signal(billing);
-
- assertNull(main.getNodeName());
- assertEquals("join", billing.getNodeName());
- assertEquals("ship", shipping.getNodeName());
- assertEquals(Execution.STATE_ACTIVE, shipping.getState());
- assertEquals(Execution.STATE_INACTIVE, billing.getState());
- assertEquals(Execution.STATE_INACTIVE, main.getState());
-
- main.signal(shipping);
-
- assertEquals(Execution.STATE_ACTIVE, main.getState());
- assertEquals("end", main.getNodeName());
- assertEquals("join", billing.getNodeName());
- assertTrue(billing.isEnded());
- assertEquals("join", shipping.getNodeName());
- assertTrue(shipping.isEnded());
- assertFalse(main.getExecutions().contains(billing));
- assertFalse(main.getExecutions().contains(shipping));
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionEventsTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionEventsTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionEventsTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,454 +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.api.basicfeatures;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.listener.EventListener;
-import org.jbpm.listener.EventListenerExecution;
-import org.jbpm.model.Event;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-/**
- * @author Tom Baeyens
- */
-public class TransitionEventsTest extends JbpmTestCase
-{
-
- 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){
- }
- }
-
- public class Recorder implements EventListener {
- private static final long serialVersionUID = 1L;
- public List<Object> events = new ArrayList<Object>();
- public void notify(EventListenerExecution execution) {
- events.add(execution.getEvent()+" on "+execution.getEventSource());
- }
- }
-
-
- public void testCompositeLeave(){
- Recorder processListener = new Recorder();
- Recorder outsideListener = new Recorder();
- Recorder compositeListener = new Recorder();
- Recorder insideListener = new Recorder();
-
- /*
- +--------------+
- | composite |
- | +--------+ | +---------+
- | | inside |------->| outside |
- | +--------+ | +---------+
- +--------------+
- */
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("leave a super state")
- .event(Event.NODE_END)
- .listener(processListener)
- .event(Event.NODE_BEGIN)
- .listener(processListener)
- .event(Event.TRANSITION_TAKE)
- .listener(processListener)
- .compositeNode("composite")
- .event(Event.NODE_END)
- .listener(compositeListener)
- .event(Event.NODE_BEGIN)
- .listener(compositeListener)
- .event(Event.TRANSITION_TAKE)
- .listener(compositeListener)
- .node("inside").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(insideListener)
- .event(Event.NODE_BEGIN)
- .listener(insideListener)
- .event(Event.TRANSITION_TAKE)
- .listener(insideListener)
- .transition().to("outside")
- .compositeEnd()
- .node("outside").behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(outsideListener)
- .event(Event.NODE_BEGIN)
- .listener(outsideListener)
- .event(Event.TRANSITION_TAKE)
- .listener(outsideListener)
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals(0, processListener.events.size());
- assertEquals(0, outsideListener.events.size());
- assertEquals(0, compositeListener.events.size());
- assertEquals(0, insideListener.events.size());
-
- assertEquals("inside", execution.getNode().getName());
-
- execution.signal();
-
- assertEquals("[event(node-end) on node(inside), " +
- "event(node-end) on node(composite), " +
- "event(transition-take) on (inside)-->(outside), " +
- "event(node-begin) on node(outside)]",
- processListener.events.toString());
-
- assertEquals("[event(node-begin) on node(outside)]",
- outsideListener.events.toString());
-
- assertEquals("[event(node-end) on node(inside), " +
- "event(node-end) on node(composite)]",
- compositeListener.events.toString());
-
- assertEquals("[event(node-end) on node(inside)]",
- insideListener.events.toString());
- }
-
- public void testCompositeEnter(){
- Recorder processListener = new Recorder();
- Recorder outsideListener = new Recorder();
- Recorder compositeListener = new Recorder();
- Recorder insideListener = new Recorder();
-
- /*
- +--------------+
- | composite |
- +---------+ | +--------+ |
- | outside |------>| inside | |
- +---------+ | +--------+ |
- +--------------+
- */
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("enter a super state")
- .event(Event.NODE_END)
- .listener(processListener)
- .event(Event.NODE_BEGIN)
- .listener(processListener)
- .event(Event.TRANSITION_TAKE)
- .listener(processListener)
- .node("outside").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(outsideListener)
- .event(Event.NODE_BEGIN)
- .listener(outsideListener)
- .event(Event.TRANSITION_TAKE)
- .listener(outsideListener)
- .transition().to("inside")
- .compositeNode("composite")
- .event(Event.NODE_END)
- .listener(compositeListener)
- .event(Event.NODE_BEGIN)
- .listener(compositeListener)
- .event(Event.TRANSITION_TAKE)
- .listener(compositeListener)
- .node("inside").behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(insideListener)
- .event(Event.NODE_BEGIN)
- .listener(insideListener)
- .event(Event.TRANSITION_TAKE)
- .listener(insideListener)
- .compositeEnd()
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals(0, processListener.events.size());
- assertEquals(0, outsideListener.events.size());
- assertEquals(0, compositeListener.events.size());
- assertEquals(0, insideListener.events.size());
-
- execution.signal();
-
- assertEquals("[event(node-end) on node(outside), " +
- "event(transition-take) on (outside)-->(inside), " +
- "event(node-begin) on node(composite), " +
- "event(node-begin) on node(inside)]",
- processListener.events.toString());
-
- assertEquals("[event(node-end) on node(outside)]",
- outsideListener.events.toString());
-
- assertEquals("[event(node-begin) on node(composite), " +
- "event(node-begin) on node(inside)]",
- compositeListener.events.toString());
-
- assertEquals("[event(node-begin) on node(inside)]",
- insideListener.events.toString());
- }
-
- public void testSelfTransition(){
- Recorder processListener = new Recorder();
- Recorder compositeListener = new Recorder();
- Recorder insideListener = new Recorder();
-
- /*
- +-----------------+
- | composite |
- | +--------+ |
- | | inside |---+ |
- | | | | |
- | | |<--+ |
- | +--------+ |
- +-----------------+
- */
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("leave a super state")
- .event(Event.NODE_END)
- .listener(processListener)
- .event(Event.NODE_BEGIN)
- .listener(processListener)
- .event(Event.TRANSITION_TAKE)
- .listener(processListener)
- .compositeNode("composite")
- .event(Event.NODE_END)
- .listener(compositeListener)
- .event(Event.NODE_BEGIN)
- .listener(compositeListener)
- .event(Event.TRANSITION_TAKE)
- .listener(compositeListener)
- .node("inside").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(insideListener)
- .event(Event.NODE_BEGIN)
- .listener(insideListener)
- .event(Event.TRANSITION_TAKE)
- .listener(insideListener)
- .transition().to("inside")
- .compositeEnd()
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals(0, processListener.events.size());
- assertEquals(0, compositeListener.events.size());
- assertEquals(0, insideListener.events.size());
-
- assertEquals("inside", execution.getNode().getName());
-
- execution.signal();
-
- assertEquals("[event(node-end) on node(inside), " +
- "event(transition-take) on (inside)-->(inside), " +
- "event(node-begin) on node(inside)]",
- processListener.events.toString());
-
- assertEquals("[event(node-end) on node(inside), " +
- "event(transition-take) on (inside)-->(inside), " +
- "event(node-begin) on node(inside)]",
- compositeListener.events.toString());
-
- assertEquals("[event(node-end) on node(inside), " +
- "event(node-begin) on node(inside)]",
- insideListener.events.toString());
- }
-
-
- public void testCompositeLeaveInheritedTransition(){
- Recorder processListener = new Recorder();
- Recorder outsideListener = new Recorder();
- Recorder compositeListener = new Recorder();
- Recorder insideListener = new Recorder();
-
- /*
- +--------------+ +---------+
- | composite |------->| outside |
- | +--------+ | +---------+
- | | inside | |
- | +--------+ |
- +--------------+
- */
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("leave a super state")
- .event(Event.NODE_END)
- .listener(processListener)
- .event(Event.NODE_BEGIN)
- .listener(processListener)
- .event(Event.TRANSITION_TAKE)
- .listener(processListener)
- .compositeNode("composite")
- .event(Event.NODE_END)
- .listener(compositeListener)
- .event(Event.NODE_BEGIN)
- .listener(compositeListener)
- .event(Event.TRANSITION_TAKE)
- .listener(compositeListener)
- .transition().to("outside")
- .node("inside").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(insideListener)
- .event(Event.NODE_BEGIN)
- .listener(insideListener)
- .event(Event.TRANSITION_TAKE)
- .listener(insideListener)
- .compositeEnd()
- .node("outside").behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(outsideListener)
- .event(Event.NODE_BEGIN)
- .listener(outsideListener)
- .event(Event.TRANSITION_TAKE)
- .listener(outsideListener)
- .done();
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals(0, processListener.events.size());
- assertEquals(0, outsideListener.events.size());
- assertEquals(0, compositeListener.events.size());
- assertEquals(0, insideListener.events.size());
-
- assertEquals("inside", execution.getNode().getName());
-
- execution.signal();
-
- assertEquals("[event(node-end) on node(inside), " +
- "event(node-end) on node(composite), " +
- "event(transition-take) on (composite)-->(outside), " +
- "event(node-begin) on node(outside)]",
- processListener.events.toString());
-
- assertEquals("[event(node-begin) on node(outside)]",
- outsideListener.events.toString());
-
- assertEquals("[event(node-end) on node(inside), " +
- "event(node-end) on node(composite)]",
- compositeListener.events.toString());
-
- assertEquals("[event(node-end) on node(inside)]",
- insideListener.events.toString());
- }
-
- public void testCompositeLeaveInheritedTransitionExtraNesting(){
- Recorder processListener = new Recorder();
- Recorder sourceOutsideListener = new Recorder();
- Recorder sourceMiddleListener = new Recorder();
- Recorder sourceInsideListener = new Recorder();
- Recorder destinationOutsideListener = new Recorder();
- Recorder destinationInsideListener = new Recorder();
-
- /*
- +--------------------------+
- | source outside |
- | +--------------------+ | +--------------------------+
- | | source middle | | | destination outside |
- | | +---------------+ | | | +--------------------+ |
- | | | source inside | |----------->| destination inside | |
- | | +---------------+ | | | +--------------------+ |
- | +--------------------+ | +--------------------------+
- +--------------------------+
- */
-
- ClientProcessDefinition processDefinition = ProcessFactory.build("leave a super state")
- .event(Event.NODE_END)
- .listener(processListener)
- .event(Event.NODE_BEGIN)
- .listener(processListener)
- .event(Event.TRANSITION_TAKE)
- .listener(processListener)
- .compositeNode("source outside")
- .event(Event.NODE_END)
- .listener(sourceOutsideListener)
- .event(Event.NODE_BEGIN)
- .listener(sourceOutsideListener)
- .event(Event.TRANSITION_TAKE)
- .listener(sourceOutsideListener)
- .compositeNode("source middle")
- .event(Event.NODE_END)
- .listener(sourceMiddleListener)
- .event(Event.NODE_BEGIN)
- .listener(sourceMiddleListener)
- .event(Event.TRANSITION_TAKE)
- .listener(sourceMiddleListener)
- .transition().to("destination inside")
- .node("source inside").initial().behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(sourceInsideListener)
- .event(Event.NODE_BEGIN)
- .listener(sourceInsideListener)
- .event(Event.TRANSITION_TAKE)
- .listener(sourceInsideListener)
- .compositeEnd()
- .compositeEnd()
- .compositeNode("destination outside")
- .event(Event.NODE_END)
- .listener(destinationOutsideListener)
- .event(Event.NODE_BEGIN)
- .listener(destinationOutsideListener)
- .event(Event.TRANSITION_TAKE)
- .listener(destinationOutsideListener)
- .node("destination inside").behaviour(new WaitState())
- .event(Event.NODE_END)
- .listener(destinationInsideListener)
- .event(Event.NODE_BEGIN)
- .listener(destinationInsideListener)
- .event(Event.TRANSITION_TAKE)
- .listener(destinationInsideListener)
- .compositeEnd()
- .done();
-
-
- ClientExecution execution = processDefinition.startProcessInstance();
-
- assertEquals("source inside", execution.getNode().getName());
-
- execution.signal();
-
- assertEquals("[event(node-end) on node(source inside), " +
- "event(node-end) on node(source middle), " +
- "event(node-end) on node(source outside), " +
- "event(transition-take) on (source middle)-->(destination inside), " +
- "event(node-begin) on node(destination outside), " +
- "event(node-begin) on node(destination inside)]",
- processListener.events.toString());
-
- assertEquals("[event(node-end) on node(source inside), " +
- "event(node-end) on node(source middle), " +
- "event(node-end) on node(source outside)]",
- sourceOutsideListener.events.toString());
-
- assertEquals("[event(node-end) on node(source inside), " +
- "event(node-end) on node(source middle)]",
- sourceMiddleListener.events.toString());
-
- assertEquals("[event(node-end) on node(source inside)]",
- sourceInsideListener.events.toString());
-
- assertEquals("[event(node-begin) on node(destination outside), " +
- "event(node-begin) on node(destination inside)]",
- destinationOutsideListener.events.toString());
-
- assertEquals("[event(node-begin) on node(destination inside)]",
- destinationInsideListener.events.toString());
- }
-}
Deleted: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/VariableTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/VariableTest.java 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/VariableTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,248 +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.api.basicfeatures;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.jbpm.activity.ActivityExecution;
-import org.jbpm.activity.ExternalActivity;
-import org.jbpm.client.ClientExecution;
-import org.jbpm.client.ClientProcessDefinition;
-import org.jbpm.client.ClientProcessInstance;
-import org.jbpm.pvm.model.ProcessFactory;
-import org.jbpm.test.JbpmTestCase;
-
-/**
- * @author Tom Baeyens
- */
-public class VariableTest extends JbpmTestCase {
-
- 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){
- }
- }
-
- public void testSetAndGetVariable() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- processInstance.setVariable("customer", "coca-cola");
- assertEquals("coca-cola", processInstance.getVariable("customer"));
-
- processInstance.setVariable("address", "usa");
- assertEquals("usa", processInstance.getVariable("address"));
-
- processInstance.setVariable("size", "big");
- assertEquals("big", processInstance.getVariable("size"));
- }
-
- public void testHasVariable() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- processInstance.setVariable("customer", "coca-cola");
-
- assertTrue(processInstance.hasVariable("customer"));
- assertFalse(processInstance.hasVariable("address"));
- }
-
- public void testSetVariables() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- Map<String, Object> variables = new HashMap<String, Object>();
- variables.put("customer", "coca-cola");
- variables.put("address", "usa");
- variables.put("size", "big");
-
- processInstance.setVariables(variables);
-
- assertEquals("coca-cola", processInstance.getVariable("customer"));
- assertEquals("usa", processInstance.getVariable("address"));
- assertEquals("big", processInstance.getVariable("size"));
- }
-
- public void testGetVariables() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- processInstance.setVariable("customer", "coca-cola");
- processInstance.setVariable("address", "usa");
- processInstance.setVariable("size", "big");
-
- Map<String, Object> expectedVariables = new HashMap<String, Object>();
- expectedVariables.put("customer", "coca-cola");
- expectedVariables.put("address", "usa");
- expectedVariables.put("size", "big");
- assertEquals(expectedVariables, processInstance.getVariables());
- }
-
- public void testRemoveVariable() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- processInstance.setVariable("customer", "coca-cola");
- processInstance.setVariable("address", "usa");
- processInstance.setVariable("size", "big");
-
- Map<String, Object> expectedVariables = new HashMap<String, Object>();
- expectedVariables.put("customer", "coca-cola");
- expectedVariables.put("address", "usa");
- expectedVariables.put("size", "big");
-
- assertEquals(expectedVariables, processInstance.getVariables());
-
- processInstance.removeVariable("address");
- expectedVariables.remove("address");
-
- assertEquals(expectedVariables, processInstance.getVariables());
-
- processInstance.removeVariable("customer");
- expectedVariables.remove("customer");
-
- assertEquals(expectedVariables, processInstance.getVariables());
-
- processInstance.removeVariable("size");
- expectedVariables.remove("size");
-
- assertEquals(expectedVariables, processInstance.getVariables());
- }
-
- public void testRemoveVariables() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- processInstance.setVariable("customer", "coca-cola");
- processInstance.setVariable("address", "usa");
- processInstance.setVariable("size", "big");
-
- processInstance.removeVariables();
-
- Map<String, Object> expectedVariables = new HashMap<String, Object>();
- assertEquals(expectedVariables, processInstance.getVariables());
- }
-
- public void testGetVariableKeys() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- processInstance.setVariable("customer", "coca-cola");
- processInstance.setVariable("address", "usa");
- processInstance.setVariable("size", "big");
-
- Set<String> expectedVariableKeys = new HashSet<String>();
- expectedVariableKeys.add("customer");
- expectedVariableKeys.add("address");
- expectedVariableKeys.add("size");
- assertEquals(expectedVariableKeys, new HashSet<String>(processInstance.getVariableKeys()));
- }
-
- public void testGetUnexistingVariable() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- assertNull(processInstance.getVariable("answer to life, the universe and everything"));
- }
-
- public static class VariableActivity implements ExternalActivity {
- private static final long serialVersionUID = 1L;
- public void execute(ActivityExecution execution) {
- assertEquals("coca-cola", execution.getVariable("customer"));
- execution.setVariable("message", "Killroy was here");
- execution.waitForSignal();
- }
- public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) {
- }
- }
-
- public void testInitialiseVariablesBeforeProcessInstanceBegin() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new VariableActivity())
- .done();
-
- // here, the process instance is created first, and only later it is begun
- ClientProcessInstance processInstance = processDefinition.createProcessInstance();
- processInstance.setVariable("customer", "coca-cola");
- processInstance.start();
- assertEquals("Killroy was here", processInstance.getVariable("message"));
- }
-
- public void testNullValue() {
- ClientProcessDefinition processDefinition = ProcessFactory.build()
- .node("a").initial().behaviour(new WaitState())
- .done();
-
- ClientExecution processInstance = processDefinition.startProcessInstance();
-
- processInstance.setVariable("niks", null);
- processInstance.setVariable("nada", null);
-
- assertTrue(processInstance.hasVariables());
- assertTrue(processInstance.hasVariable("niks"));
- assertTrue(processInstance.hasVariable("nada"));
-
- assertNull(processInstance.getVariable("niks"));
- assertNull(processInstance.getVariable("nada"));
-
- Set<String> expectedKeys = new HashSet<String>();
- expectedKeys.add("niks");
- expectedKeys.add("nada");
- assertEquals(expectedKeys, new HashSet<String>(processInstance.getVariableKeys()));
-
- Map<String, Object> expectedVariables = new HashMap<String, Object>();
- expectedVariables.put("niks", null);
- expectedVariables.put("nada", null);
- assertEquals(expectedVariables, new HashMap<String, Object>(processInstance.getVariables()));
- }
-
-}
Modified: jbpm4/trunk/modules/test-pojo/.classpath
===================================================================
--- jbpm4/trunk/modules/test-pojo/.classpath 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/test-pojo/.classpath 2008-12-27 13:20:00 UTC (rev 3560)
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
- <classpathentry kind="output" path="target/test-classes"/>
+ <classpathentry kind="output" path="target/classes"/>
</classpath>
Modified: jbpm4/trunk/modules/test-pojo/pom.xml
===================================================================
--- jbpm4/trunk/modules/test-pojo/pom.xml 2008-12-27 13:00:42 UTC (rev 3559)
+++ jbpm4/trunk/modules/test-pojo/pom.xml 2008-12-27 13:20:00 UTC (rev 3560)
@@ -40,11 +40,27 @@
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
+
+ <!-- TODO remove this once process factory api is complete -->
+ <dependency>
+ <groupId>org.jbpm.jbpm4</groupId>
+ <artifactId>jbpm-pvm</artifactId>
+ <version>${version}</version>
+ </dependency>
+
</dependencies>
<!-- Plugins -->
<build>
<plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <testSourceDirectory>src/main/java</testSourceDirectory>
+ <classesDirectory>target/classes</classesDirectory>
+ <testClassesDirectory>target/classes</testClassesDirectory>
+ </configuration>
+ </plugin>
</plugins>
</build>
Added: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/AutomaticActivity.java
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/AutomaticActivity.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/AutomaticActivity.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,37 @@
+/*
+ * 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.activities;
+
+import org.jbpm.activity.Activity;
+import org.jbpm.activity.ActivityExecution;
+
+/**
+ * @author Tom Baeyens
+ */
+public class AutomaticActivity implements Activity {
+
+ private static final long serialVersionUID = 1L;
+
+ public void execute(ActivityExecution execution) throws Exception {
+ }
+
+}
Property changes on: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/AutomaticActivity.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/AutomaticDecisionTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/AutomaticDecisionTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/AutomaticDecisionTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/AutomaticDecisionTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,109 @@
+/*
+ * 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.activities;
+
+import java.util.Map;
+
+import org.jbpm.activity.Activity;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.client.ClientProcessInstance;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+
+/** shows an automatic decision.
+ *
+ * @author Tom Baeyens
+ */
+public class AutomaticDecisionTest extends JbpmTestCase {
+
+ 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()
+ .node("creditRate?").initial().behaviour(new AutomaticCreditRating())
+ .transition("good").to("priority delivery")
+ .transition("average").to("bulk delivery")
+ .transition("bad").to("payment upfront")
+ .node("priority delivery").behaviour(new WaitState())
+ .node("bulk delivery").behaviour(new WaitState())
+ .node("payment upfront").behaviour(new WaitState())
+ .done();
+ }
+
+ public void testGoodRating() {
+ ClientProcessDefinition processDefinition = createCreditProcess();
+
+ ClientProcessInstance execution = processDefinition.createProcessInstance();
+ execution.setVariable("creditRate", 7);
+ execution.start();
+
+ assertEquals("priority delivery", execution.getNode().getName());
+ }
+
+ public void testAverageRating() {
+ ClientProcessDefinition processDefinition = createCreditProcess();
+
+ ClientProcessInstance execution = processDefinition.createProcessInstance();
+ execution.setVariable("creditRate", 2);
+ execution.start();
+
+ assertEquals("bulk delivery", execution.getNode().getName());
+ }
+
+ public void testBadRating() {
+ ClientProcessDefinition processDefinition = createCreditProcess();
+
+ ClientProcessInstance execution = processDefinition.createProcessInstance();
+ execution.setVariable("creditRate", -7);
+ execution.start();
+
+ assertEquals("payment upfront", execution.getNode().getName());
+ }
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/BasicExecutionFlowTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/BasicExecutionFlowTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/BasicExecutionFlowTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/BasicExecutionFlowTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,155 @@
+/*
+ * 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.activities;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.activity.Activity;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.client.ClientProcessInstance;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+/** shows wait states and automatic activities in a simple
+ * sequence based on transitions.
+ *
+ * @author Tom Baeyens
+ */
+public class BasicExecutionFlowTest extends JbpmTestCase {
+
+ // automatic activity will log an event in a given list
+
+ public static class AutomaticActivity implements Activity {
+ private static final long serialVersionUID = 1L;
+ List<String> events;
+ public AutomaticActivity(List<String> events) {
+ this.events = events;
+ }
+ public void execute(ActivityExecution execution) {
+ events.add("execute["+execution.getNodeName()+"]");
+ }
+ }
+
+ public static class WaitState implements ExternalActivity {
+ private static final long serialVersionUID = 1L;
+ List<String> events;
+ public WaitState(List<String> events) {
+ this.events = events;
+ }
+ public void execute(ActivityExecution execution) {
+ events.add("execute["+execution.getNodeName()+"]");
+ execution.waitForSignal();
+ }
+ public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
+ events.add("signal["+execution.getNodeName()+"]");
+ execution.take(signalName);
+ }
+ }
+
+ public void testChainOfAutomaticActivitiesAndWaitStates() {
+ List<String> recordedEvents = new ArrayList<String>();
+ AutomaticActivity automaticActivity = new AutomaticActivity(recordedEvents);
+ WaitState waitState = new WaitState(recordedEvents);
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("loan")
+ .node("submit loan request").initial().behaviour(automaticActivity)
+ .transition().to("evaluate")
+ .node("evaluate").behaviour(waitState)
+ .transition("approve").to("wire money")
+ .transition("reject").to("end")
+ .node("wire money").behaviour(automaticActivity)
+ .transition().to("archive")
+ .node("archive").behaviour(waitState)
+ .transition().to("end")
+ .node("end").behaviour(waitState)
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ List<String> expectedEvents = new ArrayList<String>();
+
+ expectedEvents.add("execute[submit loan request]");
+ expectedEvents.add("execute[evaluate]");
+
+ assertEquals("evaluate", execution.getNodeName());
+ assertEquals(expectedEvents, recordedEvents);
+
+ execution.signal("approve");
+
+ expectedEvents.add("signal[evaluate]");
+ expectedEvents.add("execute[wire money]");
+ expectedEvents.add("execute[archive]");
+
+ assertEquals("archive", execution.getNodeName());
+ assertEquals(expectedEvents, recordedEvents);
+
+ execution.signal();
+
+ expectedEvents.add("signal[archive]");
+ expectedEvents.add("execute[end]");
+
+ assertEquals("end", execution.getNodeName());
+ assertEquals(expectedEvents, recordedEvents);
+ }
+
+ public void testDelayedBegin() {
+ List<String> recordedEvents = new ArrayList<String>();
+ AutomaticActivity automaticActivity = new AutomaticActivity(recordedEvents);
+ WaitState waitState = new WaitState(recordedEvents);
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("loan")
+ .node("submit loan request").initial().behaviour(automaticActivity)
+ .transition().to("evaluate")
+ .node("evaluate").behaviour(waitState)
+ .transition("approve").to("wire money")
+ .transition("reject").to("end")
+ .node("wire money").behaviour(automaticActivity)
+ .transition().to("archive")
+ .node("archive").behaviour(waitState)
+ .transition().to("end")
+ .node("end").behaviour(waitState)
+ .done();
+
+
+ ClientProcessInstance processInstance = processDefinition.createProcessInstance();
+
+ // here, inbetween create and start 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.start();
+
+ expectedEvents.add("execute[submit loan request]");
+ expectedEvents.add("execute[evaluate]");
+
+ assertEquals("evaluate", processInstance.getNodeName());
+ assertEquals(expectedEvents, recordedEvents);
+ }
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/EventPropagationTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/EventPropagationTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/EventPropagationTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/EventPropagationTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,358 @@
+/*
+ * 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.activities;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.activity.Activity;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.listener.EventListener;
+import org.jbpm.listener.EventListenerExecution;
+import org.jbpm.model.Event;
+import org.jbpm.model.Node;
+import org.jbpm.model.ObservableElement;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Tom Baeyens
+ */
+public class EventPropagationTest extends JbpmTestCase
+{
+
+ public class Recorder implements EventListener {
+ private static final long serialVersionUID = 1L;
+ public List<Object> events = new ArrayList<Object>();
+ public void notify(EventListenerExecution execution) {
+ ObservableElement element = execution.getEventSource();
+ String elementName = element.getName();
+ events.add(execution.getEvent()+" on "+(elementName!=null ? elementName : element));
+ }
+ }
+
+ public static class FireableState 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.fire(signalName, execution.getNode());
+ }
+ }
+
+ public static class AutomaticActivity implements Activity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ }
+ }
+
+ 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){
+ }
+ }
+
+ public void testListenToNodeLeaveOnProcessForProcessNodes(){
+ Recorder recorder = new Recorder();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
+ .event(Event.NODE_END)
+ .listener(recorder)
+ .node("initial").initial().behaviour(new WaitState())
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+ execution.signal();
+
+ assertEquals("event(node-end) on initial", recorder.events.get(0));
+ assertEquals(1, recorder.events.size());
+ }
+
+ public void testListenToNodeEnterOnProcessForProcessNodes(){
+ Recorder recorder = new Recorder();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
+ .event(Event.NODE_BEGIN)
+ .listener(recorder)
+ .node("initial").initial().behaviour(new WaitState())
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+ execution.signal();
+
+ assertEquals("event(node-begin) on end", recorder.events.get(0));
+ assertEquals(1, recorder.events.size());
+ }
+
+ public void testListenToTransitionOnProcessForTransitionBetweenProcessNodes(){
+ Recorder recorder = new Recorder();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
+ .event(Event.TRANSITION_TAKE)
+ .listener(recorder)
+ .node("initial").initial().behaviour(new WaitState())
+ .transition("go").to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+ execution.signal();
+
+ assertEquals("event(transition-take) on go", recorder.events.get(0));
+ assertEquals(1, recorder.events.size());
+ }
+
+ // propagation of process elements in composite nodes ///////////////////////
+
+ public static class Sequence implements ExternalActivity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ List<Node> nodes = execution.getNode().getNodes();
+ if ( (nodes!=null)
+ && (!nodes.isEmpty())
+ ) {
+ execution.execute(nodes.get(0));
+ }
+ }
+ public void signal(ActivityExecution execution, String signal, Map<String, Object> parameters) {
+ Node previous = execution.getPreviousNode();
+ List<Node> nodes = execution.getNode().getNodes();
+ int index = nodes.indexOf(previous);
+ index++;
+ if (index < nodes.size()) {
+ Node next = nodes.get(index);
+ execution.execute(next);
+ }
+ }
+ }
+
+
+ public void testListenToNodeLeaveOnProcessForSequenceChildNodes(){
+ Recorder recorder = new Recorder();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
+ .event(Event.NODE_END)
+ .listener(recorder)
+ .compositeNode("sequence").initial().behaviour(new Sequence())
+ .needsPrevious()
+ .node("one").behaviour(new WaitState())
+ .node("two").behaviour(new WaitState())
+ .node("three").behaviour(new WaitState())
+ .compositeEnd()
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+ assertEquals(0, recorder.events.size());
+ execution.signal();
+ assertEquals("event(node-end) on one", recorder.events.get(0));
+ assertEquals(1, recorder.events.size());
+ execution.signal();
+ assertEquals("event(node-end) on two", recorder.events.get(1));
+ assertEquals(2, recorder.events.size());
+ execution.signal();
+ assertEquals("event(node-end) on three", recorder.events.get(2));
+ assertEquals(3, recorder.events.size());
+ }
+
+ public void testListenToNodeLeaveOnProcessForTransitionBetweenSequenceChildNodes(){
+ Recorder recorder = new Recorder();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
+ .event(Event.NODE_END)
+ .listener(recorder)
+ .compositeNode("sequence").initial().behaviour(new Sequence())
+ .node("one").behaviour(new WaitState())
+ .transition().to("two")
+ .node("two").behaviour(new WaitState())
+ .compositeEnd()
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals(0, recorder.events.size());
+ execution.signal();
+ assertEquals("event(node-end) on one", recorder.events.get(0));
+ assertEquals(1, recorder.events.size());
+ execution.signal();
+ assertEquals("event(node-end) on two", recorder.events.get(1));
+ assertEquals(2, recorder.events.size());
+ }
+
+
+ public void testListenToNodeEnterOnProcessForSequenceChildNodes(){
+ Recorder recorder = new Recorder();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
+ .event(Event.NODE_BEGIN)
+ .listener(recorder)
+ .compositeNode("sequence").initial().behaviour(new Sequence())
+ .needsPrevious()
+ .node("one").behaviour(new WaitState())
+ .node("two").behaviour(new WaitState())
+ .node("three").behaviour(new WaitState())
+ .compositeEnd()
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+ assertEquals("event(node-begin) on one", recorder.events.get(0));
+ assertEquals(1, recorder.events.size());
+ execution.signal();
+ assertEquals("event(node-begin) on two", recorder.events.get(1));
+ assertEquals(2, recorder.events.size());
+ execution.signal();
+ assertEquals("event(node-begin) on three", recorder.events.get(2));
+ assertEquals(3, recorder.events.size());
+ }
+
+ public void testListenToTransitionTakeOnProcessForTransitionBetweenSequenceChildNodes(){
+ Recorder recorder = new Recorder();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
+ .event(Event.TRANSITION_TAKE)
+ .listener(recorder)
+ .compositeNode("sequence").initial().behaviour(new Sequence())
+ .node("one").behaviour(new WaitState())
+ .transition("increment").to("two")
+ .node("two").behaviour(new WaitState())
+ .compositeEnd()
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals(0, recorder.events.size());
+ execution.signal();
+ assertEquals("event(transition-take) on increment", recorder.events.get(0));
+ assertEquals(1, recorder.events.size());
+ }
+
+ public void testDeeplyNestedCustomEvent(){
+ Recorder processRecorder = new Recorder();
+ Recorder outerRecorder = new Recorder();
+ Recorder middelRecorder = new Recorder();
+ Recorder innerRecorder = new Recorder();
+ Recorder nestedStateRecorder = new Recorder();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
+ .event("hello")
+ .listener(processRecorder)
+ .compositeNode("outer").initial().behaviour(new Sequence())
+ .event("hello")
+ .listener(outerRecorder)
+ .compositeNode("middel").behaviour(new Sequence())
+ .event("hello")
+ .listener(middelRecorder)
+ .compositeNode("inner").behaviour(new Sequence())
+ .event("hello")
+ .listener(innerRecorder)
+ .node("nested state").behaviour(new FireableState())
+ .event("hello")
+ .listener(nestedStateRecorder)
+ .compositeEnd()
+ .compositeEnd()
+ .compositeEnd()
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals(0, processRecorder.events.size());
+ execution.signal("hello");
+
+ assertEquals("event(hello) on nested state", processRecorder.events.get(0));
+ assertEquals(1, processRecorder.events.size());
+
+ assertEquals("event(hello) on nested state", outerRecorder.events.get(0));
+ assertEquals(1, outerRecorder.events.size());
+
+ assertEquals("event(hello) on nested state", middelRecorder.events.get(0));
+ assertEquals(1, middelRecorder.events.size());
+
+ assertEquals("event(hello) on nested state", innerRecorder.events.get(0));
+ assertEquals(1, innerRecorder.events.size());
+
+ assertEquals("event(hello) on nested state", nestedStateRecorder.events.get(0));
+ assertEquals(1, nestedStateRecorder.events.size());
+ }
+
+ public void testPropagatedEventsDisabled(){
+ Recorder processRecorder = new Recorder();
+ Recorder outerRecorder = new Recorder();
+ Recorder middleRecorder = new Recorder();
+ Recorder innerRecorder = new Recorder();
+ Recorder nestedStateRecorder = new Recorder();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("propagate")
+ .event("hello")
+ .listener(processRecorder)
+ .compositeNode("outer").initial().behaviour(new Sequence())
+ .event("hello")
+ .listener(outerRecorder)
+ .compositeNode("middle").behaviour(new Sequence())
+ .event("hello")
+ .listener(middleRecorder)
+ .propagationDisabled()
+ .compositeNode("inner").behaviour(new Sequence())
+ .event("hello")
+ .listener(innerRecorder)
+ .node("nested state").behaviour(new FireableState())
+ .event("hello")
+ .listener(nestedStateRecorder)
+ .compositeEnd()
+ .compositeEnd()
+ .compositeEnd()
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ // the middle action should not be executed for an event that was propagated from the nested state
+ execution.signal("hello");
+
+ assertEquals("event(hello) on nested state", processRecorder.events.get(0));
+ assertEquals(1, processRecorder.events.size());
+
+ assertEquals("event(hello) on nested state", outerRecorder.events.get(0));
+ assertEquals(1, outerRecorder.events.size());
+
+ assertEquals(0, middleRecorder.events.size());
+
+ assertEquals("event(hello) on nested state", innerRecorder.events.get(0));
+ assertEquals(1, innerRecorder.events.size());
+
+ assertEquals("event(hello) on nested state", nestedStateRecorder.events.get(0));
+ assertEquals(1, nestedStateRecorder.events.size());
+ }
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/EventTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/EventTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/EventTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/EventTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,266 @@
+/*
+ * 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.activities;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.activity.Activity;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.listener.EventListener;
+import org.jbpm.listener.EventListenerExecution;
+import org.jbpm.model.Event;
+import org.jbpm.model.Node;
+import org.jbpm.model.ObservableElement;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+/** shows how actions are listeners to following processDefinition events:
+ * <ul>
+ * <li>node-leave</li>
+ * <li>transition</li>
+ * <li>node-enter</li>
+ * <li>custom event</li>
+ * </ul>
+ *
+ * @author Tom Baeyens
+ */
+public class EventTest extends JbpmTestCase {
+
+ public static class AutomaticActivity implements Activity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ }
+ }
+
+ 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);
+ }
+ }
+
+
+ // node leave action ////////////////////////////////////////////////////////
+
+ public static class NodeLeaveAction implements EventListener {
+ private static final long serialVersionUID = 1L;
+ public void notify(EventListenerExecution execution) {
+ execution.setVariable("msg", "Kilroy was here");
+
+ assertEquals("initial", execution.getNode().getName());
+ assertEquals("initial", execution.getEventSource().getName());
+ assertEquals("leave node action test", execution.getProcessDefinition().getName());
+ assertEquals("end", execution.getTransition().getDestination().getName());
+ }
+ }
+
+ public void testEventListenerOnNodeEnd() {
+ NodeLeaveAction nodeLeaveAction = new NodeLeaveAction();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("leave node action test")
+ .node("initial").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(nodeLeaveAction)
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("initial", execution.getNode().getName());
+ execution.signal();
+ assertEquals("Kilroy was here", execution.getVariable("msg"));
+ }
+
+ // transition action ////////////////////////////////////////////////////////
+
+ public static class TransitionAction implements EventListener {
+ private static final long serialVersionUID = 1L;
+ public void notify(EventListenerExecution execution) throws Exception {
+ execution.setVariable("msg", "Kilroy was here");
+
+ assertNull(execution.getNode());
+ assertEquals("t", execution.getEventSource().getName());
+ assertEquals("transition action test", execution.getProcessDefinition().getName());
+ assertEquals("end", execution.getTransition().getDestination().getName());
+ }
+ }
+
+ public void testEventListenerOnTransition() {
+ TransitionAction transitionAction = new TransitionAction();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("transition action test")
+ .node("initial").initial().behaviour(new WaitState())
+ .transition("t").to("end")
+ .listener(transitionAction)
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("initial", execution.getNode().getName());
+ execution.signal("t");
+ assertEquals("Kilroy was here", execution.getVariable("msg"));
+ }
+
+ // node enter action ////////////////////////////////////////////////////////
+
+ public static class NodeBeginAction implements EventListener {
+ private static final long serialVersionUID = 1L;
+ public void notify(EventListenerExecution execution) throws Exception {
+ execution.setVariable("msg", "Kilroy was here");
+
+ assertEquals("end", execution.getNode().getName());
+ assertEquals("end", execution.getEventSource().getName());
+ assertEquals("enter node action test", execution.getProcessDefinition().getName());
+ assertEquals("end", execution.getTransition().getDestination().getName());
+ }
+ }
+
+ public void testEventListenerOnNodeBegin() {
+ NodeBeginAction nodeBeginAction = new NodeBeginAction();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("enter node action test")
+ .node("initial").initial().behaviour(new WaitState())
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .event(Event.NODE_BEGIN)
+ .listener(nodeBeginAction)
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("initial", execution.getNode().getName());
+ execution.signal();
+ assertEquals("Kilroy was here", execution.getVariable("msg"));
+ }
+
+ // custom event ////////////////////////////////////////////////////////////
+
+ public static class WaitStateWithCustomEvent implements ExternalActivity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) throws Exception {
+ execution.waitForSignal();
+ }
+ public void signal(ActivityExecution execution, String signal, Map<String, Object> parameters) throws Exception {
+ Node node = execution.getNode();
+ if ( (signal!=null)
+ && (node!=null)
+ && (node.hasEvent(signal))
+ ) {
+ execution.fire(signal, node);
+ execution.waitForSignal();
+ }
+ }
+ }
+
+ public static class CheckRivetsAction implements EventListener {
+ private static final long serialVersionUID = 1L;
+ public void notify(EventListenerExecution execution) throws Exception {
+ execution.setVariable("msg", "Kilroy was here");
+
+ assertEquals("initial", execution.getNode().getName());
+ assertEquals("initial", execution.getEventSource().getName());
+ assertEquals("custom node action test", execution.getProcessDefinition().getName());
+ assertNull(execution.getTransition());
+ }
+ }
+
+ public void testCustomEventInNode() {
+ CheckRivetsAction checkRivetsAction = new CheckRivetsAction();
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("custom node action test")
+ .node("initial").initial().behaviour(new WaitStateWithCustomEvent())
+ .event("end of riveter shift") // http://en.wikipedia.org/wiki/Kilroy_was_here
+ .listener(checkRivetsAction)
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("initial", execution.getNode().getName());
+ assertNull(execution.getVariable("msg"));
+
+ execution.signal("end of riveter shift");
+
+ assertEquals("initial", execution.getNode().getName());
+ assertEquals("Kilroy was here", execution.getVariable("msg"));
+
+ execution.signal();
+
+ assertEquals("end", execution.getNode().getName());
+ }
+
+ public static class EndState implements Activity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) throws Exception {
+ execution.end();
+ }
+ }
+
+ public static class RecordingProcessDefinition extends ProcessDefinitionImpl {
+ private static final long serialVersionUID = 1L;
+ protected ExecutionImpl newProcessInstance() {
+ return new RecordingExecution();
+ }
+ }
+
+ public static class RecordingExecution extends ExecutionImpl {
+ private static final long serialVersionUID = 1L;
+ List<String> events = new ArrayList<String>();
+ public void fire(String eventName, ObservableElement eventSource) {
+ events.add(eventName+" on "+eventSource);
+ }
+ }
+
+ public void testBasicEventSequence() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build("basic", new RecordingProcessDefinition())
+ .node("initial").initial().behaviour(new AutomaticActivity())
+ .transition().to("end")
+ .node("end").behaviour(new EndState())
+ .done();
+
+ RecordingExecution execution = (RecordingExecution) processDefinition.startProcessInstance();
+
+ int index = 0;
+ assertEquals("process-begin on processDefinition(basic)", execution.events.get(index));
+ index++;
+ assertEquals("node-end on node(initial)", execution.events.get(index));
+ index++;
+ assertEquals("transition-take on (initial)-->(end)", execution.events.get(index));
+ index++;
+ assertEquals("node-begin on node(end)", execution.events.get(index));
+ index++;
+ assertEquals("process-end on processDefinition(basic)", execution.events.get(index));
+ }
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ExceptionHandlerTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExceptionHandlerTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ExceptionHandlerTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ExceptionHandlerTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,325 @@
+/*
+ * 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.activities;
+
+import java.util.Map;
+
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.listener.EventListener;
+import org.jbpm.listener.EventListenerExecution;
+import org.jbpm.model.Event;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Tom Baeyens
+ */
+public class ExceptionHandlerTest extends JbpmTestCase
+{
+
+ 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){
+ }
+ }
+
+ public static class Catcher implements EventListener {
+ private static final long serialVersionUID = 1L;
+ int timesInvoked = 0;
+ public void notify(EventListenerExecution execution) {
+ timesInvoked++;
+ }
+ }
+
+ public static class Batter implements EventListener {
+ private static final long serialVersionUID = 1L;
+ public void notify(EventListenerExecution execution) {
+ throw new RuntimeException("catch me");
+ }
+ }
+
+ public void testExceptionHandlerOnProcessDefinition() {
+ Catcher catcher = new Catcher();
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .exceptionHandler(RuntimeException.class)
+ .listener(catcher)
+ .exceptionHandlerEnd()
+ .node("initial").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(new Batter())
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("initial", execution.getNode().getName());
+ assertEquals(0, catcher.timesInvoked);
+ execution.signal();
+ assertEquals(1, catcher.timesInvoked);
+ assertEquals("end", execution.getNode().getName());
+ }
+
+ public void testExceptionHandlerOnEvent() {
+ Catcher catcher = new Catcher();
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("initial").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .exceptionHandler(RuntimeException.class)
+ .listener(catcher)
+ .exceptionHandlerEnd()
+ .listener(new Batter())
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("initial", execution.getNode().getName());
+ assertEquals(0, catcher.timesInvoked);
+ execution.signal();
+ assertEquals(1, catcher.timesInvoked);
+ assertEquals("end", execution.getNode().getName());
+ }
+
+ public void testExceptionHandlerOnAction() {
+ Catcher catcher = new Catcher();
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("initial").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(new Batter())
+ .exceptionHandler(RuntimeException.class)
+ .listener(catcher)
+ .exceptionHandlerEnd()
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("initial", execution.getNode().getName());
+ assertEquals(0, catcher.timesInvoked);
+ execution.signal();
+ assertEquals(1, catcher.timesInvoked);
+ assertEquals("end", execution.getNode().getName());
+ }
+
+ public void testExceptionHandlerOnOtherNode() {
+ Catcher catcher = new Catcher();
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("initial").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(new Batter())
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .exceptionHandler(RuntimeException.class)
+ .listener(catcher)
+ .exceptionHandlerEnd()
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("initial", execution.getNode().getName());
+ assertEquals(0, catcher.timesInvoked);
+ try {
+ execution.signal();
+ fail("expected exception");
+ } catch (RuntimeException e) {
+ // OK
+ }
+ }
+
+ public void testExceptionHandlerOnOtherEvent() {
+ Catcher catcher = new Catcher();
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("initial").initial().behaviour(new WaitState())
+ .event("other")
+ .exceptionHandler(RuntimeException.class)
+ .listener(catcher)
+ .exceptionHandlerEnd()
+ .event(Event.NODE_END)
+ .listener(new Batter())
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("initial", execution.getNode().getName());
+ try {
+ execution.signal();
+ fail("expected exception");
+ } catch (RuntimeException e) {
+ // OK
+ }
+ }
+
+ public static class BehavedAction implements EventListener {
+ private static final long serialVersionUID = 1L;
+ public void notify(EventListenerExecution execution) {
+ // behaving. not throwing any exception
+ }
+ }
+
+ public void testExceptionHandlerOnOtherAction() {
+ Catcher catcher = new Catcher();
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("initial").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(new BehavedAction())
+ .exceptionHandler(RuntimeException.class)
+ .listener(catcher)
+ .exceptionHandlerEnd()
+ .listener(new Batter())
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("initial", execution.getNode().getName());
+ try {
+ execution.signal();
+ fail("expected exception");
+ } catch (RuntimeException e) {
+ // OK
+ }
+ }
+
+ public void testUnmatchedExceptionHandlerOnAction() {
+ Catcher catcher = new Catcher();
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("initial").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(new Batter())
+ .exceptionHandler(NullPointerException.class)
+ .listener(catcher)
+ .exceptionHandlerEnd()
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("initial", execution.getNode().getName());
+ try {
+ execution.signal();
+ fail("expected exception");
+ } catch (RuntimeException e) {
+ // OK
+ }
+ }
+
+ public static class RethrowingCatcher implements EventListener {
+ private static final long serialVersionUID = 1L;
+ public void notify(EventListenerExecution execution) {
+ // this exception handler will itself throw an exception
+ throw new RuntimeException("greetz from the retrhowing catcher");
+ }
+ }
+
+
+ public void testRethrowingExceptionHandler() {
+ RethrowingCatcher rethrowingCatcher = new RethrowingCatcher();
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("initial").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(new Batter())
+ .exceptionHandler(RuntimeException.class)
+ .listener(rethrowingCatcher)
+ .exceptionHandlerEnd()
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ try {
+ execution.signal();
+ fail("expected exception");
+ } catch (RuntimeException e) {
+ assertTextPresent("greetz from the retrhowing catcher", e.getMessage());
+ }
+ }
+
+ public void testRethrowingExceptionHandlerCaughtByTheOuterExceptionHandler() {
+
+ // just like in java, when an exception handler rethrows, the search
+ // for a matching exception handler will continue in the outer scope
+ // (=the surrounding process element)
+
+ RethrowingCatcher rethrowingCatcher = new RethrowingCatcher();
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("initial").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .exceptionHandler(RuntimeException.class)
+ .listener(new Catcher())
+ .exceptionHandlerEnd()
+ .listener(new Batter())
+ .exceptionHandler(RuntimeException.class)
+ .listener(rethrowingCatcher)
+ .exceptionHandlerEnd()
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("initial", execution.getNode().getName());
+ execution.signal();
+ }
+
+ public void testRethrowingExceptionHandlerIgnoredByTheSubsequentExceptionHandlerInTheSameScope() {
+
+ // just like in java, subsequent exception handlers will be skipped when the
+ // an exception handler rethrows
+
+ RethrowingCatcher rethrowingCatcher = new RethrowingCatcher();
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("initial").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(new Batter())
+ .exceptionHandler(RuntimeException.class)
+ .listener(rethrowingCatcher)
+ .exceptionHandlerEnd()
+ .exceptionHandler(RuntimeException.class)
+ .listener(new Catcher())
+ .exceptionHandlerEnd()
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+ try {
+ execution.signal();
+ fail("expected exception");
+ } catch (RuntimeException e) {
+ assertTextPresent("greetz from the retrhowing catcher", e.getMessage());
+ }
+ }
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ExecutionStateTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExecutionStateTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ExecutionStateTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ExecutionStateTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,197 @@
+/*
+ * 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.activities;
+
+import java.util.Map;
+
+import org.jbpm.Execution;
+import org.jbpm.JbpmException;
+import org.jbpm.activity.Activity;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.client.ClientProcessInstance;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+/** shows the basics of the state property on the execution.
+ *
+ * The state is automatically managed by the execution.
+ * An execution can only receive external triggers in case it is in
+ * the active state.
+ *
+ * Nested executions can occur in case of scoped executions
+ * and in case of concurrent executions. In both cases, only
+ * leave executions in the execution hierarchy are active.
+ *
+ * Executions are either locked or active. So in any state which
+ * is not active, the execution is locked and cannot accept external
+ * signals. Executions can be ended in 3 ways:
+ *
+ * 1) with execution.end() : then the state will be set to 'ended'
+ * 2) with execution.cancel() : then the state will be set to 'cancelled'
+ * 3) with execution.end(String) : then the state will be set to the
+ * given state string. An exception will be raised if the given
+ * state maches any of the known states.
+ *
+ * @author Tom Baeyens
+ */
+public class ExecutionStateTest extends JbpmTestCase {
+
+ public static class AutomaticActivity implements Activity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ assertEquals(Execution.STATE_ACTIVE, execution.getState());
+ }
+ }
+
+ public static class WaitState implements ExternalActivity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ assertEquals(Execution.STATE_ACTIVE, execution.getState());
+ execution.waitForSignal();
+ }
+ public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) {
+ assertEquals(Execution.STATE_ACTIVE, execution.getState());
+ execution.take(signalName);
+ }
+ }
+
+ public void testBasicState() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new AutomaticActivity())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .transition().to("c")
+ .node("c").behaviour(new AutomaticActivity())
+ .done();
+
+ ClientProcessInstance processInstance = processDefinition.createProcessInstance();
+
+ assertEquals(Execution.STATE_CREATED, processInstance.getState());
+
+ processInstance.start();
+
+ assertEquals(Execution.STATE_ACTIVE, processInstance.getState());
+
+ processInstance.signal();
+
+ assertEquals(Execution.STATE_ENDED, processInstance.getState());
+ }
+
+ public void testSignalOnInactiveExecution() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new AutomaticActivity())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .scope()
+ .transition().to("c")
+ .node("c").behaviour(new AutomaticActivity())
+ .done();
+
+ ClientProcessInstance processInstance = processDefinition.createProcessInstance();
+ processInstance.start();
+
+ assertEquals(Execution.STATE_INACTIVE, processInstance.getState());
+
+ try {
+ processInstance.signal();
+ fail("expected exception");
+ } catch (JbpmException e) {
+ // OK
+ assertTextPresent("process-instance is not active: inactive", e.getMessage());
+ }
+ }
+
+ public void testCustomEndState() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new AutomaticActivity())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .transition().to("c")
+ .node("c").behaviour(new AutomaticActivity())
+ .done();
+
+ ClientProcessInstance processInstance = processDefinition.createProcessInstance();
+ processInstance.start();
+ processInstance.end("error");
+
+ assertEquals("error", processInstance.getState());
+
+ try {
+ processInstance.signal();
+ fail("expected exception");
+ } catch (JbpmException e) {
+ // OK
+ assertTextPresent("process-instance is not active: error", e.getMessage());
+ }
+ }
+
+ public void testInvalidCustomStates() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new AutomaticActivity())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .transition().to("c")
+ .node("c").behaviour(new AutomaticActivity())
+ .done();
+
+ ClientProcessInstance processInstance = processDefinition.createProcessInstance();
+ processInstance.start();
+
+ try {
+ processInstance.end("active");
+ fail("expected exception");
+ } catch (JbpmException e) {
+ // OK
+ assertTextPresent("invalid end state: active", e.getMessage());
+ }
+ try {
+ processInstance.end("suspended");
+ fail("expected exception");
+ } catch (JbpmException e) {
+ // OK
+ assertTextPresent("invalid end state: suspended", e.getMessage());
+ }
+ try {
+ processInstance.end("created");
+ fail("expected exception");
+ } catch (JbpmException e) {
+ // OK
+ assertTextPresent("invalid end state: created", e.getMessage());
+ }
+ try {
+ processInstance.end("async");
+ fail("expected exception");
+ } catch (JbpmException e) {
+ // OK
+ assertTextPresent("invalid end state: async", e.getMessage());
+ }
+ try {
+ processInstance.end("inactive");
+ fail("expected exception");
+ } catch (JbpmException e) {
+ // OK
+ assertTextPresent("invalid end state: inactive", e.getMessage());
+ }
+ }
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ExternalDecisionTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ExternalDecisionTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ExternalDecisionTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ExternalDecisionTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,98 @@
+/*
+ * 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.activities;
+
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.pvm.model.ProcessFactory;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ExternalDecisionTest extends TestCase {
+
+ public static class ExternalDecision implements ExternalActivity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) throws Exception {
+ execution.waitForSignal();
+ }
+ public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
+ execution.take(signalName);
+ }
+ }
+
+ 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()
+ .node("creditRate?").initial().behaviour(new ExternalDecision())
+ .transition("good").to("priority delivery")
+ .transition("average").to("bulk delivery")
+ .transition("bad").to("payment upfront")
+ .node("priority delivery").behaviour(new WaitState())
+ .node("bulk delivery").behaviour(new WaitState())
+ .node("payment upfront").behaviour(new WaitState())
+ .done();
+ }
+
+ public void testGoodRating() {
+ ClientProcessDefinition processDefinition = createCreditProcess();
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ execution.signal("good");
+
+ assertEquals("priority delivery", execution.getNode().getName());
+ }
+
+ public void testAverageRating() {
+ ClientProcessDefinition processDefinition = createCreditProcess();
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ execution.signal("average");
+
+ assertEquals("bulk delivery", execution.getNode().getName());
+ }
+
+ public void testBadRating() {
+ ClientProcessDefinition processDefinition = createCreditProcess();
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ execution.signal("bad");
+
+ assertEquals("payment upfront", execution.getNode().getName());
+ }
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/FunctionalActivityTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/FunctionalActivityTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/FunctionalActivityTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/FunctionalActivityTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,157 @@
+/*
+ * 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.activities;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.activity.Activity;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.client.ClientProcessInstance;
+import org.jbpm.listener.EventListener;
+import org.jbpm.listener.EventListenerExecution;
+import org.jbpm.model.Node;
+import org.jbpm.model.OpenExecution;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+
+/** shows how functional nodes (nodes that have a specific function
+ * not related to control flow) can be implemented.
+ *
+ * Examples of functional nodes could be sending an email, doing a
+ * SQL update on a database, generating a file and so on.
+ *
+ * Functional nodes can be used as node behaviour in a transition based
+ * process, event listener and as node behaviour in nested node
+ * execution.
+ *
+ * @author Tom Baeyens
+ */
+public class FunctionalActivityTest extends JbpmTestCase {
+
+ public static class FunctionalActivity implements Activity, EventListener {
+ private static final long serialVersionUID = 1L;
+ List<String> events;
+ public FunctionalActivity(List<String> events) {
+ this.events = events;
+ }
+ public void execute(ActivityExecution execution) {
+ perform(execution);
+ }
+ public void notify(EventListenerExecution execution) {
+ perform(execution);
+ }
+ void perform(OpenExecution execution) {
+ events.add("performed automatic activity");
+ }
+ }
+
+ public void testFunctionalActivityAsNodeBehaviourWithTransitions() {
+ List<String> recordedEvents = new ArrayList<String>();
+ FunctionalActivity functionalActivity = new FunctionalActivity(recordedEvents);
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(functionalActivity)
+ .transition().to("b")
+ .node("b").behaviour(functionalActivity)
+ .transition().to("c")
+ .node("c").behaviour(functionalActivity)
+ .done();
+
+ ClientProcessInstance processInstance = processDefinition.createProcessInstance();
+
+ List<String> expectedEvents = new ArrayList<String>();
+
+ assertEquals("a", processInstance.getNodeName());
+ assertFalse(processInstance.isEnded());
+ assertEquals(expectedEvents, recordedEvents);
+
+ processInstance.start();
+
+ expectedEvents.add("performed automatic activity");
+ expectedEvents.add("performed automatic activity");
+ expectedEvents.add("performed automatic activity");
+
+ assertEquals(expectedEvents, recordedEvents);
+ }
+
+
+ public static class AutomaticActivity implements Activity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ }
+ }
+
+ public void testFunctionalActivityAsEventListener() {
+ List<String> recordedEvents = new ArrayList<String>();
+ FunctionalActivity functionalActivity = new FunctionalActivity(recordedEvents);
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new AutomaticActivity())
+ .transition().to("b")
+ .listener(functionalActivity)
+ .node("b").behaviour(new AutomaticActivity())
+ .done();
+
+ ClientProcessInstance processInstance = processDefinition.createProcessInstance();
+ processInstance.start();
+
+ List<String> expectedEvents = new ArrayList<String>();
+ expectedEvents.add("performed automatic activity");
+
+ assertEquals(expectedEvents, recordedEvents);
+ }
+
+ public static class Composite implements ExternalActivity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ Node nestedNode = execution.getNode().getNodes().get(0);
+ execution.execute(nestedNode);
+ }
+ public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) {
+ }
+ }
+
+ public void testFunctionalActivityAsNestedNode() {
+ List<String> recordedEvents = new ArrayList<String>();
+ FunctionalActivity functionalActivity = new FunctionalActivity(recordedEvents);
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .compositeNode("a").initial().behaviour(new Composite())
+ .node().behaviour(functionalActivity)
+ .compositeEnd()
+ .done();
+
+ ClientProcessInstance processInstance = processDefinition.createProcessInstance();
+ processInstance.start();
+
+ List<String> expectedEvents = new ArrayList<String>();
+ expectedEvents.add("performed automatic activity");
+
+ assertEquals(expectedEvents, recordedEvents);
+ }
+
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/LoopingTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/LoopingTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/LoopingTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/LoopingTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,104 @@
+package org.jbpm.test.activities;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.activity.Activity;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+public class LoopingTest extends JbpmTestCase {
+
+ public static class For implements ExternalActivity {
+ private static final long serialVersionUID = 1L;
+
+ int startIndex = 0;
+ int loops;
+ int increment = 1;
+ String indexKey = "index";
+
+ public For(int loops) {
+ this.loops = loops;
+ }
+
+ public void execute(ActivityExecution execution) throws Exception {
+ Integer index = (Integer) execution.getVariable(indexKey);
+
+ if (index==null) {
+ execution.setVariable(indexKey, startIndex);
+ execution.take("loop");
+
+ } else {
+ index++;
+ if (index<(startIndex+loops)){
+ execution.setVariable(indexKey, index);
+ execution.take("loop");
+
+ } else {
+ execution.removeVariable(indexKey);
+ execution.take("done");
+ }
+ }
+ }
+ public void signal(ActivityExecution execution, String signal, Map<String, Object> parameters) throws Exception {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setStartIndex(int startIndex) {
+ this.startIndex = startIndex;
+ }
+ public void setLoops(int loops) {
+ this.loops = loops;
+ }
+ public void setIncrement(int increment) {
+ this.increment = increment;
+ }
+ public void setIndexVariable(String indexVariable) {
+ this.indexKey = indexVariable;
+ }
+ }
+
+ static List<Object> recordedIndexes = new ArrayList<Object>();
+
+ public static class Recorder implements Activity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) throws Exception {
+ recordedIndexes.add(execution.getVariable("index"));
+ }
+ }
+
+ 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){
+ }
+ }
+
+ public void testWhile() {
+ int loops = 20;
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("for").initial().behaviour(new For(loops))
+ .transition("loop").to("recorder")
+ .transition("done").to("end")
+ .node("recorder").behaviour(new Recorder())
+ .transition().to("for")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ List<Object> expectedIndexes = new ArrayList<Object>();
+ for (int i=0; i<loops; i++) expectedIndexes.add(i);
+
+ assertEquals(expectedIndexes, recordedIndexes);
+ assertEquals("end", execution.getNode().getName());
+ }
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ScopeStateTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeStateTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ScopeStateTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ScopeStateTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,85 @@
+/*
+ * 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.activities;
+
+import java.util.Map;
+
+import org.jbpm.Execution;
+import org.jbpm.activity.Activity;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.client.ClientProcessInstance;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Tom Baeyens
+ */
+public class ScopeStateTest extends JbpmTestCase
+{
+
+ public static class AutomaticActivity implements Activity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ assertEquals(Execution.STATE_ACTIVE, execution.getState());
+ }
+ }
+
+ public static class WaitState implements ExternalActivity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ assertEquals(Execution.STATE_ACTIVE, execution.getState());
+ execution.waitForSignal();
+ }
+ public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
+ assertEquals(Execution.STATE_ACTIVE, execution.getState());
+ execution.take(signalName);
+ }
+ }
+
+ public void testInactivationWhenCreatingNestedExecution() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new AutomaticActivity())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .scope()
+ .transition().to("c")
+ .node("c").behaviour(new WaitState())
+ .done();
+
+ ClientProcessInstance processInstance = processDefinition.createProcessInstance();
+
+ assertEquals(Execution.STATE_CREATED, processInstance.getState());
+
+ processInstance.start();
+ Execution scopeExecution = processInstance.getExecutions().iterator().next();
+
+ assertEquals(Execution.STATE_INACTIVE, processInstance.getState());
+ assertEquals(Execution.STATE_ACTIVE, scopeExecution.getState());
+
+ processInstance.signal(scopeExecution);
+
+ assertEquals(Execution.STATE_ENDED, scopeExecution.getState());
+ assertEquals(Execution.STATE_ACTIVE, processInstance.getState());
+ }
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ScopeVariableDeclarationTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeVariableDeclarationTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ScopeVariableDeclarationTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ScopeVariableDeclarationTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,222 @@
+/*
+ * 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.activities;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.model.Node;
+import org.jbpm.model.OpenExecution;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ScopeVariableDeclarationTest extends JbpmTestCase {
+
+ 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 class Composite implements ExternalActivity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ Node child = execution.getNode().getNodes().get(0);
+ execution.execute(child);
+ }
+ public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) {
+ }
+ }
+
+ public void testProcessInstanceVariableDeclaration() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .variable("flight")
+ .node("a").initial().behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ assertTrue(processInstance.hasVariable("flight"));
+ assertNull(processInstance.getVariable("flight"));
+ }
+
+ public void testProcessInstanceVariableDeclarationWithInitialValue() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .variable("flight", "B52")
+ .node("a").initial().behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ assertTrue(processInstance.hasVariable("flight"));
+ assertEquals("B52", processInstance.getVariable("flight"));
+ }
+
+ public void testNestedScopeDeclarations() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .variable("flight", "B52")
+ .compositeNode("outer").behaviour(new Composite())
+ .variable("duration", "22 minutes")
+ .compositeNode("middle").behaviour(new Composite())
+ .variable("altitude", "31000 ft")
+ .compositeNode("inner").behaviour(new Composite())
+ .variable("passengers", "52")
+ .compositeNode("start").initial().behaviour(new WaitState())
+ .variable("fuel", "kerosine")
+ .compositeEnd()
+ .compositeEnd()
+ .compositeEnd()
+ .compositeEnd()
+ .done();
+
+ Map<String, Object> expectedVariables = new HashMap<String, Object>();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ expectedVariables.put("flight", "B52");
+ assertEquals(expectedVariables, processInstance.getVariables());
+
+ OpenExecution outerExecution = processInstance.getExecution("outer");
+ expectedVariables.put("duration", "22 minutes");
+ assertEquals(expectedVariables, outerExecution.getVariables());
+
+ OpenExecution middleExecution = outerExecution.getExecution("middle");
+ expectedVariables.put("altitude", "31000 ft");
+ assertEquals(expectedVariables, middleExecution.getVariables());
+
+ OpenExecution innerExecution = middleExecution.getExecution("inner");
+ expectedVariables.put("passengers", "52");
+ assertEquals(expectedVariables, innerExecution.getVariables());
+
+ OpenExecution startExecution = innerExecution.getExecution("start");
+ expectedVariables.put("fuel", "kerosine");
+ assertEquals(expectedVariables, startExecution.getVariables());
+ }
+
+ public void testHiddenVariable() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .variable("flight", "B52")
+ .compositeNode("c").behaviour(new Composite())
+ .variable("flight", "U2")
+ .node("i").initial().behaviour(new WaitState())
+ .variable("flight", "C130")
+ .compositeEnd()
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+ OpenExecution executionC = processInstance.getExecution("c");
+ OpenExecution executionI = executionC.getExecution("i");
+
+ assertEquals("B52", processInstance.getVariable("flight"));
+ assertEquals("U2", executionC.getVariable("flight"));
+ assertEquals("C130", executionI.getVariable("flight"));
+ }
+
+ public void testAutomaticScopeManagement() {
+ /*
+ process
+ ${flight} = 'B52'
+ +--------------------------------------------------------------------+
+ | outer |
+ | ${duration} = '22 minutes' |
+ | +-------------------------------+ |
+ | | left-middle | |
+ | | ${altitude} = '31000 ft' | |
+ | | +---------------------------+ | +----------------------------+ |
+ | | | left-inner | | | right-middle | |
+ | | | ${passengers} | | | ${customer} = 'coca cola' | |
+ | | | +-----------------------+ | | | +--------------------+ | |
+ | | | | left-start | -------> | right-inner | | |
+ | | | | ${fuel} = 'kerosine' | | | | | ${date} = 'today' | | |
+ | | | +-----------------------+ | | | +--------------------+ | |
+ | | +---------------------------+ | +----------------------------+ |
+ +--------------------------------------------------------------------+
+ */
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .variable("flight", "B52")
+ .compositeNode("outer").behaviour(new Composite())
+ .variable("duration", "22 minutes")
+ .compositeNode("left-middle").behaviour(new Composite())
+ .variable("altitude", "31000 ft")
+ .compositeNode("left-inner").behaviour(new Composite())
+ .variable("passengers", "52")
+ .compositeNode("left-start").initial().behaviour(new WaitState())
+ .variable("fuel", "kerosine")
+ .transition().to("right-inner")
+ .compositeEnd()
+ .compositeEnd()
+ .compositeEnd()
+ .compositeNode("right-middle").behaviour(new Composite())
+ .variable("customer", "coca-cola")
+ .compositeNode("right-inner").behaviour(new WaitState())
+ .variable("date", "today")
+ .compositeEnd()
+ .compositeEnd()
+ .compositeEnd()
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+ OpenExecution outerExecution = processInstance.getExecution("outer");
+ OpenExecution leftMiddleExecution = outerExecution.getExecution("left-middle");
+ OpenExecution leftInnerExecution = leftMiddleExecution.getExecution("left-inner");
+ OpenExecution leftStartExecution = leftInnerExecution.getExecution("left-start");
+
+ Map<String, Object> expectedVariables = new HashMap<String, Object>();
+ expectedVariables.put("flight", "B52");
+ expectedVariables.put("duration", "22 minutes");
+ expectedVariables.put("altitude", "31000 ft");
+ expectedVariables.put("passengers", "52");
+ expectedVariables.put("fuel", "kerosine");
+ assertEquals(expectedVariables, leftStartExecution.getVariables());
+
+ processInstance.signal(leftStartExecution);
+
+ OpenExecution rightMiddleExecution = outerExecution.getExecution("right-middle");
+ OpenExecution rightInnerExecution = rightMiddleExecution.getExecution("right-inner");
+
+ expectedVariables = new HashMap<String, Object>();
+ expectedVariables.put("flight", "B52");
+ expectedVariables.put("duration", "22 minutes");
+
+ assertEquals(expectedVariables, outerExecution.getVariables());
+
+ expectedVariables.put("customer", "coca-cola");
+ assertEquals(expectedVariables, rightMiddleExecution.getVariables());
+
+ expectedVariables.put("date", "today");
+ assertEquals(expectedVariables, rightInnerExecution.getVariables());
+ }
+
+
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ScopeVariableTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/ScopeVariableTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ScopeVariableTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/ScopeVariableTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,187 @@
+/*
+ * 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.activities;
+
+import java.util.Map;
+
+import org.jbpm.JbpmException;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.model.OpenExecution;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ *
+ * +---+ +--------+ +---+
+ * | a | | b | | c |
+ * | | --> | | --> | |
+ * | | | SCOPE! | | |
+ * +---+ +--------+ +---+
+ *
+ * @author Tom Baeyens
+ */
+public class ScopeVariableTest extends JbpmTestCase
+{
+
+ 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 void testOuterscopeLookup() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .scope() // !!!!
+ .transition().to("c")
+ .node("c").behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+ processInstance.setVariable("destination", "anywhere");
+
+ processInstance.signal();
+
+ OpenExecution bScope = processInstance.getExecution("b");
+
+ // check if the global vars are still visible within the scope for b.
+ assertEquals("anywhere", bScope.getVariable("destination"));
+
+ bScope.createVariable("temp", "23C");
+ assertEquals("23C", bScope.getVariable("temp"));
+ assertNull(processInstance.getVariable("temp"));
+ }
+
+ public void testLocalVariableLookup() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .scope() // !!!!
+ .transition().to("c")
+ .node("c").behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ processInstance.signal();
+ OpenExecution bScope = processInstance.getExecution("b");
+
+ bScope.createVariable("temp", "23C");
+
+ assertEquals("23C", bScope.getVariable("temp"));
+ assertNull(processInstance.getVariable("temp"));
+
+ processInstance.signal(bScope);
+
+ assertTrue(bScope.isEnded());
+ assertNull(processInstance.getVariable("temp"));
+ }
+
+ public void testLocalVariableUpdate() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .scope() // !!!!
+ .transition().to("c")
+ .node("c").behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ processInstance.signal();
+ OpenExecution bScope = processInstance.getExecution("b");
+
+ bScope.createVariable("temp", "23C");
+ bScope.setVariable("temp", "28C");
+
+ assertEquals("28C", bScope.getVariable("temp"));
+
+ processInstance.signal(bScope);
+
+ assertTrue(bScope.isEnded());
+ assertNull(processInstance.getVariable("temp"));
+ }
+
+ public void testDefaultCreationOnGlobalScope() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .scope() // !!!!
+ .transition().to("c")
+ .node("c").behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ processInstance.signal();
+ OpenExecution bScope = processInstance.getExecution("b");
+
+ bScope.setVariable("temp", "28C");
+ assertEquals("28C", bScope.getVariable("temp"));
+
+ processInstance.signal(bScope);
+
+ assertTrue(bScope.isEnded());
+ assertEquals("28C", processInstance.getVariable("temp"));
+ }
+
+ public void testVariableUpdatesOnEndedScope() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .transition().to("b")
+ .node("b").behaviour(new WaitState())
+ .scope() // !!!!
+ .transition().to("c")
+ .node("c").behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ processInstance.signal();
+ OpenExecution bScope = processInstance.getExecution("b");
+
+ bScope.createVariable("temp", "28C");
+
+ processInstance.signal(bScope);
+
+ try {
+ bScope.setVariable("temp", "21C");
+ fail("expected exception");
+ } catch (JbpmException e) {
+ // OK
+ assertTextPresent("can't update variable 'temp' on execution[b]", e.getMessage());
+ }
+ }
+
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/SubProcessTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/SubProcessTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/SubProcessTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/SubProcessTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,108 @@
+/*
+ * 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.activities;
+
+import java.util.Map;
+
+import org.jbpm.activity.Activity;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Tom Baeyens
+ */
+public class SubProcessTest extends JbpmTestCase
+{
+
+ public static class SubProcess implements ExternalActivity {
+ private static final long serialVersionUID = 1L;
+ ClientProcessDefinition subProcess;
+ public SubProcess(ClientProcessDefinition subProcess) {
+ this.subProcess = subProcess;
+ }
+ public void execute(ActivityExecution execution) throws Exception {
+ ClientExecution subProcessInstance = execution.beginSubProcessInstance(subProcess);
+ if (!subProcessInstance.isEnded()) {
+ execution.waitForSignal();
+ }
+ }
+ public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) throws Exception {
+ }
+ }
+
+ public static class AutomaticActivity implements Activity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ }
+ }
+
+ 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){
+ }
+ }
+
+ public static class EndState implements Activity {
+ public void execute(ActivityExecution execution) throws Exception {
+ execution.end();
+ }
+ }
+
+ public void testSubProcess() {
+ ClientProcessDefinition subProcess = ProcessFactory.build("sub")
+ .node("sub1").initial().behaviour(new AutomaticActivity())
+ .transition().to("sub2")
+ .node("sub2").behaviour(new WaitState())
+ .transition().to("sub3")
+ .node("sub3").behaviour(new EndState())
+ .done();
+
+ ClientProcessDefinition superProcess = ProcessFactory.build("super")
+ .node("super1").initial().behaviour(new AutomaticActivity())
+ .transition().to("super2")
+ .node("super2").behaviour(new SubProcess(subProcess))
+ .transition().to("super3")
+ .node("super3").behaviour(new WaitState())
+ .done();
+
+ ClientExecution superProcesInstance = superProcess.startProcessInstance();
+ assertEquals("super2", superProcesInstance.getNode().getName());
+
+ ClientExecution subProcessInstance = (ClientExecution) superProcesInstance.getSubProcessInstance();
+ assertNotNull(subProcessInstance);
+ assertEquals("sub2", subProcessInstance.getNode().getName());
+
+ subProcessInstance.signal();
+
+ assertEquals("sub3", subProcessInstance.getNode().getName());
+ assertTrue(subProcessInstance.isEnded());
+
+ assertEquals("super3", superProcesInstance.getNode().getName());
+ }
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/TransitionAsWaitStateTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionAsWaitStateTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/TransitionAsWaitStateTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/TransitionAsWaitStateTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -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.test.activities;
+
+import java.util.Map;
+
+import org.jbpm.activity.Activity;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.model.Condition;
+import org.jbpm.model.OpenExecution;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+/** this test shows how to implement a transition that behaves as a
+ * wait state.
+ *
+ * @author Tom Baeyens
+ */
+public class TransitionAsWaitStateTest extends JbpmTestCase
+{
+
+ public static class AlwaysTrue implements Condition {
+ private static final long serialVersionUID = 1L;
+ public boolean evaluate(OpenExecution execution) {
+ return true;
+ }
+ };
+
+ public static class AutomaticActivity implements Activity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ }
+ }
+
+ 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){
+ }
+ }
+
+ public void testSmallAmount() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("make loss").initial().behaviour(new AutomaticActivity())
+ .transition("use jbpm").to("make profit")
+ .waitCondition(new AlwaysTrue())
+ .node("make profit").behaviour(new WaitState())
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertNull(execution.getNode());
+
+ execution.signal();
+
+ assertEquals("make profit", execution.getNode().getName());
+ }
+
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/TransitionBasedConcurrencyTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionBasedConcurrencyTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/TransitionBasedConcurrencyTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/TransitionBasedConcurrencyTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,177 @@
+package org.jbpm.test.activities;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.Execution;
+import org.jbpm.activity.Activity;
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.model.Node;
+import org.jbpm.model.OpenExecution;
+import org.jbpm.model.Transition;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * concurrent execution where synchronization is done by checking if the
+ * number of expected child executions arrived at the join.
+ *
+ * @author Tom Baeyens
+ */
+public class TransitionBasedConcurrencyTest extends JbpmTestCase {
+
+ public static class Fork implements Activity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ OpenExecution processInstance = execution.getProcessInstance();
+
+ Node node = execution.getNode();
+ List<Transition> outgoingTransitions = node.getOutgoingTransitions();
+
+ // for each outgoing transition
+ for (Transition outgoingTransition: outgoingTransitions) {
+ // launch a concurrent path of execution
+ String childExecutionName = outgoingTransition.getName();
+ // creating the execution will cause the execution to become inactive
+ Execution childExecution = execution.createExecution(childExecutionName, processInstance);
+ execution.take(outgoingTransition, childExecution);
+ }
+
+ // if this was the first fork
+ if (execution.isProcessInstance()) {
+ execution.setNode(null);
+ }
+ }
+ }
+
+ public static class Join implements Activity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) throws Exception {
+ // end the child execution execution
+ // this will also remove the execution from it's parent
+ execution.setState(Execution.STATE_INACTIVE);
+ execution.waitForSignal();
+
+ Node join = execution.getNode();
+ List<OpenExecution> joinedExecutions = findJoinedExecutions(execution, join);
+
+ if (isComplete(joinedExecutions, join)) {
+ endJoinedExecutions(joinedExecutions, execution);
+
+ OpenExecution processInstance = execution.getProcessInstance();
+
+ Execution outgoingExecution = null;
+ if ( processInstance.getExecutions()==null
+ || processInstance.getExecutions().isEmpty()
+ ) {
+ outgoingExecution = processInstance;
+ } else {
+ outgoingExecution = execution.createExecution(processInstance);
+ }
+
+ execution.setNode(join, outgoingExecution);
+ Transition transition = join.getDefaultTransition();
+ execution.take(transition, outgoingExecution);
+ }
+ }
+
+ List<OpenExecution> findJoinedExecutions(OpenExecution execution, Node join) {
+ List<OpenExecution> joinedExecutions = new ArrayList<OpenExecution>();
+ scanRecursive(execution.getProcessInstance(), join, joinedExecutions);
+ return joinedExecutions;
+ }
+
+ void scanRecursive(OpenExecution execution, Node join, List<OpenExecution> joinedExecutions) {
+ // if the execution is positioned in the join
+ if (join.equals(execution.getNode())) {
+ joinedExecutions.add(execution);
+ }
+ Collection<OpenExecution> childExecutions = execution.getExecutions();
+ if (childExecutions!=null) {
+ for (OpenExecution childExecution: childExecutions) {
+ scanRecursive(childExecution, join, joinedExecutions);
+ }
+ }
+ }
+
+ boolean isComplete(List<OpenExecution> joinedExecutions, Node join) {
+ int executionsToJoin = join.getIncomingTransitions().size();
+ return (executionsToJoin==joinedExecutions.size());
+ }
+
+ void endJoinedExecutions(List<OpenExecution> joinedExecutions, ActivityExecution execution) {
+ for (OpenExecution joinedExecution: joinedExecutions) {
+ execution.end(joinedExecution);
+ }
+ }
+ }
+
+ 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 void testTransitionBasedConcurrency() {
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("fork").initial().behaviour(new Fork())
+ .transition("billing").to("bill")
+ .transition("shipping").to("ship")
+ .node("bill").behaviour(new WaitState())
+ .transition().to("join")
+ .node("ship").behaviour(new WaitState())
+ .transition().to("join")
+ .node("join").behaviour(new Join())
+ .transition().to("end")
+ .node("end").behaviour(new WaitState())
+ .done();
+
+ ClientExecution main = processDefinition.startProcessInstance();
+
+ assertNull("fork", main.getNode());
+ assertEquals(Execution.STATE_INACTIVE, main.getState());
+
+ Execution billing = main.getExecution("billing");
+ assertNotNull(billing);
+ assertEquals("bill", billing.getNodeName());
+ assertFalse(billing.isEnded());
+
+ Execution shipping = main.getExecution("shipping");
+
+ assertNotNull(shipping);
+ assertEquals("ship", shipping.getNodeName());
+ assertFalse(shipping.isEnded());
+ assertTrue(main.getExecutions().contains(billing));
+ assertTrue(main.getExecutions().contains(shipping));
+
+ main.signal(billing);
+
+ assertNull(main.getNodeName());
+ assertEquals("join", billing.getNodeName());
+ assertEquals("ship", shipping.getNodeName());
+ assertEquals(Execution.STATE_ACTIVE, shipping.getState());
+ assertEquals(Execution.STATE_INACTIVE, billing.getState());
+ assertEquals(Execution.STATE_INACTIVE, main.getState());
+
+ main.signal(shipping);
+
+ assertEquals(Execution.STATE_ACTIVE, main.getState());
+ assertEquals("end", main.getNodeName());
+ assertEquals("join", billing.getNodeName());
+ assertTrue(billing.isEnded());
+ assertEquals("join", shipping.getNodeName());
+ assertTrue(shipping.isEnded());
+ assertFalse(main.getExecutions().contains(billing));
+ assertFalse(main.getExecutions().contains(shipping));
+ }
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/TransitionEventsTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/TransitionEventsTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/TransitionEventsTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/TransitionEventsTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,454 @@
+/*
+ * 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.activities;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.listener.EventListener;
+import org.jbpm.listener.EventListenerExecution;
+import org.jbpm.model.Event;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Tom Baeyens
+ */
+public class TransitionEventsTest extends JbpmTestCase
+{
+
+ 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){
+ }
+ }
+
+ public class Recorder implements EventListener {
+ private static final long serialVersionUID = 1L;
+ public List<Object> events = new ArrayList<Object>();
+ public void notify(EventListenerExecution execution) {
+ events.add(execution.getEvent()+" on "+execution.getEventSource());
+ }
+ }
+
+
+ public void testCompositeLeave(){
+ Recorder processListener = new Recorder();
+ Recorder outsideListener = new Recorder();
+ Recorder compositeListener = new Recorder();
+ Recorder insideListener = new Recorder();
+
+ /*
+ +--------------+
+ | composite |
+ | +--------+ | +---------+
+ | | inside |------->| outside |
+ | +--------+ | +---------+
+ +--------------+
+ */
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("leave a super state")
+ .event(Event.NODE_END)
+ .listener(processListener)
+ .event(Event.NODE_BEGIN)
+ .listener(processListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(processListener)
+ .compositeNode("composite")
+ .event(Event.NODE_END)
+ .listener(compositeListener)
+ .event(Event.NODE_BEGIN)
+ .listener(compositeListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(compositeListener)
+ .node("inside").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(insideListener)
+ .event(Event.NODE_BEGIN)
+ .listener(insideListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(insideListener)
+ .transition().to("outside")
+ .compositeEnd()
+ .node("outside").behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(outsideListener)
+ .event(Event.NODE_BEGIN)
+ .listener(outsideListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(outsideListener)
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals(0, processListener.events.size());
+ assertEquals(0, outsideListener.events.size());
+ assertEquals(0, compositeListener.events.size());
+ assertEquals(0, insideListener.events.size());
+
+ assertEquals("inside", execution.getNode().getName());
+
+ execution.signal();
+
+ assertEquals("[event(node-end) on node(inside), " +
+ "event(node-end) on node(composite), " +
+ "event(transition-take) on (inside)-->(outside), " +
+ "event(node-begin) on node(outside)]",
+ processListener.events.toString());
+
+ assertEquals("[event(node-begin) on node(outside)]",
+ outsideListener.events.toString());
+
+ assertEquals("[event(node-end) on node(inside), " +
+ "event(node-end) on node(composite)]",
+ compositeListener.events.toString());
+
+ assertEquals("[event(node-end) on node(inside)]",
+ insideListener.events.toString());
+ }
+
+ public void testCompositeEnter(){
+ Recorder processListener = new Recorder();
+ Recorder outsideListener = new Recorder();
+ Recorder compositeListener = new Recorder();
+ Recorder insideListener = new Recorder();
+
+ /*
+ +--------------+
+ | composite |
+ +---------+ | +--------+ |
+ | outside |------>| inside | |
+ +---------+ | +--------+ |
+ +--------------+
+ */
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("enter a super state")
+ .event(Event.NODE_END)
+ .listener(processListener)
+ .event(Event.NODE_BEGIN)
+ .listener(processListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(processListener)
+ .node("outside").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(outsideListener)
+ .event(Event.NODE_BEGIN)
+ .listener(outsideListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(outsideListener)
+ .transition().to("inside")
+ .compositeNode("composite")
+ .event(Event.NODE_END)
+ .listener(compositeListener)
+ .event(Event.NODE_BEGIN)
+ .listener(compositeListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(compositeListener)
+ .node("inside").behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(insideListener)
+ .event(Event.NODE_BEGIN)
+ .listener(insideListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(insideListener)
+ .compositeEnd()
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals(0, processListener.events.size());
+ assertEquals(0, outsideListener.events.size());
+ assertEquals(0, compositeListener.events.size());
+ assertEquals(0, insideListener.events.size());
+
+ execution.signal();
+
+ assertEquals("[event(node-end) on node(outside), " +
+ "event(transition-take) on (outside)-->(inside), " +
+ "event(node-begin) on node(composite), " +
+ "event(node-begin) on node(inside)]",
+ processListener.events.toString());
+
+ assertEquals("[event(node-end) on node(outside)]",
+ outsideListener.events.toString());
+
+ assertEquals("[event(node-begin) on node(composite), " +
+ "event(node-begin) on node(inside)]",
+ compositeListener.events.toString());
+
+ assertEquals("[event(node-begin) on node(inside)]",
+ insideListener.events.toString());
+ }
+
+ public void testSelfTransition(){
+ Recorder processListener = new Recorder();
+ Recorder compositeListener = new Recorder();
+ Recorder insideListener = new Recorder();
+
+ /*
+ +-----------------+
+ | composite |
+ | +--------+ |
+ | | inside |---+ |
+ | | | | |
+ | | |<--+ |
+ | +--------+ |
+ +-----------------+
+ */
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("leave a super state")
+ .event(Event.NODE_END)
+ .listener(processListener)
+ .event(Event.NODE_BEGIN)
+ .listener(processListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(processListener)
+ .compositeNode("composite")
+ .event(Event.NODE_END)
+ .listener(compositeListener)
+ .event(Event.NODE_BEGIN)
+ .listener(compositeListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(compositeListener)
+ .node("inside").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(insideListener)
+ .event(Event.NODE_BEGIN)
+ .listener(insideListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(insideListener)
+ .transition().to("inside")
+ .compositeEnd()
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals(0, processListener.events.size());
+ assertEquals(0, compositeListener.events.size());
+ assertEquals(0, insideListener.events.size());
+
+ assertEquals("inside", execution.getNode().getName());
+
+ execution.signal();
+
+ assertEquals("[event(node-end) on node(inside), " +
+ "event(transition-take) on (inside)-->(inside), " +
+ "event(node-begin) on node(inside)]",
+ processListener.events.toString());
+
+ assertEquals("[event(node-end) on node(inside), " +
+ "event(transition-take) on (inside)-->(inside), " +
+ "event(node-begin) on node(inside)]",
+ compositeListener.events.toString());
+
+ assertEquals("[event(node-end) on node(inside), " +
+ "event(node-begin) on node(inside)]",
+ insideListener.events.toString());
+ }
+
+
+ public void testCompositeLeaveInheritedTransition(){
+ Recorder processListener = new Recorder();
+ Recorder outsideListener = new Recorder();
+ Recorder compositeListener = new Recorder();
+ Recorder insideListener = new Recorder();
+
+ /*
+ +--------------+ +---------+
+ | composite |------->| outside |
+ | +--------+ | +---------+
+ | | inside | |
+ | +--------+ |
+ +--------------+
+ */
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("leave a super state")
+ .event(Event.NODE_END)
+ .listener(processListener)
+ .event(Event.NODE_BEGIN)
+ .listener(processListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(processListener)
+ .compositeNode("composite")
+ .event(Event.NODE_END)
+ .listener(compositeListener)
+ .event(Event.NODE_BEGIN)
+ .listener(compositeListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(compositeListener)
+ .transition().to("outside")
+ .node("inside").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(insideListener)
+ .event(Event.NODE_BEGIN)
+ .listener(insideListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(insideListener)
+ .compositeEnd()
+ .node("outside").behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(outsideListener)
+ .event(Event.NODE_BEGIN)
+ .listener(outsideListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(outsideListener)
+ .done();
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals(0, processListener.events.size());
+ assertEquals(0, outsideListener.events.size());
+ assertEquals(0, compositeListener.events.size());
+ assertEquals(0, insideListener.events.size());
+
+ assertEquals("inside", execution.getNode().getName());
+
+ execution.signal();
+
+ assertEquals("[event(node-end) on node(inside), " +
+ "event(node-end) on node(composite), " +
+ "event(transition-take) on (composite)-->(outside), " +
+ "event(node-begin) on node(outside)]",
+ processListener.events.toString());
+
+ assertEquals("[event(node-begin) on node(outside)]",
+ outsideListener.events.toString());
+
+ assertEquals("[event(node-end) on node(inside), " +
+ "event(node-end) on node(composite)]",
+ compositeListener.events.toString());
+
+ assertEquals("[event(node-end) on node(inside)]",
+ insideListener.events.toString());
+ }
+
+ public void testCompositeLeaveInheritedTransitionExtraNesting(){
+ Recorder processListener = new Recorder();
+ Recorder sourceOutsideListener = new Recorder();
+ Recorder sourceMiddleListener = new Recorder();
+ Recorder sourceInsideListener = new Recorder();
+ Recorder destinationOutsideListener = new Recorder();
+ Recorder destinationInsideListener = new Recorder();
+
+ /*
+ +--------------------------+
+ | source outside |
+ | +--------------------+ | +--------------------------+
+ | | source middle | | | destination outside |
+ | | +---------------+ | | | +--------------------+ |
+ | | | source inside | |----------->| destination inside | |
+ | | +---------------+ | | | +--------------------+ |
+ | +--------------------+ | +--------------------------+
+ +--------------------------+
+ */
+
+ ClientProcessDefinition processDefinition = ProcessFactory.build("leave a super state")
+ .event(Event.NODE_END)
+ .listener(processListener)
+ .event(Event.NODE_BEGIN)
+ .listener(processListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(processListener)
+ .compositeNode("source outside")
+ .event(Event.NODE_END)
+ .listener(sourceOutsideListener)
+ .event(Event.NODE_BEGIN)
+ .listener(sourceOutsideListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(sourceOutsideListener)
+ .compositeNode("source middle")
+ .event(Event.NODE_END)
+ .listener(sourceMiddleListener)
+ .event(Event.NODE_BEGIN)
+ .listener(sourceMiddleListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(sourceMiddleListener)
+ .transition().to("destination inside")
+ .node("source inside").initial().behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(sourceInsideListener)
+ .event(Event.NODE_BEGIN)
+ .listener(sourceInsideListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(sourceInsideListener)
+ .compositeEnd()
+ .compositeEnd()
+ .compositeNode("destination outside")
+ .event(Event.NODE_END)
+ .listener(destinationOutsideListener)
+ .event(Event.NODE_BEGIN)
+ .listener(destinationOutsideListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(destinationOutsideListener)
+ .node("destination inside").behaviour(new WaitState())
+ .event(Event.NODE_END)
+ .listener(destinationInsideListener)
+ .event(Event.NODE_BEGIN)
+ .listener(destinationInsideListener)
+ .event(Event.TRANSITION_TAKE)
+ .listener(destinationInsideListener)
+ .compositeEnd()
+ .done();
+
+
+ ClientExecution execution = processDefinition.startProcessInstance();
+
+ assertEquals("source inside", execution.getNode().getName());
+
+ execution.signal();
+
+ assertEquals("[event(node-end) on node(source inside), " +
+ "event(node-end) on node(source middle), " +
+ "event(node-end) on node(source outside), " +
+ "event(transition-take) on (source middle)-->(destination inside), " +
+ "event(node-begin) on node(destination outside), " +
+ "event(node-begin) on node(destination inside)]",
+ processListener.events.toString());
+
+ assertEquals("[event(node-end) on node(source inside), " +
+ "event(node-end) on node(source middle), " +
+ "event(node-end) on node(source outside)]",
+ sourceOutsideListener.events.toString());
+
+ assertEquals("[event(node-end) on node(source inside), " +
+ "event(node-end) on node(source middle)]",
+ sourceMiddleListener.events.toString());
+
+ assertEquals("[event(node-end) on node(source inside)]",
+ sourceInsideListener.events.toString());
+
+ assertEquals("[event(node-begin) on node(destination outside), " +
+ "event(node-begin) on node(destination inside)]",
+ destinationOutsideListener.events.toString());
+
+ assertEquals("[event(node-begin) on node(destination inside)]",
+ destinationInsideListener.events.toString());
+ }
+}
Copied: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/VariableTest.java (from rev 3557, jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/api/basicfeatures/VariableTest.java)
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/VariableTest.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/VariableTest.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,248 @@
+/*
+ * 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.activities;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+import org.jbpm.client.ClientExecution;
+import org.jbpm.client.ClientProcessDefinition;
+import org.jbpm.client.ClientProcessInstance;
+import org.jbpm.pvm.model.ProcessFactory;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Tom Baeyens
+ */
+public class VariableTest extends JbpmTestCase {
+
+ 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){
+ }
+ }
+
+ public void testSetAndGetVariable() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ processInstance.setVariable("customer", "coca-cola");
+ assertEquals("coca-cola", processInstance.getVariable("customer"));
+
+ processInstance.setVariable("address", "usa");
+ assertEquals("usa", processInstance.getVariable("address"));
+
+ processInstance.setVariable("size", "big");
+ assertEquals("big", processInstance.getVariable("size"));
+ }
+
+ public void testHasVariable() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ processInstance.setVariable("customer", "coca-cola");
+
+ assertTrue(processInstance.hasVariable("customer"));
+ assertFalse(processInstance.hasVariable("address"));
+ }
+
+ public void testSetVariables() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ Map<String, Object> variables = new HashMap<String, Object>();
+ variables.put("customer", "coca-cola");
+ variables.put("address", "usa");
+ variables.put("size", "big");
+
+ processInstance.setVariables(variables);
+
+ assertEquals("coca-cola", processInstance.getVariable("customer"));
+ assertEquals("usa", processInstance.getVariable("address"));
+ assertEquals("big", processInstance.getVariable("size"));
+ }
+
+ public void testGetVariables() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ processInstance.setVariable("customer", "coca-cola");
+ processInstance.setVariable("address", "usa");
+ processInstance.setVariable("size", "big");
+
+ Map<String, Object> expectedVariables = new HashMap<String, Object>();
+ expectedVariables.put("customer", "coca-cola");
+ expectedVariables.put("address", "usa");
+ expectedVariables.put("size", "big");
+ assertEquals(expectedVariables, processInstance.getVariables());
+ }
+
+ public void testRemoveVariable() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ processInstance.setVariable("customer", "coca-cola");
+ processInstance.setVariable("address", "usa");
+ processInstance.setVariable("size", "big");
+
+ Map<String, Object> expectedVariables = new HashMap<String, Object>();
+ expectedVariables.put("customer", "coca-cola");
+ expectedVariables.put("address", "usa");
+ expectedVariables.put("size", "big");
+
+ assertEquals(expectedVariables, processInstance.getVariables());
+
+ processInstance.removeVariable("address");
+ expectedVariables.remove("address");
+
+ assertEquals(expectedVariables, processInstance.getVariables());
+
+ processInstance.removeVariable("customer");
+ expectedVariables.remove("customer");
+
+ assertEquals(expectedVariables, processInstance.getVariables());
+
+ processInstance.removeVariable("size");
+ expectedVariables.remove("size");
+
+ assertEquals(expectedVariables, processInstance.getVariables());
+ }
+
+ public void testRemoveVariables() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ processInstance.setVariable("customer", "coca-cola");
+ processInstance.setVariable("address", "usa");
+ processInstance.setVariable("size", "big");
+
+ processInstance.removeVariables();
+
+ Map<String, Object> expectedVariables = new HashMap<String, Object>();
+ assertEquals(expectedVariables, processInstance.getVariables());
+ }
+
+ public void testGetVariableKeys() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ processInstance.setVariable("customer", "coca-cola");
+ processInstance.setVariable("address", "usa");
+ processInstance.setVariable("size", "big");
+
+ Set<String> expectedVariableKeys = new HashSet<String>();
+ expectedVariableKeys.add("customer");
+ expectedVariableKeys.add("address");
+ expectedVariableKeys.add("size");
+ assertEquals(expectedVariableKeys, new HashSet<String>(processInstance.getVariableKeys()));
+ }
+
+ public void testGetUnexistingVariable() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ assertNull(processInstance.getVariable("answer to life, the universe and everything"));
+ }
+
+ public static class VariableActivity implements ExternalActivity {
+ private static final long serialVersionUID = 1L;
+ public void execute(ActivityExecution execution) {
+ assertEquals("coca-cola", execution.getVariable("customer"));
+ execution.setVariable("message", "Killroy was here");
+ execution.waitForSignal();
+ }
+ public void signal(ActivityExecution execution, String signalName, Map<String, Object> parameters) {
+ }
+ }
+
+ public void testInitialiseVariablesBeforeProcessInstanceBegin() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new VariableActivity())
+ .done();
+
+ // here, the process instance is created first, and only later it is begun
+ ClientProcessInstance processInstance = processDefinition.createProcessInstance();
+ processInstance.setVariable("customer", "coca-cola");
+ processInstance.start();
+ assertEquals("Killroy was here", processInstance.getVariable("message"));
+ }
+
+ public void testNullValue() {
+ ClientProcessDefinition processDefinition = ProcessFactory.build()
+ .node("a").initial().behaviour(new WaitState())
+ .done();
+
+ ClientExecution processInstance = processDefinition.startProcessInstance();
+
+ processInstance.setVariable("niks", null);
+ processInstance.setVariable("nada", null);
+
+ assertTrue(processInstance.hasVariables());
+ assertTrue(processInstance.hasVariable("niks"));
+ assertTrue(processInstance.hasVariable("nada"));
+
+ assertNull(processInstance.getVariable("niks"));
+ assertNull(processInstance.getVariable("nada"));
+
+ Set<String> expectedKeys = new HashSet<String>();
+ expectedKeys.add("niks");
+ expectedKeys.add("nada");
+ assertEquals(expectedKeys, new HashSet<String>(processInstance.getVariableKeys()));
+
+ Map<String, Object> expectedVariables = new HashMap<String, Object>();
+ expectedVariables.put("niks", null);
+ expectedVariables.put("nada", null);
+ assertEquals(expectedVariables, new HashMap<String, Object>(processInstance.getVariables()));
+ }
+
+}
Added: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/WaitState.java
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/WaitState.java (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/WaitState.java 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,44 @@
+/*
+ * 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.activities;
+
+import java.util.Map;
+
+import org.jbpm.activity.ActivityExecution;
+import org.jbpm.activity.ExternalActivity;
+
+/**
+ * @author Tom Baeyens
+ */
+public 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) {
+ }
+}
Property changes on: jbpm4/trunk/modules/test-pojo/src/main/java/org/jbpm/test/activities/WaitState.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: jbpm4/trunk/modules/test-pojo/src/main/resources/logging.properties
===================================================================
--- jbpm4/trunk/modules/test-pojo/src/main/resources/logging.properties (rev 0)
+++ jbpm4/trunk/modules/test-pojo/src/main/resources/logging.properties 2008-12-27 13:20:00 UTC (rev 3560)
@@ -0,0 +1,28 @@
+handlers= java.util.logging.ConsoleHandler
+# to add the error triggered file handler
+# handlers= java.util.logging.ConsoleHandler org.jbpm.util.ErrorTriggeredFileHandler
+
+redirect.commons.logging = enabled
+
+java.util.logging.ConsoleHandler.level = FINEST
+java.util.logging.ConsoleHandler.formatter = org.jbpm.log.LogFormatter
+
+# org.jbpm.util.ErrorTriggeredFileHandler.size = 500
+# org.jbpm.util.ErrorTriggeredFileHandler.push = OFF
+# org.jbpm.util.ErrorTriggeredFileHandler.pattern = %h/jbpm%u.log
+
+# For example, set the com.xyz.foo logger to only log SEVERE messages:
+# com.xyz.foo.level = SEVERE
+
+org.jbpm.level=INFO
+# org.jbpm.pvm.internal.tx.level=FINE
+# org.jbpm.pvm.internal.wire.level=FINE
+# org.jbpm.pvm.internal.util.level=FINE
+
+org.hibernate.level=INFO
+org.hibernate.cfg.HbmBinder.level=SEVERE
+org.hibernate.cfg.SettingsFactory.level=SEVERE
+# org.hibernate.SQL.level=FINEST
+# org.hibernate.type.level=FINEST
+# org.hibernate.tool.hbm2ddl.SchemaExport.level=FINEST
+# org.hibernate.transaction.level=FINEST
More information about the jbpm-commits
mailing list