001: package process;
002:
003: import java.util.Collection;
004: import java.util.Iterator;
005:
006: import junit.framework.Test;
007: import junit.framework.TestSuite;
008:
009: import de.danet.an.util.junit.EJBClientTest;
010:
011: /**
012: * Test the transitions of different activities and processes.
013: * The transitions are triggered by the engine.
014: * @author <a href="mailto:weidauer@danet.de">Christian Weidauer</a>
015: * @version 1.0
016: */
017: public class ProcLifeCycleEngineTriggeredActivityTriggeringParentProcess
018: extends WfMOpenTestCase {
019:
020: /**
021: * Constructor of this TestCase
022: * @param name a <code>String</code> value
023: */
024: public ProcLifeCycleEngineTriggeredActivityTriggeringParentProcess(
025: String name) {
026: super (name);
027: }
028:
029: /**
030: * Construct this test suite.
031: * @return a <code>Test</code> value
032: */
033: public static Test suite() {
034: TestSuite suite = new TestSuite();
035: suite
036: .addTest(new ProcLifeCycleEngineTriggeredActivityTriggeringParentProcess(
037: "importProcessDefinitions"));
038: suite
039: .addTest(new ProcLifeCycleEngineTriggeredActivityTriggeringParentProcess(
040: "checkP1T6T7"));
041: suite
042: .addTest(new ProcLifeCycleEngineTriggeredActivityTriggeringParentProcess(
043: "checkP4T6T6"));
044: suite
045: .addTest(new ProcLifeCycleEngineTriggeredActivityTriggeringParentProcess(
046: "checkP1T7T7"));
047: return new EJBClientTest(plc, suite);
048: }
049:
050: /**
051: * Initialisation.
052: * The <code>setUp</code> method defines the way a state change is
053: * realized. Override this method to change this way.
054: * @exception Exception if an error occurs
055: */
056: protected void setUp() throws Exception {
057: xpdlFile = "/process/systestproc2.xml";
058: super .setUp();
059: }
060:
061: //checkPxT5T4 already checked by checkP0T4T257 in parentProcess->activities
062:
063: /**
064: * Test a simple process definition. The process is terminated without
065: * being started.
066: * @exception Exception if an error occurs
067: */
068: public void checkP1T6T7() throws Exception {
069: // create the process
070: SmartWfProcess process = createProcess("st-process2", "P1");
071: assertState(process, NOT_STARTED);
072: Collection c = process.steps();
073: Iterator it = c.iterator();
074:
075: SmartWfActivity aCompleting = null;
076: SmartWfActivity aTerminatedWhenCompleting = (SmartWfActivity) it
077: .next();
078: ActivityNameAnalyser ana = new ActivityNameAnalyser(
079: aTerminatedWhenCompleting.name());
080: if (ana.number().equals("1.1")) {
081: aCompleting = (SmartWfActivity) it.next();
082: } else {
083: aCompleting = aTerminatedWhenCompleting;
084: aTerminatedWhenCompleting = (SmartWfActivity) it.next();
085: }
086:
087: process.setupWaitForState(RUNNING);
088: aTerminatedWhenCompleting.setupWaitForState(RUNNING);
089: aCompleting.setupWaitForState(RUNNING);
090: process.start();
091: process.waitForState();
092: assertState(process, RUNNING);
093: process.setupWaitForState(TERMINATED);
094:
095: aTerminatedWhenCompleting.waitForState();
096: aCompleting.waitForState();
097: aCompleting.setupWaitForState(COMPLETED);
098:
099: aTerminatedWhenCompleting.setupWaitForState(TERMINATED);
100: aTerminatedWhenCompleting.terminate();
101: aTerminatedWhenCompleting.waitForState();
102: assertState(aTerminatedWhenCompleting, TERMINATED);
103: assertState(aCompleting, RUNNING);
104: assertState(process, RUNNING);
105: //last activity (6) -> parent process (7)
106: aCompleting.waitForState();
107: assertState(aCompleting, COMPLETED);
108: process.waitForState();
109: assertState(process, TERMINATED);
110:
111: removeProcess(process);
112: }
113:
114: /**
115: * Test a simple process definition. The process is terminated without
116: * being started.
117: * @exception Exception if an error occurs
118: */
119: public void checkP1T7T7() throws Exception {
120: // create the process
121: SmartWfProcess process = createProcess("st-process2", "P1");
122: assertState(process, NOT_STARTED);
123: Collection c = process.steps();
124: Iterator it = c.iterator();
125:
126: SmartWfActivity aTerminating = (SmartWfActivity) it.next();
127: SmartWfActivity aCompletedWhenTerminating = null;
128: ActivityNameAnalyser ana = new ActivityNameAnalyser(
129: aTerminating.name());
130: if (ana.number().equals("1.1")) {
131: aCompletedWhenTerminating = (SmartWfActivity) it.next();
132: } else {
133: aCompletedWhenTerminating = aTerminating;
134: aTerminating = (SmartWfActivity) it.next();
135: }
136:
137: process.setupWaitForState(RUNNING);
138: aCompletedWhenTerminating.setupWaitForState(COMPLETED);
139: aTerminating.setupWaitForState(RUNNING);
140: process.start();
141: process.waitForState();
142: assertState(process, RUNNING);
143:
144: aCompletedWhenTerminating.waitForState();
145: aTerminating.waitForState();
146: assertState(aTerminating, RUNNING);
147: //last activity (7) -> parent process (7)
148: aTerminating.setupWaitForState(TERMINATED);
149: aTerminating.terminate();
150: aTerminating.waitForState();
151: assertState(aTerminating, TERMINATED);
152: assertState(process, TERMINATED);
153:
154: removeProcess(process);
155: }
156:
157: /**
158: * Test a simple process definition. The process is terminated without
159: * being started.
160: * @exception Exception if an error occurs
161: */
162: public void checkP4T6T6() throws Exception {
163: // create the process
164: SmartWfProcess process = createProcess("st-process2", "P4");
165: assertState(process, NOT_STARTED);
166: Collection c = process.steps();
167: Iterator it = c.iterator();
168:
169: SmartWfActivity aCompleting = null;
170: SmartWfActivity aCompletedWhenCompleting = (SmartWfActivity) it
171: .next();
172: ActivityNameAnalyser ana = new ActivityNameAnalyser(
173: aCompletedWhenCompleting.name());
174: if (ana.number().equals("4.1")) {
175: aCompleting = (SmartWfActivity) it.next();
176: } else {
177: aCompleting = aCompletedWhenCompleting;
178: aCompletedWhenCompleting = (SmartWfActivity) it.next();
179: }
180:
181: process.setupWaitForState(RUNNING);
182: aCompletedWhenCompleting.setupWaitForState(COMPLETED);
183: aCompleting.setupWaitForState(RUNNING);
184: process.start();
185: assertState(process, RUNNING);
186: process.waitForState();
187: process.setupWaitForState(COMPLETED);
188:
189: aCompletedWhenCompleting.waitForState();
190: aCompleting.waitForState();
191: assertState(aCompleting, RUNNING);
192: assertState(process, RUNNING);
193: aCompleting.setupWaitForState(COMPLETED);
194: //last activity (6) -> parent process (6)
195: aCompleting.waitForState();
196: assertState(aCompleting, COMPLETED);
197: process.waitForState();
198: assertState(process, COMPLETED);
199:
200: removeProcess(process);
201: }
202: }
|