1 22 package org.jboss.test.jmx.test; 23 24 import org.jboss.system.ServiceMBeanState; 25 import org.jboss.test.JBossTestCase; 26 import org.jboss.util.state.IllegalTransitionException; 27 import org.jboss.util.state.State; 28 import org.jboss.util.state.StateMachine; 29 30 36 public class ServiceMBeanStateMachineUnitTestCase extends JBossTestCase 37 { 38 39 private StateMachine sm = ServiceMBeanState.createStateMachine("A test state machine"); 40 41 public ServiceMBeanStateMachineUnitTestCase(String name) 42 { 43 super(name); 44 } 45 46 public void setUp() 47 { 48 sm.reset(); 49 } 50 51 public void testRegisterUnregister() throws Exception 52 { 53 getLog().debug("+++ testRegisterUnregister"); 54 55 String [] script = { 56 "register", 57 "unregister" 58 }; 59 tryActionScript(script, false); 60 } 61 62 public void testCreateDestroy() throws Exception 63 { 64 getLog().debug("+++ testCreateDestroy"); 65 66 String [] script = { 67 "register", 68 "create", 69 "destroy" 70 }; 71 tryActionScript(script, false); 72 } 73 74 public void testCreateDestroyCreate() throws Exception 75 { 76 getLog().debug("+++ testCreateDestroyCreate"); 77 78 String [] script = { 79 "register", 80 "create", 81 "destroy", 82 "create" 83 }; 84 tryActionScript(script, false); 85 } 86 87 public void testStartStopStart() throws Exception 88 { 89 getLog().debug("+++ testStartStopStart"); 90 91 String [] script = { 92 "register", 93 "create", 94 "startBegin", 95 "startEnd", 96 "stopBegin", 97 "stopEnd", 98 "startBegin", 99 "startEnd" 100 }; 101 tryActionScript(script, false); 102 } 103 104 public void testFullLifecycle() throws Exception 105 { 106 getLog().debug("+++ testFullLifecycle"); 107 108 String [] script = { 109 "register", 110 "create", 111 "startBegin", 112 "startEnd", 113 "stopBegin", 114 "stopEnd", 115 "destroy", 116 "unregister" 117 }; 118 tryActionScript(script, false); 119 } 120 121 public void testFailedCreate() throws Exception 122 { 123 getLog().debug("+++ testFailedCreate"); 124 125 String [] script = { 126 "register", 127 "create", 128 "fail" 129 }; 130 tryActionScript(script, false); 131 } 132 133 public void testFailedStart() throws Exception 134 { 135 getLog().debug("+++ testFailedStart"); 136 137 String [] script = { 138 "register", 139 "create", 140 "startBegin", 141 "fail" 142 }; 143 tryActionScript(script, false); 144 } 145 146 public void testFailedStop() throws Exception 147 { 148 getLog().debug("+++ testFailedStop"); 149 150 String [] script = { 151 "register", 152 "create", 153 "startBegin", 154 "startEnd", 155 "stopBegin", 156 "fail" 157 }; 158 tryActionScript(script, false); 159 } 160 161 public void testFailedDestroy() throws Exception 162 { 163 getLog().debug("+++ testFailedDestroy"); 164 165 String [] script = { 166 "register", 167 "create", 168 "startBegin", 169 "startEnd", 170 "stopBegin", 171 "stopEnd", 172 "destroy", 173 "fail" 174 }; 175 tryActionScript(script, false); 176 } 177 178 public void testDontCreateBeforeRegister() throws Exception 179 { 180 getLog().debug("+++ testDontCreateBeforeRegister"); 181 182 String [] script = { 183 "create" 184 }; 185 tryActionScript(script, true); 186 } 187 188 public void testDontStartBeforeCreate() throws Exception 189 { 190 getLog().debug("+++ testDontStartBeforeCreate"); 191 192 String [] script = { 193 "register", 194 "startBegin" 195 }; 196 tryActionScript(script, true); 197 } 198 199 public void testDontDestroyBeforeStop() throws Exception 200 { 201 getLog().debug("+++ testDontDestroyBeforeStop"); 202 203 String [] script = { 204 "register", 205 "create", 206 "startBegin", 207 "startEnd", 208 "destroy" 209 }; 210 tryActionScript(script, true); 211 } 212 213 private void tryActionScript(String [] script, boolean exceptionExpected) throws Exception 214 { 215 for (int i = 0; i < script.length; i++) 216 { 217 getLog().debug("Current State: " + sm.getCurrentState().getName() + ", Action: " + script[i]); 218 try 219 { 220 State stateAfter = sm.nextState(script[i]); 221 } 222 catch (IllegalTransitionException e) 223 { 224 if (exceptionExpected) 225 { 226 getLog().debug("Caught Excepted IllegalTransitionException: " + e.getMessage()); 227 } 228 else 229 { 230 getLog().debug("Caught Unexcepted IllegalTransitionException: " + e.getMessage()); 231 232 throw e; 233 } 234 } 235 } 236 getLog().debug("Final State: " + sm.getCurrentState().getName()); 237 } 238 } 239 | Popular Tags |