| Home >> All |
Source code: domain/States.java
1 /* 2 * Danet GmbH 3 * Beratung und Software-Entwicklung 4 * Geschäftstelle AN 5 * 6 * $Id: States.java,v 1.22 2003/06/05 17:26:58 lipp Exp $ 7 * 8 * $Log: States.java,v $ 9 * Revision 1.22 2003/06/05 17:26:58 lipp 10 * Extended error message. 11 * 12 * Revision 1.21 2003/04/26 16:12:35 lipp 13 * Moved some classes to reduce package dependencies. 14 * 15 * Revision 1.20 2002/11/11 12:20:44 lipp 16 * Some fixes. 17 * 18 * Revision 1.19 2002/10/21 19:08:05 lipp 19 * Continuing implementation of new state handling. 20 * 21 * Revision 1.18 2002/10/21 16:59:55 lipp 22 * More fixes. 23 * 24 * Revision 1.17 2002/10/21 16:24:24 lipp 25 * Added state compatibility test. 26 * 27 * Revision 1.16 2002/10/21 13:48:03 lipp 28 * Continuing implementation of new state handling. 29 * 30 * Revision 1.15 2002/10/21 11:54:23 lipp 31 * Better suspend state handling. 32 * 33 * Revision 1.14 2002/10/09 14:27:33 lipp 34 * Intermediate, compilable state. 35 * 36 * Revision 1.13 2002/08/30 13:37:05 lipp 37 * Using Workflow engine facade now. 38 * 39 * Revision 1.12 2002/08/22 15:19:34 lipp 40 * Redesign of EJB persistence. 41 * 42 * Revision 1.11 2002/08/21 22:06:48 lipp 43 * Finished transition to ProcessMgrStub. 44 * 45 * Revision 1.10 2002/08/02 09:28:53 huaiyang 46 * Use JDOM. 47 * 48 * Revision 1.9 2002/02/04 22:43:12 lipp 49 * Adapted tests to changed. 50 * 51 * Revision 1.8 2002/01/23 15:42:04 lipp 52 * Adapted to interface changes. 53 * 54 * Revision 1.7 2001/12/13 21:00:05 lipp 55 * Simplified temporary implementation of a requester. 56 * 57 * Revision 1.6 2001/10/08 10:58:24 lipp 58 * Adapted to interface/implementation separation in domain. 59 * 60 * Revision 1.5 2001/09/26 13:52:46 montag 61 * *** empty log message *** 62 * 63 * Revision 1.4 2001/09/25 12:12:03 montag 64 * unittests corrected 65 * 66 * Revision 1.3 2001/09/24 13:54:15 montag 67 * WfProcessPK, WfActivityPK and ContributorPK removed. 68 * 69 * Revision 1.2 2001/09/07 11:47:49 montag 70 * new substates for open.not_running.suspended 71 * 72 * Revision 1.1 2001/08/29 10:59:11 lipp 73 * Tests split in groups. 74 * 75 */ 76 package domain; 77 78 import de.danet.an.workflow.omgcore.NotRunningException; 79 import de.danet.an.workflow.omgcore.TransitionNotAllowedException; 80 import de.danet.an.workflow.omgcore.WfExecutionObject; 81 82 import de.danet.an.workflow.api.Activity.StartFinishMode; 83 84 import de.danet.an.workflow.domain.AbstractExecutionObject; 85 86 import junit.framework.Test; 87 import junit.framework.TestCase; 88 import junit.framework.TestSuite; 89 90 /** 91 * Zusammenstellung aller TimerObjectTests. 92 * @author <a href="mailto:lipp@danet.de"></a> 93 * @version 1.0 94 */ 95 public class States extends TestCase { 96 97 /** 98 * Konstruktor zum Erzeugen eines TestCase 99 * @param name a <code>String</code> value 100 */ 101 public States(String name) { 102 super (name); 103 } 104 105 /** 106 * Stellt diese TestSuite zusammen. 107 * @return a <code>Test</code> value 108 */ 109 public static Test suite() { 110 TestSuite suite = new TestSuite(); 111 suite.addTest(new States("availableStates")); 112 suite.addTest(new States("executionState")); 113 suite.addTest(new States("availableModes")); 114 return suite; 115 } 116 117 /** 118 * Check if state machine for 1for avaiable states of the 1. iteration. 119 * @exception Exception if an error occurs 120 */ 121 public void availableStates() throws Exception { 122 WfExecutionObject.State[] states = new WfExecutionObject.State[11]; 123 states[0] = WfExecutionObject.State.fromString("open"); 124 assertTrue (states[0] != null); 125 states[1] = WfExecutionObject.State.fromString("closed"); 126 assertTrue (states[1] != null); 127 states[2] = WfExecutionObject.State.fromString("open.running"); 128 assertTrue (states[2] != null); 129 states[3] = WfExecutionObject.State.fromString("open.not_running"); 130 assertTrue (states[3] != null); 131 states[4] = WfExecutionObject.State.fromString 132 ("open.not_running.not_started"); 133 assertTrue (states[4] != null); 134 states[5] = WfExecutionObject.State.fromString 135 ("open.not_running.suspended"); 136 assertTrue (states[5] != null); 137 states[6] = WfExecutionObject.State.fromString("closed.completed"); 138 assertTrue (states[6] != null); 139 states[7] = WfExecutionObject.State.fromString("closed.aborted"); 140 assertTrue (states[7] != null); 141 states[8] = WfExecutionObject.State.fromString("closed.terminated"); 142 assertTrue (states[8] != null); 143 WfExecutionObject.State s 144 = AbstractExecutionObject.RunningState.RUNNING; 145 s = AbstractExecutionObject.SuspendedState.SUSPENDED; 146 states[9] = WfExecutionObject.State 147 .fromString("open.not_running.suspended.aborting"); 148 assertTrue (states[9] != null); 149 states[10] = WfExecutionObject.State 150 .fromString("open.running.terminating"); 151 assertTrue (states[10] != null); 152 153 for (int i=0; i<11;i++) { 154 for (int j=0; j<11;j++) { 155 if (states[i].toString().equals(states[j].toString()) 156 || (states[i].toString() 157 .startsWith(states[j].toString() + "."))) { 158 assertTrue (states[i] + " should be same or have substate " 159 + states[j], 160 states[i].isSameOrSubState(states[j])); 161 } else { 162 assertTrue 163 (states[i] + " should not be same or have substate " 164 + states[j], 165 !states[i].isSameOrSubState(states[j])); 166 } 167 } 168 } 169 } 170 171 /** 172 * Check if state machine for 1. iteration works. 173 * @exception Exception if an error occurs 174 */ 175 public void executionState() throws Exception { 176 VolatileProcess aeo = new VolatileProcess(); 177 VolatileActivity act = new VolatileActivity (aeo); 178 aeo.addActivity (act); 179 act.setStartMode (StartFinishMode.MANUAL); 180 assertTrue(aeo.state().equals("open.not_running.not_started")); 181 assertTrue(aeo.workflowState().equals(WfExecutionObject.State.OPEN)); 182 assertTrue(aeo.whileOpen() 183 .equals(WfExecutionObject.OpenState.NOT_RUNNING)); 184 assertTrue(aeo.whyNotRunning() 185 .equals(WfExecutionObject.NotRunningState.NOT_STARTED)); 186 boolean exceptionCaught = false; 187 try { 188 aeo.howClosed(); 189 } catch (IllegalStateException is) { 190 exceptionCaught = true; 191 } 192 assertTrue (exceptionCaught); 193 // change to illegal state 194 exceptionCaught = false; 195 try { 196 aeo.changeState(WfExecutionObject 197 .ClosedState.COMPLETED.toString()); 198 } catch (TransitionNotAllowedException ie) { 199 exceptionCaught = true; 200 } 201 assertTrue (exceptionCaught); 202 // change to illegal state 203 exceptionCaught = false; 204 try { 205 aeo.suspend(); 206 } catch (NotRunningException ce) { 207 exceptionCaught = true; 208 } 209 assertTrue (exceptionCaught); 210 211 // legal change 212 aeo.changeState(WfExecutionObject.OpenState.RUNNING.toString()); 213 // change to illegal transition 214 exceptionCaught = false; 215 try { 216 aeo.changeState(WfExecutionObject 217 .NotRunningState.NOT_STARTED.toString()); 218 } catch (TransitionNotAllowedException te) { 219 exceptionCaught = true; 220 } 221 assertTrue (exceptionCaught); 222 // finally abort 223 aeo.suspend(); 224 aeo.abort(); 225 assertTrue(aeo.state().equals("closed.aborted")); 226 assertTrue(aeo.workflowState().equals(WfExecutionObject.State.CLOSED)); 227 exceptionCaught = false; 228 try { 229 aeo.whileOpen(); 230 } catch (IllegalStateException is2) { 231 exceptionCaught = true; 232 } 233 assertTrue (exceptionCaught); 234 exceptionCaught = false; 235 try { 236 aeo.whyNotRunning(); 237 } catch (IllegalStateException is3) { 238 exceptionCaught = true; 239 } 240 assertTrue (exceptionCaught); 241 assertTrue (aeo.howClosed() 242 .equals(WfExecutionObject.ClosedState.ABORTED)); 243 } 244 245 /** 246 * Check if state machine for 1for avaiable states of the 1. iteration. 247 * @exception Exception if an error occurs 248 */ 249 public void availableModes() throws Exception { 250 StartFinishMode[] modes = new StartFinishMode[3]; 251 modes[0] = StartFinishMode.fromString("Manual"); 252 assertTrue (modes[0] == StartFinishMode.MANUAL); 253 modes[1] = StartFinishMode.fromString("Automatic"); 254 assertTrue (modes[1] == StartFinishMode.AUTOMATIC); 255 } 256 257 } 258