001: package process;
002:
003: import java.util.Iterator;
004:
005: import junit.framework.Test;
006: import junit.framework.TestSuite;
007: import de.danet.an.util.junit.EJBClientTest;
008:
009: /**
010: * Describe class
011: * <code>ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity</code> here.
012: *
013: * @author mao
014: * @version 1.0
015: */
016: public class ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity
017: extends WfMOpenTestCase {
018: /**
019: * Constructor of this TestCase
020: * @param name a <code>String</code> value
021: */
022: public ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity(
023: String name) {
024: super (name);
025: }
026:
027: /**
028: * Construct this test suit.
029: * @return a <code>Test</code> value
030: */
031: public static Test suite() {
032: TestSuite suite = new TestSuite();
033: suite
034: .addTest(new ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity(
035: "importProcessDefinitions"));
036: suite
037: .addTest(new ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity(
038: "checkP0T5T5"));
039: suite
040: .addTest(new ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity(
041: "checkP1T6T8"));
042: suite
043: .addTest(new ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity(
044: "checkP0T7T7"));
045: suite
046: .addTest(new ProcLifeCycleEngineTriggeredSubProcessTriggeringActivity(
047: "checkP0T349Tnothing"));
048: return new EJBClientTest(plc, suite);
049: }
050:
051: /**
052: * Initialisation.
053: * The <code>setUp</code> method defines the way a state change is
054: * realized. Override this method to change this way.
055: * @exception Exception if an error occurs
056: */
057: protected void setUp() throws Exception {
058: xpdlFile = "/process/systestproc4.xml";
059: super .setUp();
060: }
061:
062: /**
063: * The engine set the state of a subflow process to closed.aborted. Check
064: * state of all the included activities of this subflow process.
065: * @exception Exception if an error occurs
066: */
067: public void checkP0T5T5() throws Exception {
068: // create the process
069: SmartWfProcess process = createProcess("st-process4", "P0");
070: assertState(process, NOT_STARTED);
071: process.start();
072: assertState(process, RUNNING);
073: Thread.sleep(1000);
074:
075: Iterator activitiesIt = process.steps().iterator();
076: while (activitiesIt.hasNext()) {
077: SmartWfActivity activity = (SmartWfActivity) activitiesIt
078: .next();
079: if (activity.name().equals("A0.1SAA")) {
080: assertState(activity, RUNNING);
081: Iterator performersIt = activity.performers()
082: .iterator();
083: SmartWfProcess subFlowProcess = (SmartWfProcess) performersIt
084: .next();
085: subFlowProcess.setupWaitForState(SUSPENDED);
086: subFlowProcess.suspend();
087: subFlowProcess.waitForState();
088: assertState(subFlowProcess, SUSPENDED);
089: // abort subflow process, and the activity will be aborted.
090: activity.setupWaitForState(ABORTED);
091: subFlowProcess.setupWaitForState(ABORTED);
092: subFlowProcess.abort();
093: activity.waitForState();
094: subFlowProcess.waitForState();
095: assertState(subFlowProcess, ABORTED);
096: assertState(activity, ABORTED);
097: }
098: }
099: }
100:
101: /**
102: * The engine starts a process. It runs automatically. At the end the state
103: * of a activity must be terminated. The same is for its implemented
104: * subflow.
105: * @exception Exception if an error occurs
106: */
107: public void checkP1T6T8() throws Exception {
108: // create the process
109: SmartWfProcess process = createProcess("st-process4", "P1");
110: assertState(process, NOT_STARTED);
111: process.start();
112: assertState(process, RUNNING);
113:
114: Iterator activitiesIt = process.steps().iterator();
115: while (activitiesIt.hasNext()) {
116: SmartWfActivity activity = (SmartWfActivity) activitiesIt
117: .next();
118: if (activity.name().equals("A1.1SAA")) {
119: Thread.sleep(1000);
120: Iterator performersIt = activity.performers()
121: .iterator();
122: SmartWfProcess subFlowProcess = (SmartWfProcess) performersIt
123: .next();
124: if (!subFlowProcess.hasState(COMPLETED)) {
125: subFlowProcess.setupWaitForState(COMPLETED);
126: subFlowProcess.waitForState();
127: assertState(subFlowProcess, COMPLETED);
128: }
129: if (!activity.hasState(COMPLETED)) {
130: activity.setupWaitForState(COMPLETED);
131: activity.waitForState();
132: assertState(activity, COMPLETED);
133: }
134: }
135: }
136: if (!process.hasState(COMPLETED)) {
137: process.setupWaitForState(COMPLETED);
138: process.waitForState();
139: assertState(process, COMPLETED);
140: }
141: }
142:
143: /**
144: * The engine set the state of a subflow process to terminated. Check
145: * state of the calling activity. It should be terminated.
146: * @exception Exception if an error occurs
147: */
148: public void checkP0T7T7() throws Exception {
149: // create the process
150: SmartWfProcess process = createProcess("st-process4", "P0");
151: assertState(process, NOT_STARTED);
152: process.start();
153: assertState(process, RUNNING);
154:
155: Iterator activitiesIt = process.steps().iterator();
156: while (activitiesIt.hasNext()) {
157: SmartWfActivity activity = (SmartWfActivity) activitiesIt
158: .next();
159: if (activity.name().equals("A0.1SAA")) {
160: assertState(activity, RUNNING);
161: Thread.sleep(1000);
162: Iterator performersIt = activity.performers()
163: .iterator();
164: SmartWfProcess subFlowProcess = (SmartWfProcess) performersIt
165: .next();
166: assertState(subFlowProcess, RUNNING);
167: activity.setupWaitForState(TERMINATED);
168: // terminate the SubFlowProcess
169: subFlowProcess.setupWaitForState(TERMINATED);
170: subFlowProcess.terminate();
171: subFlowProcess.waitForState();
172: assertState(subFlowProcess, TERMINATED);
173: activity.waitForState();
174: assertState(activity, TERMINATED);
175: }
176: }
177: }
178:
179: /**
180: * The state of the activity calling subflow is unchanged after the engine
181: * set the state of a subflow process from suspended to running, from
182: * running to suspended or from suspended to suspended.
183: * @exception Exception if an error occurs
184: */
185: public void checkP0T349Tnothing() throws Exception {
186: // create the process
187: SmartWfProcess process = createProcess("st-process4", "P0");
188: assertState(process, NOT_STARTED);
189: process.start();
190: assertState(process, RUNNING);
191: Thread.sleep(1000);
192:
193: Iterator activitiesIt = process.steps().iterator();
194: while (activitiesIt.hasNext()) {
195: SmartWfActivity activity = (SmartWfActivity) activitiesIt
196: .next();
197: if (activity.name().equals("A0.1SAA")) {
198: assertState(activity, RUNNING);
199: Thread.sleep(1000);
200: Iterator performersIt = activity.performers()
201: .iterator();
202: SmartWfProcess subFlowProcess = (SmartWfProcess) performersIt
203: .next();
204: assertState(subFlowProcess, RUNNING);
205: // suspend the SubFlowProcess(transition 4)
206: subFlowProcess.setupWaitForState(SUSPENDED);
207: subFlowProcess.suspend();
208: subFlowProcess.waitForState();
209: assertState(subFlowProcess, SUSPENDED);
210: // state of the activity not changed.
211: assertState(activity, RUNNING);
212: // resume the SubFlowProcess(transition 3)
213: subFlowProcess.setupWaitForState(RUNNING);
214: subFlowProcess.resume();
215: subFlowProcess.waitForState();
216: assertState(subFlowProcess, RUNNING);
217: // state of the activity not changed.
218: assertState(activity, RUNNING);
219: // suspend the SubFlowProcess(transition 9)
220: subFlowProcess.setupWaitForState(SUSPENDED);
221: subFlowProcess.suspend();
222: subFlowProcess.waitForState();
223: assertState(subFlowProcess, SUSPENDED);
224: // state of the activity not changed.
225: assertState(activity, RUNNING);
226: }
227: }
228: }
229: }
|