提交 166cde55 编写于 作者: J jbarrez

Deleting unwanted files due to overzealous Eclipse commit

上级 111f6c46
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.activiti.engine.delegate.EventListener;
import org.activiti.engine.delegate.EventListenerExecution;
/**
* @author Tom Baeyens
*/
public class EventCollector implements EventListener {
private static Logger log = Logger.getLogger(EventCollector.class.getName());
public List<String> events = new ArrayList<String>();
public void notify(EventListenerExecution execution) {
log.fine("collecting event: "+execution.getEventName()+" on "+execution.getEventSource());
events.add(execution.getEventName()+" on "+execution.getEventSource());
}
public String toString() {
StringBuilder text = new StringBuilder();
for (String event: events) {
text.append(event);
text.append("\n");
}
return text.toString();
}
}
package org.activiti.test.pvm;
import java.util.ArrayList;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.WaitState;
import org.activiti.test.pvm.activities.While;
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @author Tom Baeyens
*/
public class PvmBasicLinearExecutionTest extends PvmTestCase {
/**
* +-------+ +-----+
* | start |-->| end |
* +-------+ +-----+
*/
public void testStartEnd() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
/**
* +-----+ +-----+ +-------+
* | one |-->| two |-->| three |
* +-----+ +-----+ +-------+
*/
public void testSingleAutomatic() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("one")
.initial()
.behavior(new Automatic())
.transition("two")
.endActivity()
.createActivity("two")
.behavior(new Automatic())
.transition("three")
.endActivity()
.createActivity("three")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
/**
* +-----+ +-----+ +-------+
* | one |-->| two |-->| three |
* +-----+ +-----+ +-------+
*/
public void testSingleWaitState() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("one")
.initial()
.behavior(new Automatic())
.transition("two")
.endActivity()
.createActivity("two")
.behavior(new WaitState())
.transition("three")
.endActivity()
.createActivity("three")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
PvmExecution activityInstance = processInstance.findExecution("two");
assertNotNull(activityInstance);
activityInstance.signal(null, null);
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
/**
* +-----+ +-----+ +-------+ +------+ +------+
* | one |-->| two |-->| three |-->| four |--> | five |
* +-----+ +-----+ +-------+ +------+ +------+
*/
public void testCombinationOfWaitStatesAndAutomatics() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("one")
.endActivity()
.createActivity("one")
.behavior(new WaitState())
.transition("two")
.endActivity()
.createActivity("two")
.behavior(new WaitState())
.transition("three")
.endActivity()
.createActivity("three")
.behavior(new Automatic())
.transition("four")
.endActivity()
.createActivity("four")
.behavior(new Automatic())
.transition("five")
.endActivity()
.createActivity("five")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
PvmExecution activityInstance = processInstance.findExecution("one");
assertNotNull(activityInstance);
activityInstance.signal(null, null);
activityInstance = processInstance.findExecution("two");
assertNotNull(activityInstance);
activityInstance.signal(null, null);
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
/**
* +----------------------------+
* v |
* +-------+ +------+ +-----+ +-----+ +-------+
* | start |-->| loop |-->| one |-->| two |--> | three |
* +-------+ +------+ +-----+ +-----+ +-------+
* |
* | +-----+
* +-->| end |
* +-----+
*/
public void testWhileLoop() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("loop")
.endActivity()
.createActivity("loop")
.behavior(new While("count", 0, 500))
.transition("one", "more")
.transition("end", "done")
.endActivity()
.createActivity("one")
.behavior(new Automatic())
.transition("two")
.endActivity()
.createActivity("two")
.behavior(new Automatic())
.transition("three")
.endActivity()
.createActivity("three")
.behavior(new Automatic())
.transition("loop")
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.EmbeddedSubProcess;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.ParallelGateway;
import org.activiti.test.pvm.activities.WaitState;
/**
* @author Tom Baeyens
*/
public class PvmEmbeddedSubProcessTest extends PvmTestCase {
/**
* +------------------------------+
* | embedded subprocess |
* +-----+ | +-----------+ +---------+ | +---+
* |start|-->| |startInside|-->|endInside| |-->|end|
* +-----+ | +-----------+ +---------+ | +---+
* +------------------------------+
*/
public void testEmbeddedSubProcess() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("embeddedsubprocess")
.endActivity()
.createActivity("embeddedsubprocess")
.scope()
.behavior(new EmbeddedSubProcess())
.createActivity("startInside")
.behavior(new Automatic())
.transition("endInside")
.endActivity()
.createActivity("endInside")
.behavior(new End())
.endActivity()
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
List<String> expectedActiveActivityIds = new ArrayList<String>();
expectedActiveActivityIds.add("end");
assertEquals(expectedActiveActivityIds, processInstance.findActiveActivityIds());
}
/**
* +----------------------------------------+
* | embeddedsubprocess +----------+ |
* | +---->|endInside1| |
* | | +----------+ |
* | | |
* +-----+ | +-----------+ +----+ +----------+ | +---+
* |start|-->| |startInside|-->|fork|-->|endInside2| |-->|end|
* +-----+ | +-----------+ +----+ +----------+ | +---+
* | | |
* | | +----------+ |
* | +---->|endInside3| |
* | +----------+ |
* +----------------------------------------+
*/
public void testMultipleConcurrentEndsInsideEmbeddedSubProcess() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("embeddedsubprocess")
.endActivity()
.createActivity("embeddedsubprocess")
.scope()
.behavior(new EmbeddedSubProcess())
.createActivity("startInside")
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("endInside1")
.transition("endInside2")
.transition("endInside3")
.endActivity()
.createActivity("endInside1")
.behavior(new End())
.endActivity()
.createActivity("endInside2")
.behavior(new End())
.endActivity()
.createActivity("endInside3")
.behavior(new End())
.endActivity()
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertTrue(processInstance.isEnded());
}
/**
* +-------------------------------------------------+
* | embeddedsubprocess +----------+ |
* | +---->|endInside1| |
* | | +----------+ |
* | | |
* +-----+ | +-----------+ +----+ +----+ +----------+ | +---+
* |start|-->| |startInside|-->|fork|-->|wait|-->|endInside2| |-->|end|
* +-----+ | +-----------+ +----+ +----+ +----------+ | +---+
* | | |
* | | +----------+ |
* | +---->|endInside3| |
* | +----------+ |
* +-------------------------------------------------+
*/
public void testMultipleConcurrentEndsInsideEmbeddedSubProcessWithWaitState() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("embeddedsubprocess")
.endActivity()
.createActivity("embeddedsubprocess")
.scope()
.behavior(new EmbeddedSubProcess())
.createActivity("startInside")
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("endInside1")
.transition("wait")
.transition("endInside3")
.endActivity()
.createActivity("endInside1")
.behavior(new End())
.endActivity()
.createActivity("wait")
.behavior(new WaitState())
.transition("endInside2")
.endActivity()
.createActivity("endInside2")
.behavior(new End())
.endActivity()
.createActivity("endInside3")
.behavior(new End())
.endActivity()
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertFalse(processInstance.isEnded());
PvmExecution execution = processInstance.findExecution("wait");
execution.signal(null, null);
assertTrue(processInstance.isEnded());
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.delegate.EventListener;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.EmbeddedSubProcess;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.ParallelGateway;
import org.activiti.test.pvm.activities.WaitState;
/**
* @author Tom Baeyens
*/
public class PvmEventTest extends PvmTestCase {
/**
* +-------+ +-----+
* | start |-->| end |
* +-------+ +-----+
*/
public void testStartEndEvents() {
EventCollector eventCollector = new EventCollector();
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("events")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("start")
.initial()
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.startTransition("end")
.eventListener(eventCollector)
.endTransition()
.endActivity()
.createActivity("end")
.behavior(new End())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
List<String> expectedEvents = new ArrayList<String>();
expectedEvents.add("start on ProcessDefinition(events)");
expectedEvents.add("start on Activity(start)");
expectedEvents.add("end on Activity(start)");
expectedEvents.add("take on (start)-->(end)");
expectedEvents.add("start on Activity(end)");
expectedEvents.add("end on Activity(end)");
expectedEvents.add("end on ProcessDefinition(events)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
}
/**
* +--------------+
* |outerscope |
* | +----------+ |
* | |innerscope| |
* +-----+ | | +----+ | | +---+
* |start|---->|wait|------>|end|
* +-----+ | | +----+ | | +---+
* | +----------+ |
* +--------------+
*/
public void testNestedActivitiesEventsOnTransitionEvents() {
EventCollector eventCollector = new EventCollector();
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("events")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("start")
.initial()
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.startTransition("wait")
.eventListener(eventCollector)
.endTransition()
.endActivity()
.createActivity("outerscope")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("innerscope")
.scope()
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("wait")
.behavior(new WaitState())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("end")
.endActivity()
.endActivity()
.endActivity()
.createActivity("end")
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
List<String> expectedEvents = new ArrayList<String>();
expectedEvents.add("start on ProcessDefinition(events)");
expectedEvents.add("start on Activity(start)");
expectedEvents.add("end on Activity(start)");
expectedEvents.add("take on (start)-->(wait)");
expectedEvents.add("start on Activity(outerscope)");
expectedEvents.add("start on Activity(innerscope)");
expectedEvents.add("start on Activity(wait)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
PvmExecution execution = processInstance.findExecution("wait");
execution.signal(null, null);
expectedEvents.add("end on Activity(wait)");
expectedEvents.add("end on Activity(innerscope)");
expectedEvents.add("end on Activity(outerscope)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
}
/**
* +------------------------------+
* +-----+ | +-----------+ +----------+ | +---+
* |start|-->| |startInside|-->|endInsdide| |-->|end|
* +-----+ | +-----------+ +----------+ | +---+
* +------------------------------+
*/
public void testEmbeddedSubProcessEvents() {
EventCollector eventCollector = new EventCollector();
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("events")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("start")
.initial()
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("embeddedsubprocess")
.endActivity()
.createActivity("embeddedsubprocess")
.scope()
.behavior(new EmbeddedSubProcess())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("startInside")
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("endInside")
.endActivity()
.createActivity("endInside")
.behavior(new End())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.endActivity()
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
List<String> expectedEvents = new ArrayList<String>();
expectedEvents.add("start on ProcessDefinition(events)");
expectedEvents.add("start on Activity(start)");
expectedEvents.add("end on Activity(start)");
expectedEvents.add("start on Activity(embeddedsubprocess)");
expectedEvents.add("start on Activity(startInside)");
expectedEvents.add("end on Activity(startInside)");
expectedEvents.add("start on Activity(endInside)");
expectedEvents.add("end on Activity(endInside)");
expectedEvents.add("end on Activity(embeddedsubprocess)");
expectedEvents.add("start on Activity(end)");
expectedEvents.add("end on Activity(end)");
expectedEvents.add("end on ProcessDefinition(events)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
}
/**
* +--+
* +--->|c1|---+
* | +--+ |
* | v
* +-----+ +----+ +----+ +---+
* |start|-->|fork| |join|-->|end|
* +-----+ +----+ +----+ +---+
* | ^
* | +--+ |
* +--->|c2|---+
* +--+
*/
public void testSimpleAutmaticConcurrencyEvents() {
EventCollector eventCollector = new EventCollector();
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("events")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("start")
.initial()
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("c1")
.transition("c2")
.endActivity()
.createActivity("c1")
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("join")
.endActivity()
.createActivity("c2")
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("join")
.endActivity()
.createActivity("join")
.behavior(new ParallelGateway())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
List<String> expectedEvents = new ArrayList<String>();
expectedEvents.add("start on ProcessDefinition(events)");
expectedEvents.add("start on Activity(start)");
expectedEvents.add("end on Activity(start)");
expectedEvents.add("start on Activity(fork)");
expectedEvents.add("end on Activity(fork)");
expectedEvents.add("start on Activity(c1)");
expectedEvents.add("end on Activity(c1)");
expectedEvents.add("start on Activity(join)");
expectedEvents.add("end on Activity(fork)");
expectedEvents.add("start on Activity(c2)");
expectedEvents.add("end on Activity(c2)");
expectedEvents.add("start on Activity(join)");
expectedEvents.add("end on Activity(join)");
expectedEvents.add("start on Activity(end)");
expectedEvents.add("end on Activity(end)");
expectedEvents.add("end on ProcessDefinition(events)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.ParallelGateway;
/**
* @author Tom Baeyens
*/
public class PvmParallelEndTest extends PvmTestCase {
/**
* +----+
* +--->|end1|
* | +----+
* |
* +-----+ +----+
* |start|-->|fork|
* +-----+ +----+
* |
* | +----+
* +--->|end2|
* +----+
*/
public void testParallelEnd() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("end1")
.transition("end2")
.endActivity()
.createActivity("end1")
.behavior(new End())
.endActivity()
.createActivity("end2")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertTrue(processInstance.isEnded());
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.ParallelGateway;
import org.activiti.test.pvm.activities.WaitState;
/**
* @author Tom Baeyens
*/
public class PvmParallelTest extends PvmTestCase {
public void testSimpleAutmaticConcurrency() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("c1")
.transition("c2")
.endActivity()
.createActivity("c1")
.behavior(new Automatic())
.transition("join")
.endActivity()
.createActivity("c2")
.behavior(new Automatic())
.transition("join")
.endActivity()
.createActivity("join")
.behavior(new ParallelGateway())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertTrue(processInstance.isEnded());
}
public void testSimpleWaitStateConcurrency() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("c1")
.transition("c2")
.endActivity()
.createActivity("c1")
.behavior(new WaitState())
.transition("join")
.endActivity()
.createActivity("c2")
.behavior(new WaitState())
.transition("join")
.endActivity()
.createActivity("join")
.behavior(new ParallelGateway())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
PvmExecution activityInstanceC1 = processInstance.findExecution("c1");
assertNotNull(activityInstanceC1);
PvmExecution activityInstanceC2 = processInstance.findExecution("c2");
assertNotNull(activityInstanceC2);
activityInstanceC1.signal(null, null);
activityInstanceC2.signal(null, null);
List<String> activityNames = processInstance.findActiveActivityIds();
List<String> expectedActivityNames = new ArrayList<String>();
expectedActivityNames.add("end");
assertEquals(expectedActivityNames, activityNames);
}
public void testUnstructuredConcurrencyTwoJoins() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("c1")
.transition("c2")
.transition("c3")
.endActivity()
.createActivity("c1")
.behavior(new Automatic())
.transition("join1")
.endActivity()
.createActivity("c2")
.behavior(new Automatic())
.transition("join1")
.endActivity()
.createActivity("c3")
.behavior(new Automatic())
.transition("join2")
.endActivity()
.createActivity("join1")
.behavior(new ParallelGateway())
.transition("c4")
.endActivity()
.createActivity("c4")
.behavior(new Automatic())
.transition("join2")
.endActivity()
.createActivity("join2")
.behavior(new ParallelGateway())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertNotNull(processInstance.findExecution("end"));
}
public void testUnstructuredConcurrencyTwoForks() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("fork1")
.endActivity()
.createActivity("fork1")
.behavior(new ParallelGateway())
.transition("c1")
.transition("c2")
.transition("fork2")
.endActivity()
.createActivity("c1")
.behavior(new Automatic())
.transition("join")
.endActivity()
.createActivity("c2")
.behavior(new Automatic())
.transition("join")
.endActivity()
.createActivity("fork2")
.behavior(new ParallelGateway())
.transition("c3")
.transition("c4")
.endActivity()
.createActivity("c3")
.behavior(new Automatic())
.transition("join")
.endActivity()
.createActivity("c4")
.behavior(new Automatic())
.transition("join")
.endActivity()
.createActivity("join")
.behavior(new ParallelGateway())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertNotNull(processInstance.findExecution("end"));
}
public void testJoinForkCombinedInOneParallelGateway() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("fork")
.endActivity()
.createActivity("fork")
.behavior(new ParallelGateway())
.transition("c1")
.transition("c2")
.transition("c3")
.endActivity()
.createActivity("c1")
.behavior(new Automatic())
.transition("join1")
.endActivity()
.createActivity("c2")
.behavior(new Automatic())
.transition("join1")
.endActivity()
.createActivity("c3")
.behavior(new Automatic())
.transition("join2")
.endActivity()
.createActivity("join1")
.behavior(new ParallelGateway())
.transition("c4")
.transition("c5")
.transition("c6")
.endActivity()
.createActivity("c4")
.behavior(new Automatic())
.transition("join2")
.endActivity()
.createActivity("c5")
.behavior(new Automatic())
.transition("join2")
.endActivity()
.createActivity("c6")
.behavior(new Automatic())
.transition("join2")
.endActivity()
.createActivity("join2")
.behavior(new ParallelGateway())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
assertNotNull(processInstance.findExecution("end"));
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import org.activiti.engine.delegate.EventListener;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.WaitState;
/**
* @author Tom Baeyens
*/
public class PvmProcessInstanceEndTest extends PvmTestCase {
public void testSimpleProcessInstanceEnd() {
EventCollector eventCollector = new EventCollector();
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("wait")
.endActivity()
.createActivity("wait")
.behavior(new WaitState())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
System.err.println(eventCollector);
processInstance.deleteCascade("test");
System.err.println();
System.err.println(eventCollector);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.ReusableSubProcess;
/**
* @author Tom Baeyens
*/
public class PvmReusableSubProcessTest extends PvmTestCase {
public void testReusableSubProcess() {
PvmProcessDefinition subProcessDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("subEnd")
.endActivity()
.createActivity("subEnd")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessDefinition superProcessDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("subprocess")
.endActivity()
.createActivity("subprocess")
.behavior(new ReusableSubProcess(subProcessDefinition))
.transition("superEnd")
.endActivity()
.createActivity("superEnd")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = superProcessDefinition.createProcessInstance();
processInstance.start();
assertTrue(processInstance.isEnded());
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.delegate.EventListener;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.WaitState;
/**
* @author Tom Baeyens
*/
public class PvmScopeAndEventsTest extends PvmTestCase {
/**
* +--------------------------------------------------------------------------------+
* | mostOuterNestedActivity |
* | +----------------------------------------------------------------------------+ |
* | | outerScope (scope) | |
* | | +----------------------------------+ +-----------------------------------+ | |
* | | | firstInnerScope (scope) | | secondInnerScope (scope) | | |
* | | | +------------------------------+ | | +-------------------------------+ | | |
* | | | | firstMostInnerNestedActivity | | | | secondMostInnerNestedActivity | | | |
* | | | | +-------+ +-------------+ | | | | +--------------+ +-----+ | | | |
* | | | | | start |-->| waitInFirst |--------->| waitInSecond |--> | end | | | | |
* | | | | +-------+ +-------------+ | | | | +--------------+ +-----+ | | | |
* | | | +------------------------------+ | | +-------------------------------+ | | |
* | | +----------------------------------+ +-----------------------------------+ | |
* | +----------------------------------------------------------------------------+ |
* +--------------------------------------------------------------------------------+
*
*/
public void testStartEndWithScopesAndNestedActivities() {
EventCollector eventCollector = new EventCollector();
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder("scopes and events")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("mostOuterNestedActivity")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("outerScope")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("firstInnerScope")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("firstMostInnerNestedActivity")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("start")
.initial()
.behavior(new Automatic())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("waitInFirst")
.endActivity()
.createActivity("waitInFirst")
.behavior(new WaitState())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("waitInSecond")
.endActivity()
.endActivity()
.endActivity()
.createActivity("secondInnerScope")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("secondMostInnerNestedActivity")
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.createActivity("waitInSecond")
.behavior(new WaitState())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.eventListener(EventListener.EVENTNAME_START, eventCollector)
.eventListener(EventListener.EVENTNAME_END, eventCollector)
.endActivity()
.endActivity()
.endActivity()
.endActivity()
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
List<String> expectedEvents = new ArrayList<String>();
expectedEvents.add("start on ProcessDefinition(scopes and events)");
expectedEvents.add("start on Activity(mostOuterNestedActivity)");
expectedEvents.add("start on Activity(outerScope)");
expectedEvents.add("start on Activity(firstInnerScope)");
expectedEvents.add("start on Activity(firstMostInnerNestedActivity)");
expectedEvents.add("start on Activity(start)");
expectedEvents.add("end on Activity(start)");
expectedEvents.add("start on Activity(waitInFirst)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
eventCollector.events.clear();
PvmExecution execution = processInstance.findExecution("waitInFirst");
execution.signal(null, null);
expectedEvents = new ArrayList<String>();
expectedEvents.add("end on Activity(waitInFirst)");
expectedEvents.add("end on Activity(firstMostInnerNestedActivity)");
expectedEvents.add("end on Activity(firstInnerScope)");
expectedEvents.add("start on Activity(secondInnerScope)");
expectedEvents.add("start on Activity(secondMostInnerNestedActivity)");
expectedEvents.add("start on Activity(waitInSecond)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
eventCollector.events.clear();
execution = processInstance.findExecution("waitInSecond");
execution.signal(null, null);
expectedEvents = new ArrayList<String>();
expectedEvents.add("end on Activity(waitInSecond)");
expectedEvents.add("start on Activity(end)");
expectedEvents.add("end on Activity(end)");
expectedEvents.add("end on Activity(secondMostInnerNestedActivity)");
expectedEvents.add("end on Activity(secondInnerScope)");
expectedEvents.add("end on Activity(outerScope)");
expectedEvents.add("end on Activity(mostOuterNestedActivity)");
expectedEvents.add("end on ProcessDefinition(scopes and events)");
assertEquals("expected "+expectedEvents+", but was \n"+eventCollector+"\n", expectedEvents, eventCollector.events);
eventCollector.events.clear();
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.ArrayList;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.Automatic;
import org.activiti.test.pvm.activities.End;
import org.activiti.test.pvm.activities.WaitState;
/**
* @author Tom Baeyens
*/
public class PvmScopeWaitStateTest extends PvmTestCase {
/**
* +-----+ +----------+ +---+
* |start|-->|scopedWait|-->|end|
* +-----+ +----------+ +---+
*/
public void testWaitStateScope() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("scopedWait")
.endActivity()
.createActivity("scopedWait")
.scope()
.behavior(new WaitState())
.transition("end")
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
PvmExecution execution = processInstance.findExecution("scopedWait");
assertNotNull(execution);
execution.signal(null, null);
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
/**
* +--------------+
* | outerScope |
* +-----+ | +----------+ | +---+
* |start|--->|scopedWait|--->|end|
* +-----+ | +----------+ | +---+
* +--------------+
*/
public void testNestedScope() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("start")
.initial()
.behavior(new Automatic())
.transition("scopedWait")
.endActivity()
.createActivity("outerScope")
.scope()
.createActivity("scopedWait")
.scope()
.behavior(new WaitState())
.transition("end")
.endActivity()
.endActivity()
.createActivity("end")
.behavior(new End())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.start();
PvmExecution activityInstance = processInstance.findExecution("scopedWait");
assertNotNull(activityInstance);
activityInstance.signal(null, null);
assertEquals(new ArrayList<String>(), processInstance.findActiveActivityIds());
assertTrue(processInstance.isEnded());
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.impl.pvm.ProcessDefinitionBuilder;
import org.activiti.engine.impl.pvm.PvmExecution;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.test.PvmTestCase;
import org.activiti.test.pvm.activities.WaitState;
import org.junit.Test;
/**
* @author Tom Baeyens
*/
public class PvmVariablesTest extends PvmTestCase {
@Test
public void testVariables() {
PvmProcessDefinition processDefinition = new ProcessDefinitionBuilder()
.createActivity("a")
.initial()
.behavior(new WaitState())
.endActivity()
.buildProcessDefinition();
PvmProcessInstance processInstance = processDefinition.createProcessInstance();
processInstance.setVariable("amount", 500L);
processInstance.setVariable("msg", "hello world");
processInstance.start();
assertEquals(500L, processInstance.getVariable("amount"));
assertEquals("hello world", processInstance.getVariable("msg"));
PvmExecution activityInstance = processInstance.findExecution("a");
assertEquals(500L, activityInstance.getVariable("amount"));
assertEquals("hello world", activityInstance.getVariable("msg"));
Map<String, Object> expectedVariables = new HashMap<String, Object>();
expectedVariables.put("amount", 500L);
expectedVariables.put("msg", "hello world");
assertEquals(expectedVariables, activityInstance.getVariables());
assertEquals(expectedVariables, processInstance.getVariables());
}
}
\ No newline at end of file
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import org.activiti.engine.delegate.ActivityBehavior;
import org.activiti.engine.delegate.ActivityExecution;
import org.activiti.engine.impl.pvm.PvmTransition;
/**
* @author Tom Baeyens
*/
public class Automatic implements ActivityBehavior {
public void execute(ActivityExecution execution) throws Exception {
PvmTransition transition = execution.getActivity().getOutgoingTransitions().get(0);
execution.take(transition);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.activiti.engine.delegate.ActivityExecution;
import org.activiti.engine.delegate.CompositeActivityBehavior;
import org.activiti.engine.impl.pvm.PvmActivity;
import org.activiti.engine.impl.pvm.PvmTransition;
/**
* @author Tom Baeyens
*/
public class EmbeddedSubProcess implements CompositeActivityBehavior {
public void execute(ActivityExecution execution) throws Exception {
List<PvmActivity> startActivities = new ArrayList<PvmActivity>();
for (PvmActivity activity: execution.getActivity().getActivities()) {
if (activity.getIncomingTransitions().isEmpty()) {
startActivities.add(activity);
}
}
for (PvmActivity startActivity: startActivities) {
execution.executeActivity(startActivity);
}
}
@SuppressWarnings("unchecked")
public void lastExecutionEnded(ActivityExecution execution) {
List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
execution.takeAll(outgoingTransitions, Collections.EMPTY_LIST);
}
// used by timers
@SuppressWarnings("unchecked")
public void timerFires(ActivityExecution execution, String signalName, Object signalData) throws Exception {
PvmActivity timerActivity = execution.getActivity();
boolean isInterrupting = (Boolean) timerActivity.getProperty("isInterrupting");
List<ActivityExecution> recyclableExecutions = null;
if (isInterrupting) {
recyclableExecutions = removeAllExecutions(execution);
} else {
recyclableExecutions = Collections.EMPTY_LIST;
}
execution.takeAll(timerActivity.getOutgoingTransitions(), recyclableExecutions);
}
private List<ActivityExecution> removeAllExecutions(ActivityExecution execution) {
return null;
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import org.activiti.engine.delegate.ActivityBehavior;
import org.activiti.engine.delegate.ActivityExecution;
/**
* @author Tom Baeyens
*/
public class End implements ActivityBehavior {
public void execute(ActivityExecution execution) throws Exception {
execution.end();
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.activiti.engine.delegate.ActivityBehavior;
import org.activiti.engine.delegate.ActivityExecution;
import org.activiti.engine.impl.pvm.PvmActivity;
import org.activiti.engine.impl.pvm.PvmTransition;
import org.activiti.engine.impl.pvm.runtime.ExecutionImpl;
/**
* @author Tom Baeyens
*/
public class ParallelGateway implements ActivityBehavior {
private static Logger log = Logger.getLogger(ParallelGateway.class.getName());
public void execute(ActivityExecution execution) {
PvmActivity activity = execution.getActivity();
List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
execution.inactivate();
List<ActivityExecution> joinedExecutions = execution.findInactiveConcurrentExecutions(activity);
int nbrOfExecutionsToJoin = execution.getActivity().getIncomingTransitions().size();
int nbrOfExecutionsJoined = joinedExecutions.size();
if (nbrOfExecutionsJoined==nbrOfExecutionsToJoin) {
log.fine("parallel gateway '"+activity.getId()+"' activates: "+nbrOfExecutionsJoined+" of "+nbrOfExecutionsToJoin+" joined");
execution.takeAll(outgoingTransitions, joinedExecutions);
} else if (log.isLoggable(Level.FINE)){
log.fine("parallel gateway '"+activity.getId()+"' does not activate: "+nbrOfExecutionsJoined+" of "+nbrOfExecutionsToJoin+" joined");
}
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import java.util.List;
import org.activiti.engine.delegate.ActivityExecution;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.SubProcessActivityBehavior;
import org.activiti.engine.impl.pvm.PvmProcessDefinition;
import org.activiti.engine.impl.pvm.PvmProcessInstance;
import org.activiti.engine.impl.pvm.PvmTransition;
/**
* @author Tom Baeyens
*/
public class ReusableSubProcess implements SubProcessActivityBehavior {
PvmProcessDefinition processDefinition;
public ReusableSubProcess(PvmProcessDefinition processDefinition) {
this.processDefinition = processDefinition;
}
public void execute(ActivityExecution execution) throws Exception {
PvmProcessInstance subProcessInstance = execution.createSubProcessInstance(processDefinition);
// TODO set variables
subProcessInstance.start();
}
public void completing(DelegateExecution execution, DelegateExecution subProcessInstance) throws Exception {
// TODO extract information from the subprocess and inject it into the superprocess
}
public void completed(ActivityExecution execution) throws Exception {
List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
execution.takeAll(outgoingTransitions, null);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import org.activiti.engine.delegate.ActivityExecution;
import org.activiti.engine.delegate.SignallableActivityBehavior;
import org.activiti.engine.impl.pvm.PvmTransition;
/**
* @author Tom Baeyens
*/
public class WaitState implements SignallableActivityBehavior {
public void execute(ActivityExecution execution) throws Exception {
}
public void signal(ActivityExecution execution, String signalName, Object signalData) throws Exception {
PvmTransition transition = execution.getActivity().getOutgoingTransitions().get(0);
execution.take(transition);
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.test.pvm.activities;
import org.activiti.engine.delegate.ActivityBehavior;
import org.activiti.engine.delegate.ActivityExecution;
import org.activiti.engine.impl.pvm.PvmTransition;
/**
* @author Tom Baeyens
*/
public class While implements ActivityBehavior {
String variableName;
int from;
int to;
public While(String variableName, int from, int to) {
this.variableName = variableName;
this.from = from;
this.to = to;
}
public void execute(ActivityExecution execution) throws Exception {
PvmTransition more = execution.getActivity().findOutgoingTransition("more");
PvmTransition done = execution.getActivity().findOutgoingTransition("done");
Integer value = (Integer) execution.getVariable(variableName);
if (value==null) {
execution.setVariable(variableName, from);
execution.take(more);
} else {
value = value+1;
if (value<to) {
execution.setVariable(variableName, value);
execution.take(more);
} else {
execution.take(done);
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册