1 22 package org.objectweb.petals.jbi.component.thread; 23 24 import javax.jbi.JBIException; 25 import javax.jbi.component.Component; 26 import javax.jbi.component.ComponentContext; 27 import javax.jbi.component.ComponentLifeCycle; 28 29 import junit.framework.TestCase; 30 import static org.easymock.EasyMock.expect; 31 import static org.easymock.classextension.EasyMock.createMock; 32 import static org.easymock.classextension.EasyMock.replay; 33 import static org.easymock.classextension.EasyMock.reset; 34 import static org.easymock.classextension.EasyMock.verify; 35 36 41 public class ComponentLifeCycleThreadTest extends TestCase { 42 43 46 private ComponentLifeCycleThread lifeCycleThread; 47 48 51 private ComponentLifeCycle lifeCycleMock; 52 53 56 private Component componentMock; 57 58 61 private ComponentContext contextMock; 62 63 67 public void testDoInit() throws Exception { 68 lifeCycleThread.start(); 69 reset(componentMock); 70 expect(componentMock.getLifeCycle()).andReturn(lifeCycleMock); 71 replay(componentMock); 72 73 lifeCycleThread.doInit(contextMock); 74 verify(componentMock); 75 76 JBIException jbie = lifeCycleThread.getJbiException(); 77 assertNull(jbie); 78 } 79 80 84 public void testDoStart() throws Exception { 85 lifeCycleThread.start(); 86 reset(componentMock); 87 expect(componentMock.getLifeCycle()).andReturn(lifeCycleMock); 88 replay(componentMock); 89 90 lifeCycleThread.doStart(); 91 verify(componentMock); 92 93 JBIException jbie = lifeCycleThread.getJbiException(); 94 assertNull(jbie); 95 } 96 97 100 public void testDoStop() throws Exception { 101 lifeCycleThread.start(); 102 103 reset(componentMock); 104 expect(componentMock.getLifeCycle()).andReturn(lifeCycleMock); 105 replay(componentMock); 106 107 lifeCycleThread.doStop(); 108 verify(componentMock); 109 110 JBIException jbie = lifeCycleThread.getJbiException(); 111 assertNull(jbie); 112 } 113 114 118 public void testDoShutdown() throws Exception { 119 lifeCycleThread.start(); 120 121 reset(componentMock); 122 expect(componentMock.getLifeCycle()).andReturn(lifeCycleMock); 123 replay(componentMock); 124 125 lifeCycleThread.doShutdown(); 126 verify(componentMock); 127 128 JBIException jbie = lifeCycleThread.getJbiException(); 129 assertNull(jbie); 130 } 131 132 136 public void testMultipleCalls() { 137 lifeCycleThread.start(); 138 139 reset(componentMock); 141 expect(componentMock.getLifeCycle()).andReturn(lifeCycleMock); 142 replay(componentMock); 143 try { 144 lifeCycleThread.doStop(); 145 } catch (JBIException e) { 146 fail(e.getMessage()); 147 } 148 verify(componentMock); 149 150 reset(componentMock); 152 expect(componentMock.getLifeCycle()).andReturn(lifeCycleMock); 153 replay(componentMock); 154 try { 155 lifeCycleThread.doShutdown(); 156 } catch (JBIException e) { 157 fail(e.getMessage()); 158 } 159 verify(componentMock); 160 161 } 162 163 168 protected void setUp() throws Exception { 169 super.setUp(); 170 171 componentMock = createMock(Component.class); 172 contextMock = createMock(ComponentContext.class); 173 lifeCycleMock = createMock(ComponentLifeCycle.class); 174 175 lifeCycleThread = new ComponentLifeCycleThread(componentMock); 176 } 177 178 } 179 | Popular Tags |