1 22 package org.objectweb.petals.jbi.component.thread; 23 24 import javax.jbi.JBIException; 25 import javax.jbi.component.Bootstrap; 26 import javax.jbi.component.InstallationContext; 27 import javax.management.ObjectName ; 28 29 import junit.framework.TestCase; 30 31 import org.objectweb.petals.jbi.component.context.InstallationContextImpl; 32 import org.objectweb.petals.jbi.component.lifecycle.Installer; 33 34 import static org.easymock.EasyMock.expect; 35 import static org.easymock.EasyMock.expectLastCall; 36 import static org.easymock.classextension.EasyMock.createMock; 37 import static org.easymock.classextension.EasyMock.replay; 38 import static org.easymock.classextension.EasyMock.reset; 39 import static org.easymock.classextension.EasyMock.verify; 40 41 46 public class InstallerThreadTest extends TestCase { 47 48 private BootstrapThread installerThread; 49 50 private Installer installerMock; 51 52 private InstallationContext installContextMock; 53 54 private Bootstrap bootstrapMock; 55 56 60 public void testCleanUp() throws JBIException { 61 installerThread.start(); 62 63 reset(bootstrapMock); 64 bootstrapMock.cleanUp(); 65 expectLastCall(); 66 replay(bootstrapMock); 67 68 try { 69 installerThread.cleanUp(); 70 } catch (JBIException e) { 71 fail(e.getMessage()); 72 } 73 verify(bootstrapMock); 74 } 75 76 80 public void testInit() throws JBIException { 81 installerThread.start(); 82 83 installContextMock = createMock(InstallationContextImpl.class); 84 85 reset(bootstrapMock); 86 87 bootstrapMock.init(installContextMock); 88 expectLastCall(); 89 replay(bootstrapMock); 90 91 try { 92 installerThread.init(installContextMock); 93 } catch (JBIException e) { 94 fail(e.getMessage()); 95 } 96 verify(bootstrapMock); 97 } 98 99 103 public void testOnInstall() throws JBIException { 104 installerThread.start(); 105 106 reset(bootstrapMock); 107 bootstrapMock.onInstall(); 108 expectLastCall(); 109 replay(bootstrapMock); 110 111 try { 112 installerThread.onInstall(); 113 } catch (JBIException e) { 114 fail(e.getMessage()); 115 } 116 verify(bootstrapMock); 117 } 118 119 123 public void testOnUninstall() throws JBIException { 124 installerThread.start(); 125 126 reset(bootstrapMock); 127 bootstrapMock.onUninstall(); 128 expectLastCall(); 129 replay(bootstrapMock); 130 131 try { 132 installerThread.onUninstall(); 133 } catch (JBIException e) { 134 fail(e.getMessage()); 135 } 136 verify(bootstrapMock); 137 } 138 139 143 public void testGetExtensionMBeanName() { 144 installerThread.start(); 145 146 reset(bootstrapMock); 147 ObjectName objectName = createMock(ObjectName .class); 148 expect(bootstrapMock.getExtensionMBeanName()).andReturn(objectName); 149 replay(bootstrapMock); 150 151 ObjectName oName = installerThread.getExtensionMBeanName(); 152 assertEquals(oName, objectName); 153 verify(bootstrapMock); 154 } 155 156 public void testMultipleCalls(){ 157 installerThread.start(); 158 159 try { 160 installerThread.onInstall(); 161 installerThread.onUninstall(); 162 installerThread.onInstall(); 163 installerThread.onUninstall(); 164 installerThread.onInstall(); 165 installerThread.onUninstall(); 166 } catch (JBIException e) { 167 e.printStackTrace(); 169 } 170 } 171 172 177 protected void setUp() throws Exception { 178 super.setUp(); 179 180 installerMock = createMock(Installer.class); 181 bootstrapMock = createMock(Bootstrap.class); 182 expect(installerMock.getComponentName()).andReturn(null); 183 replay(installerMock); 184 185 installerThread = new BootstrapThread(installerMock, bootstrapMock); 186 } 187 188 } 189 | Popular Tags |