1 17 package org.apache.servicemix.beanflow.util; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.servicemix.beanflow.Activity; 22 import org.apache.servicemix.beanflow.Activity.Transitions; 23 24 import java.util.Timer ; 25 26 import junit.framework.TestCase; 27 28 32 public abstract class ActivityTestSupport extends TestCase { 33 34 private static final Log log = LogFactory.getLog(ActivityTestSupport.class); 35 36 protected Timer timer = new Timer (); 37 protected long timeout = 500L; 38 39 protected void assertStarted(Activity activity) throws Exception { 40 assertNotFailed(activity); 41 assertEquals("Transition", Transitions.Started, activity.getState().get()); 42 } 43 44 protected void assertStopped(Activity activity) throws Exception { 45 assertNotFailed(activity); 46 assertEquals("Transition", Transitions.Stopped, activity.getState().get()); 47 48 assertTrue("Flow should be stopped but is: " + activity.getState().get(), activity.isStopped()); 49 assertTrue("Flow should not have failed", !activity.isFailed()); 50 } 51 52 protected void assertNotFailed(Activity activity) throws Exception { 53 assertTrue("Should not have failed: " + activity.getFailedReason() + " exception: " 54 + activity.getFailedException(), !activity.isFailed()); 55 56 Throwable failedException = activity.getFailedException(); 57 if (failedException != null) { 58 if (failedException instanceof Exception ) { 59 throw (Exception ) failedException; 60 } 61 else { 62 throw new RuntimeException (failedException); 63 } 64 } 65 } 66 67 protected void assertFailed(Activity activity) { 68 assertEquals("Transition", Transitions.Failed, activity.getState().get()); 69 70 assertTrue("Flow should be stopped but is: " + activity.getState().get(), activity.isStopped()); 71 assertTrue("Flow should have failed", activity.isFailed()); 72 73 log.info("The activity failed due to: " + activity.getFailedReason()); 74 } 75 76 protected void startActivity(Activity activity, long timeout) throws Exception { 77 assertTrue("activity should not be stopped", !activity.isStopped()); 78 assertTrue("activity should not have failed", !activity.isFailed()); 79 assertEquals("Transition", Transitions.Initialised, activity.getState().get()); 80 81 activity.startWithTimeout(timer, timeout); 82 assertStarted(activity); 83 } 84 85 } 86 | Popular Tags |