/*
* Danet GmbH
* Beratung und Software-Entwicklung
* Gesch�ftstelle AN
*
* $Id: Proc.java 2577 2007-11-02 22:11:45Z mlipp $
*
* $Log$
* Revision 1.4 2007/09/21 06:19:35 mlipp
* Fixed problem with NamingException during process deletion.
*
* Revision 1.3 2007/05/03 21:58:24 mlipp
* Internal refactoring for making better use of local EJBs.
*
* Revision 1.2 2007/03/27 21:59:42 mlipp
* Fixed lots of checkstyle warnings.
*
* Revision 1.1.1.1 2003/06/30 20:06:59 drmlipp
* Initial import
*
* Revision 1.43 2003/04/26 16:12:36 lipp
* Moved some classes to reduce package dependencies.
*
* Revision 1.42 2003/03/31 16:50:28 huaiyang
* Logging using common-logging.
*
* Revision 1.41 2002/12/09 10:53:00 lipp
* Updated to abort() modifications.
*
* Revision 1.40 2002/11/26 11:23:29 lipp
* Modified RemoteException comment.
*
* Revision 1.39 2002/11/19 15:14:52 lipp
* New transition manager.
*
* Revision 1.38 2002/11/11 12:20:44 lipp
* Some fixes.
*
* Revision 1.37 2002/11/04 08:40:25 barzik
* adapted to several modifications in the workflow component
*
* Revision 1.36 2002/10/21 11:54:23 lipp
* Better suspend state handling.
*
* Revision 1.35 2002/10/18 13:46:02 lipp
* Getting on with adaptions...
*
* Revision 1.34 2002/10/09 15:17:51 lipp
* Improved start mode handling.
*
* Revision 1.33 2002/10/09 14:27:33 lipp
* Intermediate, compilable state.
*
* Revision 1.32 2002/09/11 14:17:22 lipp
* Execptions using msgs now.
*
* Revision 1.31 2002/08/30 13:37:05 lipp
* Using Workflow engine facade now.
*
* Revision 1.30 2002/08/30 09:06:40 lipp
* Renamed internal state to typed state and use polymorphism for type
* names where possible.
*
* Revision 1.29 2002/08/28 12:58:03 lipp
* Fixed unittests.
*
* Revision 1.28 2002/08/28 12:47:20 lipp
* Starting new process generation.
*
* Revision 1.27 2002/08/22 15:19:34 lipp
* Redesign of EJB persistence.
*
* Revision 1.26 2002/08/21 22:06:48 lipp
* Finished transition to ProcessMgrStub.
*
* Revision 1.25 2002/08/02 09:28:53 huaiyang
* Use JDOM.
*
* Revision 1.24 2002/06/27 10:47:35 lipp
* Adapted to change in return type.
*
* Revision 1.23 2002/05/27 14:55:29 lipp
* Adapted to API changes.
*
* Revision 1.22 2002/02/04 22:43:12 lipp
* Adapted tests to changed.
*
* Revision 1.21 2002/02/04 15:18:55 lipp
* Made ActivityFinderAndKey visible in EJB Remote interface.
*
* Revision 1.20 2002/02/03 21:41:41 lipp
* Cleaned up unittests.
*
* Revision 1.19 2002/01/23 15:42:04 lipp
* Adapted to interface changes.
*
* Revision 1.18 2001/12/18 22:16:53 lipp
* Restructured DOM generation, implemented "assignments" method from ras.
*
* Revision 1.17 2001/12/15 12:47:07 lipp
* Getting an ActivityFinder implemented.
*
* Revision 1.16 2001/12/13 22:11:48 lipp
* Simplified temporary implementation of a requester.
*
* Revision 1.15 2001/12/13 21:00:05 lipp
* Simplified temporary implementation of a requester.
*
* Revision 1.14 2001/12/11 09:54:45 lipp
* Introduced security for workflow.
*
* Revision 1.13 2001/11/07 11:39:00 montag
* changed to internal ejb references
*
* Revision 1.12 2001/10/25 17:15:51 lipp
* Renamed getTransitionsRefs() to getNextActivities() (more appropriate
* name) and added TransitionRefs to DOM representatiosn.
*
* Revision 1.11 2001/10/25 14:36:43 montag
* Obsolete test case removed.
*
* Revision 1.10 2001/10/23 14:07:15 lipp
* Adapted to interface changes.
*
* Revision 1.9 2001/10/09 07:43:51 montag
* BaseElement reactivated
*
* Revision 1.8 2001/10/08 10:58:24 lipp
* Adapted to interface/implementation separation in domain.
*
* Revision 1.7 2001/10/04 08:01:54 montag
* unittests adopt for new transitionmanager
*
* Revision 1.6 2001/09/25 12:12:03 montag
* unittests corrected
*
* Revision 1.5 2001/09/24 13:43:11 montag
* WfProcessPK, WfActivityPK and ContributorPK removed.
*
* Revision 1.4 2001/09/24 12:30:52 montag
* ProcessAttributes removed.
*
* Revision 1.3 2001/09/11 12:30:05 montag
* clean up refresh/dispose due to new db scheme
*
* Revision 1.2 2001/09/10 06:37:19 montag
* notify process not in setInternalState()
*
* Revision 1.1 2001/08/29 10:59:11 lipp
* Tests split in groups.
*
*/
package domain;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
import java.rmi.RemoteException;
import de.danet.an.workflow.api.Activity.StartFinishMode;
import de.danet.an.workflow.localapi.ActivityLocal;
import de.danet.an.workflow.localapi.ProcessLocal;
import de.danet.an.workflow.localcoreapi.WfActivityLocal;
import de.danet.an.workflow.omgcore.AlreadySuspendedException;
import de.danet.an.workflow.omgcore.InvalidStateException;
import de.danet.an.workflow.omgcore.TransitionNotAllowedException;
import de.danet.an.workflow.omgcore.WfExecutionObject.State;
import junit.framework.*;
/**
* Zusammenstellung aller domain Tests f�r (Abstract)Process.
* @author <a href="mailto:lipp@danet.de"></a>
* @version 1.0
*/
public class Proc extends TestCase {
private static final org.apache.commons.logging.Log logger
= org.apache.commons.logging.LogFactory.getLog(Proc.class);
/**
* Konstruktor zum Erzeugen eines TestCase
* @param name a <code>String</code> value
*/
public Proc(String name) {
super (name);
}
/**
* Stellt diese TestSuite zusammen.
* @return a <code>Test</code> value
*/
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new Proc("processTest"));
suite.addTest(new Proc("processTest2"));
suite.addTest(new Proc("processTest3"));
suite.addTest(new Proc("processTest4"));
suite.addTest(new Proc("activityTest"));
suite.addTest(new Proc("abortProcess"));
return suite;
}
/**
* Test for Process
* @exception Exception if an error occurs
*/
public void processTest() throws Exception {
TestProcess p = getProcess();
assertTrue (p != null);
}
/**
* Test for Activity
* @exception Exception if an error occurs
*/
public void activityTest() throws Exception {
TestActivity a = getActivity(null);
assertTrue (a != null);
}
/**
* Test for Process with activity
* @exception Exception if an error occurs
*/
public void processTest2() throws Exception {
TestProcess p = getProcess();
assertTrue (p != null);
TestActivity a = getActivity(p);
assertTrue (a != null);
Collection c = new Vector();
c.add(a);
p.setActivities(c);
Collection d = p.stepsLocal();
Iterator it = d.iterator();
while (it.hasNext()) {
WfActivityLocal wfa = (WfActivityLocal)it.next();
assertTrue(wfa != null);
}
boolean allClosed = p.allActivitiesClosed();
assertTrue (!allClosed);
p.start();
allClosed = p.allActivitiesClosed();
assertTrue (allClosed);
}
/**
* Test for Process with activities
* @exception Exception if an error occurs
*/
public void processTest3() throws Exception {
TestProcess p = getProcess();
assertTrue (p != null);
TestActivity a1 = getActivity(p);
assertTrue (a1 != null);
TestActivity a2 = getActivity(p);
assertTrue (a2 != null);
p.addActivity(a1);
p.addActivity(a2);
p.addTransition ("t1", "t1", 0, a1, a2);
Collection d = p.stepsLocal();
Iterator it = d.iterator();
while (it.hasNext()) {
de.danet.an.workflow.localcoreapi.WfActivityLocal
wfa = (de.danet.an.workflow.localcoreapi.WfActivityLocal)
it.next();
assertTrue(wfa != null);
}
assertTrue (p.activitiesInState("open").size() == 2);
assertTrue (p.activitiesInState ("open.not_running").size() == 2);
assertTrue (p.activitiesInState
("open.not_running.not_started").size() == 2);
assertTrue (p.activitiesInState("closed").size() == 0);
boolean allClosed = p.allActivitiesClosed();
assertTrue (!allClosed);
p.start ();
allClosed = p.allActivitiesClosed();
assertTrue (allClosed);
assertTrue (p.activitiesInState("open").size() == 0);
assertTrue (p.activitiesInState("closed").size() == 2);
}
/**
* Test for Process with activities and transitions
* @exception Exception if an error occurs
*/
public void processTest4() throws Exception {
TestProcess p = getProcess();
assertTrue (p != null);
TestActivity a1 = getActivity(p);
assertTrue (a1 != null);
TestActivity a2 = getActivity(p);
assertTrue (a2 != null);
Collection ca = new Vector();
ca.add(a1);
ca.add(a2);
p.setActivities(ca);
}
/**
* Test for aborting a Process and his activities
* @exception Exception if an error occurs
*/
public void abortProcess() throws Exception {
TestProcess p = getProcess();
assertTrue (p != null);
TestActivity a1 = getActivity(p);
assertTrue (a1 != null);
a1.setStartMode (StartFinishMode.MANUAL);
TestActivity a2 = getActivity(p);
assertTrue (a2 != null);
a2.setStartMode (StartFinishMode.MANUAL);
Collection c = new Vector();
p.addActivity(a1);
p.addActivity(a2);
p.addTransition ("t1", "t1", 0, a1, a2);
p.start ();
assertTrue(a1.state().startsWith("open.not_running.suspended"));
assertTrue(a2.state().startsWith("open.not_running.not_started"));
p.changeState("open.not_running.suspended");
assertTrue(p.state().startsWith("open.not_running.suspended"));
boolean gotIt = false;
try {
p.suspend();
} catch (AlreadySuspendedException e) {
gotIt = true;
}
assertTrue (gotIt);
p.resume ();
assertTrue(p.state().startsWith("open.running"));
p.suspend();
assertTrue(p.state().startsWith("open.not_running.suspended"));
assertTrue(a1 + " is " + a1.state() + " should be open.not_running.suspended",
a1.state().startsWith("open.not_running.suspended"));
assertTrue(a2 + " is " + a2.state() + " should be open.not_running.not_started",
a2.state().startsWith("open.not_running.not_started"));
p.abort ();
assertTrue(p + " is " + p.state() + ", should be closed.aborted",
p.state().equals("closed.aborted"));
assertTrue(a1 + " is " + a1.state() + ", should be closed.aborted",
a1.state().equals("closed.aborted"));
assertTrue(a2 + " is " + a2.state() + ", should be open.not_running.not_started",
a2.state().startsWith("open.not_running.not_started"));
}
//////////////////////////////////////////////////////////
private TestProcess getProcess() {
return new TestProcess();
}
/**
* Describe class <code>TestProcess</code> here.
*
*/
public class TestProcess extends VolatileProcess {
/**
* Creates a new <code>TestProcess</code> instance.
*
*/
public TestProcess () {
super ("p1");
}
/**
* Checks if all activities of the process are closed.
* @return <code>true</code>, if all activities of the process
* are closed; <code>false</code> else.
* @throws RemoteException if a system-level error occurs.
*/
public boolean allActivitiesClosed() throws RemoteException {
for (Iterator it = stepsLocal().iterator(); it.hasNext();) {
ActivityLocal act = (ActivityLocal)it.next();
if (! act.typedState().isSameOrSubState(State.CLOSED)) {
return false;
}
}
return true;
}
}
private TestActivity getActivity(TestProcess p) {
return new TestActivity(p);
}
private static int actkeyGen = 1;
/**
* Describe class <code>TestActivity</code> here.
*
*/
public class TestActivity extends VolatileActivity {
/**
* Creates a new <code>TestActivity</code> instance.
*
* @param p a <code>Process</code> value
*/
public TestActivity(TestProcess p) {
super (p, "a" + Integer.toString(actkeyGen++));
}
/**
* Describe <code>pubSetState</code> method here.
*
* @param s a <code>State</code> value
* @exception InvalidStateException if an error occurs
*/
public void pubSetState (State s)
throws InvalidStateException, TransitionNotAllowedException {
changeState (s);
}
}
}