/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity.java 2326 2007-03-27 21:59:44Z mlipp $
*
* $Log$
* Revision 1.2 2006/09/29 12:32:07 drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.1.1.2 2003/12/19 13:01:43 drmlipp
* Updated to 1.1rc1
*
* Revision 1.19 2003/12/16 21:55:11 lipp
* Fixed test.
*
* Revision 1.18 2003/10/21 21:00:45 lipp
* Moved EJBClientTest to new junit sub-package.
*
* Revision 1.17 2003/10/08 12:39:40 huaiyang
* make test weblogic compatible.
*
* Revision 1.16 2003/06/27 09:44:03 lipp
* Fixed copyright/license information.
*
* Revision 1.15 2003/05/13 13:16:45 weidauer
* adapted test cases to current state transition table
*
* Revision 1.14 2003/04/26 16:12:22 lipp
* Moved some classes to reduce package dependencies.
*
* Revision 1.13 2003/04/16 19:58:49 lipp
* Adapted to jdk 1.4
*
* Revision 1.12 2003/02/25 17:08:18 lipp
* Reorganized requester implementation.
*
* Revision 1.11 2003/02/14 14:02:41 lipp
* Added missing catches for direct state setting.
*
* Revision 1.10 2003/02/14 10:07:53 lipp
* Fixed test case.
*
* Revision 1.9 2003/02/12 16:14:43 lipp
* Delays now based on events.
*
* Revision 1.8 2003/02/05 15:57:06 lipp
* Replaced DummyRequester with DefaultRequester.
*
* Revision 1.7 2002/12/06 12:39:46 weidauer
* for an aborted process it can only be asserted that its activities are not running anymore.
*
* Revision 1.6 2002/12/05 16:30:47 weidauer
* a suspended activity cannot be terminated anymore be terminating process
*
* Revision 1.5 2002/11/26 17:24:55 weidauer
* added test for suspended activity triggered by terminating parent process.
*
* Revision 1.4 2002/11/25 17:22:42 weidauer
* refactored with WfMOpenTestCase as base test case and cleaned up classes
*
* Revision 1.3 2002/11/25 15:19:02 weidauer
* modified totally to SmartWfExecutionObjects
*
* Revision 1.2 2002/11/21 16:24:51 weidauer
* added smart handling of WfExecutionObjects
*
* Revision 1.1 2002/11/21 14:09:53 weidauer
* modified test structure
*
* Revision 1.2 2002/11/08 13:15:18 weidauer
* improved engine triggered test cases
*
* Revision 1.1 2002/11/05 17:02:25 weidauer
* initial version
*
* Revision 1.2 2002/11/01 14:49:22 weidauer
* trouble maker
*
* Revision 1.1 2002/10/31 17:36:12 weidauer
* initial system test
*
*/
package process;
import java.util.Collection;
import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestSuite;
import de.danet.an.workflow.omgcore.CannotStopException;
import de.danet.an.workflow.omgcore.TransitionNotAllowedException;
import de.danet.an.util.junit.EJBClientTest;
/**
* Test the transitions of different activities and processes.
* The transisitions are triggered by the engine.
* @author <a href="mailto:weidauer@danet.de">Christian Weidauer</a>
* @version 1.0
*/
public class ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity
extends WfMOpenTestCase {
/**
* Constructor of this TestCase
* @param name a <code>String</code> value
*/
public ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity
(String name) {
super (name);
}
/**
* Construct this test suite.
* @return a <code>Test</code> value
*/
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new
ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity
("importProcessDefinitions"));
suite.addTest(new
ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity
("checkP0T2TNothing"));
suite.addTest(new
ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity
("checkP0T4T57"));
suite.addTest(new
ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity
("checkP2T5T57"));
suite.addTest(new
ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity
("checkP0T7T7"));
suite.addTest(new
ProcLifeCycleEngineTriggeredParentProcessTriggeringActivity
("checkExceptionP1T7T7"));
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/systestproc2.xml";
super.setUp();
}
/**
* Test a simple process definition. The process is terminated without
* being started.
* @exception Exception if an error occurs
*/
public void checkP0T2TNothing()
throws Exception {
// create the process
SmartWfProcess process = createProcess("st-process2", "P0");
assertState(process, NOT_STARTED);
Collection c = process.steps();
Iterator it = c.iterator();
SmartWfActivity a = (SmartWfActivity)it.next();
assertState(a, NOT_STARTED);
// terminate the process (2)-> activitiy(2)
process.setupWaitForState (TERMINATED);
process.terminate();
process.waitForState();
assertState(process, TERMINATED);
assertState(a, NOT_STARTED);
removeProcess(process);
}
/**
* Test a simple process definition. The process is aborted.
* @exception Exception if an error occurs
*/
public void checkP0T4T57()
throws Exception {
// create the process
SmartWfProcess process = createProcess("st-process2", "P0");
assertState(process, NOT_STARTED);
// start the process (1)-> activitiy(1)
process.setupWaitForState (RUNNING);
process.start();
process.waitForState ();
assertState(process, RUNNING);
process.setupWaitForState (ABORTED);
Collection cRunning = process.activitiesInState(RUNNING);
Iterator it = cRunning.iterator();
SmartWfActivity aAbortedWhenAborting = (SmartWfActivity)it.next();
SmartWfActivity aRunningWhenAborting = (SmartWfActivity)it.next();
SmartWfActivity aSuspendedWhenAborting = (SmartWfActivity)it.next();
assertTrue(aSuspendedWhenAborting != null);
assertState(aSuspendedWhenAborting, RUNNING);
Collection cNotRunning = process.activitiesInState(NOT_STARTED);
it = cNotRunning.iterator();
SmartWfActivity aNotStartedWhenAborting = (SmartWfActivity)it.next();
assertTrue(aNotStartedWhenAborting != null);
aSuspendedWhenAborting.suspend();
assertState(aSuspendedWhenAborting, SUSPENDED);
aAbortedWhenAborting.suspend();
assertState(aAbortedWhenAborting, SUSPENDED);
// abort activity causing process (4)-> activities(5, 7), process(5)
aAbortedWhenAborting.abort();
assertState(aAbortedWhenAborting, ABORTED);
process.waitForState();
assertState(process, ABORTED);
assertTrue(!aRunningWhenAborting.hasState(RUNNING));
assertTrue(!aSuspendedWhenAborting.hasState(RUNNING));
assertTrue(!aNotStartedWhenAborting.hasState(RUNNING));
removeProcess(process);
}
/**
* Test a simple process definition. The process is aborted.
* @exception Exception if an error occurs
*/
public void checkP2T5T57()
throws Exception {
// create the process
SmartWfProcess process = createProcess("st-process2", "P2");
assertState(process, NOT_STARTED);
// start the process (1)-> activitiy(1)
process.setupWaitForState (RUNNING);
process.start();
process.waitForState ();
assertState(process, RUNNING);
Collection cRunning = process.activitiesInState(RUNNING);
Iterator it = cRunning.iterator();
ActivityNameAnalyser ana;
SmartWfActivity aNotStopableRunningWhenAborting = null;
SmartWfActivity aRunningWhenAborting = (SmartWfActivity)it.next();
ana = new ActivityNameAnalyser(aRunningWhenAborting.name());
// activity 2.4 is implemented as JSExecutor and therefore cannot be
// terminated
if (ana.number().equals("2.4")) {
aNotStopableRunningWhenAborting = aRunningWhenAborting;
aRunningWhenAborting = (SmartWfActivity)it.next();
}
SmartWfActivity aSuspendedWhenAborting = (SmartWfActivity)it.next();
ana = new ActivityNameAnalyser(aSuspendedWhenAborting.name());
if (ana.number().equals("2.4")) {
aNotStopableRunningWhenAborting = aSuspendedWhenAborting;
aSuspendedWhenAborting = (SmartWfActivity)it.next();
}
if (aNotStopableRunningWhenAborting == null) {
aNotStopableRunningWhenAborting = (SmartWfActivity)it.next();
}
assertTrue(aSuspendedWhenAborting != null);
assertState(aSuspendedWhenAborting, RUNNING);
Collection cNotRunning = process.activitiesInState(NOT_STARTED);
it = cNotRunning.iterator();
SmartWfActivity aNotStartedWhenAborting = (SmartWfActivity)it.next();
assertTrue(aNotStartedWhenAborting != null);
// suspend the process (4)-> activities(-)
process.suspend();
assertState(process, SUSPENDED);
assertState(aSuspendedWhenAborting, RUNNING);
aSuspendedWhenAborting.suspend();
assertState(aSuspendedWhenAborting, SUSPENDED);
// abort the process (5)-> activities(5, 7)
process.abort();
assertState(process, ABORTED);
assertState(aRunningWhenAborting, TERMINATED);
assertState(aSuspendedWhenAborting, ABORTED);
assertState(aNotStartedWhenAborting, NOT_STARTED);
assertState(aNotStopableRunningWhenAborting, ABORTED);
removeProcess(process);
}
/**
* Test a simple process definition. The process is terminated.
* @exception Exception if an error occurs
*/
public void checkP0T7T7() throws Exception {
// create the process
SmartWfProcess process = createProcess("st-process2", "P0");
assertState(process, NOT_STARTED);
// start the process (1)-> activitiy(1)
process.setupWaitForState (RUNNING);
process.start();
assertState(process, RUNNING);
process.waitForState ();
Collection cRunning = process.activitiesInState(RUNNING);
Iterator it = cRunning.iterator();
SmartWfActivity aRunningWhenTerminated = (SmartWfActivity)it.next();
assertTrue(aRunningWhenTerminated != null);
assertState(aRunningWhenTerminated, RUNNING);
SmartWfActivity aSuspendedWhenTerminated = (SmartWfActivity)it.next();
assertTrue(aSuspendedWhenTerminated != null);
assertState(aSuspendedWhenTerminated, RUNNING);
Collection cNotRunning = process.activitiesInState(NOT_STARTED);
it = cNotRunning.iterator();
SmartWfActivity aNotStartedWhenTerminated = (SmartWfActivity)it.next();
assertTrue(aNotStartedWhenTerminated != null);
Collection cNotTerminateable = process.activitiesInState(SUSPENDED);
it = cNotTerminateable.iterator();
SmartWfActivity aNotTerminateableWhenTerminated
= (SmartWfActivity)it.next();
assertTrue(aNotTerminateableWhenTerminated != null);
// suspend the process (4)-> activitiy(-)
process.setupWaitForState (SUSPENDED);
process.suspend();
assertState(process, SUSPENDED);
process.waitForState ();
assertState(process, SUSPENDED);
assertState(aRunningWhenTerminated, RUNNING);
// resume the process (3)-> activitiy(-)
process.setupWaitForState (RUNNING);
process.resume();
assertState(process, RUNNING);
process.waitForState ();
assertState(process, RUNNING);
assertState(aRunningWhenTerminated, RUNNING);
aSuspendedWhenTerminated.setupWaitForState (SUSPENDED);
aSuspendedWhenTerminated.suspend();
aSuspendedWhenTerminated.waitForState ();
// try to terminate the process (try 7)-> activitiy(7) a suspended
// activity stays suspended :: Throw CannotStopException
boolean exceptionCaught = false;
try {
process.terminate();
} catch (CannotStopException ex) {
exceptionCaught = true;
} catch (TransitionNotAllowedException ex) {
exceptionCaught = true;
}
assertTrue(exceptionCaught);
assertState(process, RUNNING);
assertState(aRunningWhenTerminated, RUNNING);
assertState(aNotStartedWhenTerminated, NOT_STARTED);
assertState(aSuspendedWhenTerminated, SUSPENDED);
assertState(aNotTerminateableWhenTerminated, SUSPENDED);
aSuspendedWhenTerminated.setupWaitForState (RUNNING);
aSuspendedWhenTerminated.resume();
aSuspendedWhenTerminated.waitForState ();
aNotTerminateableWhenTerminated.setupWaitForState (RUNNING);
aNotTerminateableWhenTerminated.resume();
aNotTerminateableWhenTerminated.waitForState ();
Thread.sleep(500);//wait for started JSExecutor tool
// no suspended activity but not terminateable activity
// terminate the process (try 7)-> terminateable activitiy(7)and
// running not terminateable activity stays running
aRunningWhenTerminated.setupWaitForState(TERMINATED);
aSuspendedWhenTerminated.setupWaitForState(TERMINATED);
exceptionCaught = false;
try {
process.terminate();
} catch (CannotStopException ex) {
exceptionCaught = true;
} catch (TransitionNotAllowedException ex) {
exceptionCaught = true;
}
assertTrue(exceptionCaught);
//all terminateable activities are terminated
aRunningWhenTerminated.waitForState();
assertState(aRunningWhenTerminated, TERMINATED);
assertState(aNotStartedWhenTerminated, NOT_STARTED);
aSuspendedWhenTerminated.waitForState();
assertState(aSuspendedWhenTerminated, TERMINATED);
assertState(aNotTerminateableWhenTerminated, RUNNING);
assertState(process, RUNNING);
Thread.sleep(2000); //wait for started Webform tool
assertState(aNotTerminateableWhenTerminated, RUNNING);
//now all activities (only one) are running and terminateable
process.setupWaitForState (TERMINATED);
aNotTerminateableWhenTerminated.setupWaitForState (TERMINATED);
process.terminate();
aNotTerminateableWhenTerminated.waitForState();
assertState(aNotTerminateableWhenTerminated, TERMINATED);
process.waitForState();
assertState(process, TERMINATED);
removeProcess(process);
}
/**
* Test a simple process definition. The process is aborted. But one
* activity cannot be terminated because it is implemented as JSExecutor
* tool. An Exception has to be thrown.
* @exception Exception if an error occurs
*/
public void checkExceptionP1T7T7()
throws Exception {
// create the process
SmartWfProcess process = createProcess("st-process2", "P1");
assertState(process, NOT_STARTED);
Collection activities = process.steps();
Iterator it = activities.iterator();
SmartWfActivity activity = (SmartWfActivity)it.next();
SmartWfActivity stopableActivity;
SmartWfActivity notStopableActivity;
if ((new ActivityNameAnalyser(activity.name())).number()
.equals("1.1")) { // activity 1.1 is a webform tool
stopableActivity = activity; // Webform tool
notStopableActivity = (SmartWfActivity)it.next(); //JSExecutor tool
} else {
notStopableActivity = activity; // JSExecutor tool
stopableActivity = (SmartWfActivity)it.next(); // Webform tool
}
// start the process (1)-> activities(1)
process.setupWaitForState (RUNNING);
notStopableActivity.setupWaitForState(RUNNING);
stopableActivity.setupWaitForState(RUNNING);
process.start();
assertState(process, RUNNING);
process.waitForState ();
assertState(process, RUNNING);
notStopableActivity.waitForState();
assertState(notStopableActivity, RUNNING);
stopableActivity.waitForState();
assertState(stopableActivity, RUNNING);
// to terminate process
process.setupWaitForState (TERMINATED);
boolean exceptionCaught = false;
try {
process.terminate();
} catch (CannotStopException e) {
exceptionCaught = true;
} catch (TransitionNotAllowedException e) {
exceptionCaught = true;
}
assertTrue(exceptionCaught);
assertState(process, RUNNING);
assertState(notStopableActivity, RUNNING);
assertState(stopableActivity, TERMINATED);
process.waitForState();
assertState(process, TERMINATED);
removeProcess(process);
}
}