package process;
import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestSuite;
import de.danet.an.util.junit.EJBClientTest;
/**
* Describe class
* <code>ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity</code> here.
*
* @author mao
* @version 1.0
*/
public class ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity
extends WfMOpenTestCase {
/**
* Constructor of this TestCase
* @param name a <code>String</code> value
*/
public ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity
(String name) {
super (name);
}
/**
* Construct this test suit.
* @return a <code>Test</code> value
*/
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest
(new ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity
("importProcessDefinitions"));
suite.addTest
(new ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity
("checkP0T5T5"));
suite.addTest
(new ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity
("checkP1T6T8"));
suite.addTest
(new ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity
("checkP0T7T7"));
suite.addTest
(new ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity
("checkP0T349Tnothing"));
return new EJBClientTest (plc, suite);
}
/**
* Initialisation.
* The <code>setUp</code> method defines the way a state change is
* realized. Override this method to change this way.
* @exception Exception if an error occurs
*/
protected void setUp() throws Exception {
xpdlFile = "/process/systestproc4.xml";
super.setUp();
}
/**
* The engine set the state of a subflow process to closed.aborted. Check
* state of all the included activities of this subflow process.
* @exception Exception if an error occurs
*/
public void checkP0T5T5() throws Exception {
// create the process
SmartWfProcess process = createProcess("st-process4", "P0");
assertState(process, NOT_STARTED);
process.start();
assertState(process, RUNNING);
Thread.sleep(1000);
Iterator activitiesIt = process.steps().iterator();
while (activitiesIt.hasNext()) {
SmartWfActivity activity = (SmartWfActivity)activitiesIt.next();
if (activity.name().equals("A0.1SAA")) {
assertState(activity, RUNNING);
Iterator performersIt = activity.performers().iterator();
SmartWfProcess subFlowProcess
= (SmartWfProcess)performersIt.next();
subFlowProcess.setupWaitForState(SUSPENDED);
subFlowProcess.suspend();
subFlowProcess.waitForState();
assertState(subFlowProcess, SUSPENDED);
// abort subflow process, and the activity will be aborted.
activity.setupWaitForState(ABORTED);
subFlowProcess.setupWaitForState (ABORTED);
subFlowProcess.abort();
activity.waitForState();
subFlowProcess.waitForState();
assertState(subFlowProcess, ABORTED);
assertState(activity, ABORTED);
}
}
}
/**
* The engine starts a process. It runs automatically. At the end the state
* of a activity must be terminated. The same is for its implemented
* subflow.
* @exception Exception if an error occurs
*/
public void checkP1T6T8() throws Exception {
// create the process
SmartWfProcess process = createProcess("st-process4", "P1");
assertState(process, NOT_STARTED);
process.start();
assertState(process, RUNNING);
Iterator activitiesIt = process.steps().iterator();
while (activitiesIt.hasNext()) {
SmartWfActivity activity = (SmartWfActivity)activitiesIt.next();
if (activity.name().equals("A1.1SAA")) {
Thread.sleep(1000);
Iterator performersIt = activity.performers().iterator();
SmartWfProcess subFlowProcess
= (SmartWfProcess)performersIt.next();
if (!subFlowProcess.hasState(COMPLETED)) {
subFlowProcess.setupWaitForState (COMPLETED);
subFlowProcess.waitForState();
assertState(subFlowProcess, COMPLETED);
}
if (!activity.hasState(COMPLETED)) {
activity.setupWaitForState (COMPLETED);
activity.waitForState();
assertState(activity, COMPLETED);
}
}
}
if (!process.hasState(COMPLETED)) {
process.setupWaitForState (COMPLETED);
process.waitForState();
assertState(process, COMPLETED);
}
}
/**
* The engine set the state of a subflow process to terminated. Check
* state of the calling activity. It should be terminated.
* @exception Exception if an error occurs
*/
public void checkP0T7T7() throws Exception {
// create the process
SmartWfProcess process = createProcess("st-process4", "P0");
assertState(process, NOT_STARTED);
process.start();
assertState(process, RUNNING);
Iterator activitiesIt = process.steps().iterator();
while (activitiesIt.hasNext()) {
SmartWfActivity activity = (SmartWfActivity)activitiesIt.next();
if (activity.name().equals("A0.1SAA")) {
assertState(activity, RUNNING);
Thread.sleep(1000);
Iterator performersIt = activity.performers().iterator();
SmartWfProcess subFlowProcess
= (SmartWfProcess)performersIt.next();
assertState(subFlowProcess, RUNNING);
activity.setupWaitForState (TERMINATED);
// terminate the SubFlowProcess
subFlowProcess.setupWaitForState (TERMINATED);
subFlowProcess.terminate();
subFlowProcess.waitForState();
assertState(subFlowProcess, TERMINATED);
activity.waitForState();
assertState(activity, TERMINATED);
}
}
}
/**
* The state of the activity calling subflow is unchanged after the engine
* set the state of a subflow process from suspended to running, from
* running to suspended or from suspended to suspended.
* @exception Exception if an error occurs
*/
public void checkP0T349Tnothing() throws Exception {
// create the process
SmartWfProcess process = createProcess("st-process4", "P0");
assertState(process, NOT_STARTED);
process.start();
assertState(process, RUNNING);
Thread.sleep(1000);
Iterator activitiesIt = process.steps().iterator();
while (activitiesIt.hasNext()) {
SmartWfActivity activity = (SmartWfActivity)activitiesIt.next();
if (activity.name().equals("A0.1SAA")) {
assertState(activity, RUNNING);
Thread.sleep(1000);
Iterator performersIt = activity.performers().iterator();
SmartWfProcess subFlowProcess
= (SmartWfProcess)performersIt.next();
assertState(subFlowProcess, RUNNING);
// suspend the SubFlowProcess(transition 4)
subFlowProcess.setupWaitForState (SUSPENDED);
subFlowProcess.suspend();
subFlowProcess.waitForState();
assertState(subFlowProcess, SUSPENDED);
// state of the activity not changed.
assertState(activity, RUNNING);
// resume the SubFlowProcess(transition 3)
subFlowProcess.setupWaitForState (RUNNING);
subFlowProcess.resume();
subFlowProcess.waitForState();
assertState(subFlowProcess, RUNNING);
// state of the activity not changed.
assertState(activity, RUNNING);
// suspend the SubFlowProcess(transition 9)
subFlowProcess.setupWaitForState (SUSPENDED);
subFlowProcess.suspend();
subFlowProcess.waitForState();
assertState(subFlowProcess, SUSPENDED);
// state of the activity not changed.
assertState(activity, RUNNING);
}
}
}
}