1 9 package org.jboss.portal.test.portal.kernel; 10 11 import junit.framework.TestCase; 12 13 import org.apache.log4j.Logger; 14 import org.jboss.portal.server.kernel.TransitionNotPossibleException; 15 import org.jboss.portal.server.kernel.state.State; 16 import org.jboss.portal.server.kernel.state.StateMachine; 17 18 22 public class StateMachineTestCase extends TestCase 23 { 24 25 public StateMachineTestCase(String s) 26 { 27 super(s); 28 } 29 30 private StateMachine machine; 31 32 protected void setUp() throws Exception 33 { 34 machine = new StateMachine(Logger.getLogger(StateMachine.class)); 35 } 36 37 protected void tearDown() throws Exception 38 { 39 machine = null; 40 } 41 42 public void test1() 43 { 44 assertEquals(State.UNREGISTERED, machine.getState()); 45 create(false); 46 start(false); 47 stop(false); 48 destroy(false); 49 unregister(false); 50 } 51 52 public void test2() 53 { 54 register(true); 55 assertEquals(State.REGISTERED, machine.getState()); 56 } 57 58 public void test3() 59 { 60 register(true); 61 register(false); 62 start(false); 63 stop(false); 64 destroy(false); 65 } 66 67 public void test4() 68 { 69 register(true); 70 unregister(true); 71 assertEquals(State.UNREGISTERED, machine.getState()); 72 } 73 74 public void test5() 75 { 76 register(true); 77 create(true); 78 assertEquals(State.STOPPED, machine.getState()); 79 } 80 81 public void test6() 82 { 83 register(true); 84 create(true); 85 create(false); 86 register(false); 87 unregister(false); 88 stop(false); 89 } 90 91 public void test7() 92 { 93 register(true); 94 create(true); 95 start(true); 96 assertEquals(State.STARTED, machine.getState()); 97 } 98 99 public void test8() 100 { 101 register(true); 102 create(true); 103 destroy(true); 104 assertEquals(State.REGISTERED, machine.getState()); 105 } 106 107 public void test9() 108 { 109 register(true); 110 create(true); 111 start(true); 112 register(false); 113 create(false); 114 start(false); 115 destroy(false); 116 unregister(false); 117 } 118 119 public void test10() 120 { 121 register(true); 122 create(true); 123 start(true); 124 stop(true); 125 assertEquals(State.STOPPED, machine.getState()); 126 } 127 128 private void register(boolean succesfull) 129 { 130 try 131 { 132 machine.register(false); 133 if (!succesfull) 134 { 135 fail(); 136 } 137 } 138 catch (TransitionNotPossibleException expected) 139 { 140 if (succesfull) 141 { 142 fail(); 143 } 144 } 145 } 146 147 private void create(boolean succesfull) 148 { 149 try 150 { 151 machine.create(false); 152 if (!succesfull) 153 { 154 fail(); 155 } 156 } 157 catch (TransitionNotPossibleException expected) 158 { 159 if (succesfull) 160 { 161 fail(); 162 } 163 } 164 } 165 166 private void start(boolean succesfull) 167 { 168 try 169 { 170 machine.start(false); 171 if (!succesfull) 172 { 173 fail(); 174 } 175 } 176 catch (TransitionNotPossibleException expected) 177 { 178 if (succesfull) 179 { 180 fail(); 181 } 182 } 183 } 184 185 private void stop(boolean succesfull) 186 { 187 try 188 { 189 machine.stop(false); 190 if (!succesfull) 191 { 192 fail(); 193 } 194 } 195 catch (TransitionNotPossibleException expected) 196 { 197 if (succesfull) 198 { 199 fail(); 200 } 201 } 202 } 203 204 private void destroy(boolean succesfull) 205 { 206 try 207 { 208 machine.destroy(false); 209 if (!succesfull) 210 { 211 fail(); 212 } 213 } 214 catch (TransitionNotPossibleException expected) 215 { 216 if (succesfull) 217 { 218 fail(); 219 } 220 } 221 } 222 223 private void unregister(boolean succesfull) 224 { 225 try 226 { 227 machine.unregister(false); 228 if (!succesfull) 229 { 230 fail(); 231 } 232 } 233 catch (TransitionNotPossibleException expected) 234 { 235 if (succesfull) 236 { 237 fail(); 238 } 239 } 240 } 241 242 private void fail(boolean succesfull) 243 { 244 try 245 { 246 machine.fail(false); 247 if (!succesfull) 248 { 249 fail(); 250 } 251 } 252 catch (TransitionNotPossibleException expected) 253 { 254 if (succesfull) 255 { 256 fail(); 257 } 258 } 259 } 260 } 261 262 | Popular Tags |