001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity.java,v 1.3 2007/03/27 21:59:43 mlipp Exp $
021: *
022: * $Log: ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity.java,v $
023: * Revision 1.3 2007/03/27 21:59:43 mlipp
024: * Fixed lots of checkstyle warnings.
025: *
026: * Revision 1.2 2006/09/29 12:32:07 drmlipp
027: * Consistently using WfMOpen as projct name now.
028: *
029: * Revision 1.1.1.2 2003/12/19 13:01:43 drmlipp
030: * Updated to 1.1rc1
031: *
032: * Revision 1.19 2003/12/16 21:55:11 lipp
033: * Fixed test.
034: *
035: * Revision 1.18 2003/10/21 21:00:45 lipp
036: * Moved EJBClientTest to new junit sub-package.
037: *
038: * Revision 1.17 2003/10/08 12:39:40 huaiyang
039: * make test weblogic compatible.
040: *
041: * Revision 1.16 2003/06/27 09:44:03 lipp
042: * Fixed copyright/license information.
043: *
044: * Revision 1.15 2003/05/13 13:16:45 weidauer
045: * adapted test cases to current state transition table
046: *
047: * Revision 1.14 2003/04/26 16:12:22 lipp
048: * Moved some classes to reduce package dependencies.
049: *
050: * Revision 1.13 2003/04/16 19:58:49 lipp
051: * Adapted to jdk 1.4
052: *
053: * Revision 1.12 2003/02/25 17:08:18 lipp
054: * Reorganized requester implementation.
055: *
056: * Revision 1.11 2003/02/14 14:02:41 lipp
057: * Added missing catches for direct state setting.
058: *
059: * Revision 1.10 2003/02/14 10:07:53 lipp
060: * Fixed test case.
061: *
062: * Revision 1.9 2003/02/12 16:14:43 lipp
063: * Delays now based on events.
064: *
065: * Revision 1.8 2003/02/05 15:57:06 lipp
066: * Replaced DummyRequester with DefaultRequester.
067: *
068: * Revision 1.7 2002/12/06 12:39:46 weidauer
069: * for an aborted process it can only be asserted that its activities are not running anymore.
070: *
071: * Revision 1.6 2002/12/05 16:30:47 weidauer
072: * a suspended activity cannot be terminated anymore be terminating process
073: *
074: * Revision 1.5 2002/11/26 17:24:55 weidauer
075: * added test for suspended activity triggered by terminating parent process.
076: *
077: * Revision 1.4 2002/11/25 17:22:42 weidauer
078: * refactored with WfMOpenTestCase as base test case and cleaned up classes
079: *
080: * Revision 1.3 2002/11/25 15:19:02 weidauer
081: * modified totally to SmartWfExecutionObjects
082: *
083: * Revision 1.2 2002/11/21 16:24:51 weidauer
084: * added smart handling of WfExecutionObjects
085: *
086: * Revision 1.1 2002/11/21 14:09:53 weidauer
087: * modified test structure
088: *
089: * Revision 1.2 2002/11/08 13:15:18 weidauer
090: * improved engine triggered test cases
091: *
092: * Revision 1.1 2002/11/05 17:02:25 weidauer
093: * initial version
094: *
095: * Revision 1.2 2002/11/01 14:49:22 weidauer
096: * trouble maker
097: *
098: * Revision 1.1 2002/10/31 17:36:12 weidauer
099: * initial system test
100: *
101: */
102: package process;
103:
104: import java.util.Collection;
105: import java.util.Iterator;
106:
107: import junit.framework.Test;
108: import junit.framework.TestSuite;
109: import de.danet.an.workflow.omgcore.CannotStopException;
110: import de.danet.an.workflow.omgcore.TransitionNotAllowedException;
111: import de.danet.an.util.junit.EJBClientTest;
112:
113: /**
114: * Test the transitions of different activities and processes.
115: * The transisitions are triggered by the engine.
116: * @author <a href="mailto:weidauer@danet.de">Christian Weidauer</a>
117: * @version 1.0
118: */
119: public class ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity
120: extends WfMOpenTestCase {
121:
122: /**
123: * Constructor of this TestCase
124: * @param name a <code>String</code> value
125: */
126: public ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity(
127: String name) {
128: super (name);
129: }
130:
131: /**
132: * Construct this test suite.
133: * @return a <code>Test</code> value
134: */
135: public static Test suite() {
136: TestSuite suite = new TestSuite();
137: suite
138: .addTest(new ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity(
139: "importProcessDefinitions"));
140: suite
141: .addTest(new ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity(
142: "checkP0T2TNothing"));
143: suite
144: .addTest(new ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity(
145: "checkP0T4T57"));
146: suite
147: .addTest(new ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity(
148: "checkP2T5T57"));
149: suite
150: .addTest(new ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity(
151: "checkP0T7T7"));
152: suite
153: .addTest(new ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity(
154: "checkExceptionP1T7T7"));
155: return new EJBClientTest(plc, suite);
156: }
157:
158: /**
159: * Initialisation.
160: * The <code>setUp</code> method defines the way a state change is
161: * realized. Override this method to change this way.
162: * @exception Exception if an error occurs
163: */
164: protected void setUp() throws Exception {
165: xpdlFile = "/process/systestproc2.xml";
166: super .setUp();
167: }
168:
169: /**
170: * Test a simple process definition. The process is terminated without
171: * being started.
172: * @exception Exception if an error occurs
173: */
174: public void checkP0T2TNothing() throws Exception {
175: // create the process
176: SmartWfProcess process = createProcess("st-process2", "P0");
177: assertState(process, NOT_STARTED);
178: Collection c = process.steps();
179: Iterator it = c.iterator();
180: SmartWfActivity a = (SmartWfActivity) it.next();
181: assertState(a, NOT_STARTED);
182:
183: // terminate the process (2)-> activitiy(2)
184: process.setupWaitForState(TERMINATED);
185: process.terminate();
186: process.waitForState();
187: assertState(process, TERMINATED);
188: assertState(a, NOT_STARTED);
189:
190: removeProcess(process);
191: }
192:
193: /**
194: * Test a simple process definition. The process is aborted.
195: * @exception Exception if an error occurs
196: */
197: public void checkP0T4T57() throws Exception {
198: // create the process
199: SmartWfProcess process = createProcess("st-process2", "P0");
200: assertState(process, NOT_STARTED);
201:
202: // start the process (1)-> activitiy(1)
203: process.setupWaitForState(RUNNING);
204: process.start();
205: process.waitForState();
206: assertState(process, RUNNING);
207: process.setupWaitForState(ABORTED);
208:
209: Collection cRunning = process.activitiesInState(RUNNING);
210: Iterator it = cRunning.iterator();
211: SmartWfActivity aAbortedWhenAborting = (SmartWfActivity) it
212: .next();
213: SmartWfActivity aRunningWhenAborting = (SmartWfActivity) it
214: .next();
215: SmartWfActivity aSuspendedWhenAborting = (SmartWfActivity) it
216: .next();
217: assertTrue(aSuspendedWhenAborting != null);
218: assertState(aSuspendedWhenAborting, RUNNING);
219: Collection cNotRunning = process.activitiesInState(NOT_STARTED);
220: it = cNotRunning.iterator();
221: SmartWfActivity aNotStartedWhenAborting = (SmartWfActivity) it
222: .next();
223: assertTrue(aNotStartedWhenAborting != null);
224:
225: aSuspendedWhenAborting.suspend();
226: assertState(aSuspendedWhenAborting, SUSPENDED);
227: aAbortedWhenAborting.suspend();
228: assertState(aAbortedWhenAborting, SUSPENDED);
229: // abort activity causing process (4)-> activities(5, 7), process(5)
230: aAbortedWhenAborting.abort();
231: assertState(aAbortedWhenAborting, ABORTED);
232: process.waitForState();
233: assertState(process, ABORTED);
234: assertTrue(!aRunningWhenAborting.hasState(RUNNING));
235: assertTrue(!aSuspendedWhenAborting.hasState(RUNNING));
236: assertTrue(!aNotStartedWhenAborting.hasState(RUNNING));
237:
238: removeProcess(process);
239: }
240:
241: /**
242: * Test a simple process definition. The process is aborted.
243: * @exception Exception if an error occurs
244: */
245: public void checkP2T5T57() throws Exception {
246: // create the process
247: SmartWfProcess process = createProcess("st-process2", "P2");
248: assertState(process, NOT_STARTED);
249:
250: // start the process (1)-> activitiy(1)
251: process.setupWaitForState(RUNNING);
252: process.start();
253: process.waitForState();
254: assertState(process, RUNNING);
255:
256: Collection cRunning = process.activitiesInState(RUNNING);
257: Iterator it = cRunning.iterator();
258: ActivityNameAnalyser ana;
259: SmartWfActivity aNotStopableRunningWhenAborting = null;
260: SmartWfActivity aRunningWhenAborting = (SmartWfActivity) it
261: .next();
262: ana = new ActivityNameAnalyser(aRunningWhenAborting.name());
263: // activity 2.4 is implemented as JSExecutor and therefore cannot be
264: // terminated
265: if (ana.number().equals("2.4")) {
266: aNotStopableRunningWhenAborting = aRunningWhenAborting;
267: aRunningWhenAborting = (SmartWfActivity) it.next();
268: }
269: SmartWfActivity aSuspendedWhenAborting = (SmartWfActivity) it
270: .next();
271: ana = new ActivityNameAnalyser(aSuspendedWhenAborting.name());
272: if (ana.number().equals("2.4")) {
273: aNotStopableRunningWhenAborting = aSuspendedWhenAborting;
274: aSuspendedWhenAborting = (SmartWfActivity) it.next();
275: }
276: if (aNotStopableRunningWhenAborting == null) {
277: aNotStopableRunningWhenAborting = (SmartWfActivity) it
278: .next();
279: }
280: assertTrue(aSuspendedWhenAborting != null);
281: assertState(aSuspendedWhenAborting, RUNNING);
282: Collection cNotRunning = process.activitiesInState(NOT_STARTED);
283: it = cNotRunning.iterator();
284: SmartWfActivity aNotStartedWhenAborting = (SmartWfActivity) it
285: .next();
286: assertTrue(aNotStartedWhenAborting != null);
287:
288: // suspend the process (4)-> activities(-)
289: process.suspend();
290: assertState(process, SUSPENDED);
291: assertState(aSuspendedWhenAborting, RUNNING);
292: aSuspendedWhenAborting.suspend();
293: assertState(aSuspendedWhenAborting, SUSPENDED);
294:
295: // abort the process (5)-> activities(5, 7)
296: process.abort();
297: assertState(process, ABORTED);
298: assertState(aRunningWhenAborting, TERMINATED);
299: assertState(aSuspendedWhenAborting, ABORTED);
300: assertState(aNotStartedWhenAborting, NOT_STARTED);
301: assertState(aNotStopableRunningWhenAborting, ABORTED);
302:
303: removeProcess(process);
304: }
305:
306: /**
307: * Test a simple process definition. The process is terminated.
308: * @exception Exception if an error occurs
309: */
310: public void checkP0T7T7() throws Exception {
311: // create the process
312: SmartWfProcess process = createProcess("st-process2", "P0");
313: assertState(process, NOT_STARTED);
314:
315: // start the process (1)-> activitiy(1)
316: process.setupWaitForState(RUNNING);
317: process.start();
318: assertState(process, RUNNING);
319: process.waitForState();
320:
321: Collection cRunning = process.activitiesInState(RUNNING);
322: Iterator it = cRunning.iterator();
323: SmartWfActivity aRunningWhenTerminated = (SmartWfActivity) it
324: .next();
325: assertTrue(aRunningWhenTerminated != null);
326: assertState(aRunningWhenTerminated, RUNNING);
327:
328: SmartWfActivity aSuspendedWhenTerminated = (SmartWfActivity) it
329: .next();
330: assertTrue(aSuspendedWhenTerminated != null);
331: assertState(aSuspendedWhenTerminated, RUNNING);
332:
333: Collection cNotRunning = process.activitiesInState(NOT_STARTED);
334: it = cNotRunning.iterator();
335: SmartWfActivity aNotStartedWhenTerminated = (SmartWfActivity) it
336: .next();
337: assertTrue(aNotStartedWhenTerminated != null);
338:
339: Collection cNotTerminateable = process
340: .activitiesInState(SUSPENDED);
341: it = cNotTerminateable.iterator();
342: SmartWfActivity aNotTerminateableWhenTerminated = (SmartWfActivity) it
343: .next();
344: assertTrue(aNotTerminateableWhenTerminated != null);
345:
346: // suspend the process (4)-> activitiy(-)
347: process.setupWaitForState(SUSPENDED);
348: process.suspend();
349: assertState(process, SUSPENDED);
350: process.waitForState();
351: assertState(process, SUSPENDED);
352: assertState(aRunningWhenTerminated, RUNNING);
353:
354: // resume the process (3)-> activitiy(-)
355: process.setupWaitForState(RUNNING);
356: process.resume();
357: assertState(process, RUNNING);
358: process.waitForState();
359: assertState(process, RUNNING);
360: assertState(aRunningWhenTerminated, RUNNING);
361:
362: aSuspendedWhenTerminated.setupWaitForState(SUSPENDED);
363: aSuspendedWhenTerminated.suspend();
364: aSuspendedWhenTerminated.waitForState();
365: // try to terminate the process (try 7)-> activitiy(7) a suspended
366: // activity stays suspended :: Throw CannotStopException
367: boolean exceptionCaught = false;
368: try {
369: process.terminate();
370: } catch (CannotStopException ex) {
371: exceptionCaught = true;
372: } catch (TransitionNotAllowedException ex) {
373: exceptionCaught = true;
374: }
375: assertTrue(exceptionCaught);
376: assertState(process, RUNNING);
377: assertState(aRunningWhenTerminated, RUNNING);
378: assertState(aNotStartedWhenTerminated, NOT_STARTED);
379: assertState(aSuspendedWhenTerminated, SUSPENDED);
380: assertState(aNotTerminateableWhenTerminated, SUSPENDED);
381:
382: aSuspendedWhenTerminated.setupWaitForState(RUNNING);
383: aSuspendedWhenTerminated.resume();
384: aSuspendedWhenTerminated.waitForState();
385: aNotTerminateableWhenTerminated.setupWaitForState(RUNNING);
386: aNotTerminateableWhenTerminated.resume();
387: aNotTerminateableWhenTerminated.waitForState();
388: Thread.sleep(500);//wait for started JSExecutor tool
389: // no suspended activity but not terminateable activity
390: // terminate the process (try 7)-> terminateable activitiy(7)and
391: // running not terminateable activity stays running
392: aRunningWhenTerminated.setupWaitForState(TERMINATED);
393: aSuspendedWhenTerminated.setupWaitForState(TERMINATED);
394: exceptionCaught = false;
395: try {
396: process.terminate();
397: } catch (CannotStopException ex) {
398: exceptionCaught = true;
399: } catch (TransitionNotAllowedException ex) {
400: exceptionCaught = true;
401: }
402: assertTrue(exceptionCaught);
403:
404: //all terminateable activities are terminated
405: aRunningWhenTerminated.waitForState();
406: assertState(aRunningWhenTerminated, TERMINATED);
407: assertState(aNotStartedWhenTerminated, NOT_STARTED);
408: aSuspendedWhenTerminated.waitForState();
409: assertState(aSuspendedWhenTerminated, TERMINATED);
410: assertState(aNotTerminateableWhenTerminated, RUNNING);
411: assertState(process, RUNNING);
412:
413: Thread.sleep(2000); //wait for started Webform tool
414: assertState(aNotTerminateableWhenTerminated, RUNNING);
415:
416: //now all activities (only one) are running and terminateable
417: process.setupWaitForState(TERMINATED);
418: aNotTerminateableWhenTerminated.setupWaitForState(TERMINATED);
419: process.terminate();
420: aNotTerminateableWhenTerminated.waitForState();
421: assertState(aNotTerminateableWhenTerminated, TERMINATED);
422: process.waitForState();
423: assertState(process, TERMINATED);
424:
425: removeProcess(process);
426: }
427:
428: /**
429: * Test a simple process definition. The process is aborted. But one
430: * activity cannot be terminated because it is implemented as JSExecutor
431: * tool. An Exception has to be thrown.
432: * @exception Exception if an error occurs
433: */
434: public void checkExceptionP1T7T7() throws Exception {
435: // create the process
436: SmartWfProcess process = createProcess("st-process2", "P1");
437: assertState(process, NOT_STARTED);
438:
439: Collection activities = process.steps();
440: Iterator it = activities.iterator();
441:
442: SmartWfActivity activity = (SmartWfActivity) it.next();
443: SmartWfActivity stopableActivity;
444: SmartWfActivity notStopableActivity;
445: if ((new ActivityNameAnalyser(activity.name())).number()
446: .equals("1.1")) { // activity 1.1 is a webform tool
447: stopableActivity = activity; // Webform tool
448: notStopableActivity = (SmartWfActivity) it.next(); //JSExecutor tool
449: } else {
450: notStopableActivity = activity; // JSExecutor tool
451: stopableActivity = (SmartWfActivity) it.next(); // Webform tool
452: }
453:
454: // start the process (1)-> activities(1)
455: process.setupWaitForState(RUNNING);
456: notStopableActivity.setupWaitForState(RUNNING);
457: stopableActivity.setupWaitForState(RUNNING);
458: process.start();
459: assertState(process, RUNNING);
460: process.waitForState();
461: assertState(process, RUNNING);
462:
463: notStopableActivity.waitForState();
464: assertState(notStopableActivity, RUNNING);
465: stopableActivity.waitForState();
466: assertState(stopableActivity, RUNNING);
467:
468: // to terminate process
469: process.setupWaitForState(TERMINATED);
470: boolean exceptionCaught = false;
471: try {
472: process.terminate();
473: } catch (CannotStopException e) {
474: exceptionCaught = true;
475: } catch (TransitionNotAllowedException e) {
476: exceptionCaught = true;
477: }
478: assertTrue(exceptionCaught);
479: assertState(process, RUNNING);
480: assertState(notStopableActivity, RUNNING);
481: assertState(stopableActivity, TERMINATED);
482:
483: process.waitForState();
484: assertState(process, TERMINATED);
485:
486: removeProcess(process);
487: }
488: }
|