1 22 package org.objectweb.petals.binding.xquarebc; 23 24 import java.io.File ; 25 26 import javax.jbi.JBIException; 27 import javax.jbi.component.InstallationContext; 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.verify; 34 35 44 public class XQuareBCBootstrapImplTest extends TestCase { 45 File installationRoot = null; 46 47 private String baseDir; 48 49 public void testCleanUp() { 50 51 XQuareBCBootstrapImpl xquareBCBootstrap = new XQuareBCBootstrapImpl(); 52 53 try { 55 xquareBCBootstrap.cleanUp(); 56 } catch (JBIException e) { 57 e.printStackTrace(); 58 fail("Error in SMTPBCBootstrap clean up"); 59 } 60 } 61 62 public void testGetExtensionMBeanName() { 63 XQuareBCBootstrapImpl xquareBCBootstrap = new XQuareBCBootstrapImpl(); 65 66 Object result = null; 68 result = xquareBCBootstrap.getExtensionMBeanName(); 69 assertNull("Result of invocation should be null", result); 70 } 71 72 public void testInit() { 73 InstallationContext installationContext = createMock(InstallationContext.class); 75 expect(installationContext.getInstallRoot()).andReturn( 77 installationRoot.getAbsolutePath()); 78 replay(installationContext); 79 80 XQuareBCBootstrapImpl xquareBCBootstrap = new XQuareBCBootstrapImpl(); 81 try { 83 xquareBCBootstrap.init(installationContext); 84 } catch (JBIException e) { 85 e.printStackTrace(); 86 fail("Error in XQuareBCBootstrapImpl init method"); 87 } 88 89 assertEquals(xquareBCBootstrap.context, installationContext); 90 } 91 92 public void testOnInstall() { 93 InstallationContext installationContext = createMock(InstallationContext.class); 95 XQuareBCBootstrapImpl xquareBCBootstrap = new XQuareBCBootstrapImpl(); 97 try { 99 xquareBCBootstrap.init(installationContext); 100 } catch (JBIException e) { 101 e.printStackTrace(); 102 fail("Error in XQuareBCBootstrapImpl onInstall method"); 103 } 104 } 105 106 public void testOnUninstall() { 107 InstallationContext installationContext = createMock(InstallationContext.class); 109 expect(installationContext.getInstallRoot()).andReturn( 111 installationRoot.getAbsolutePath()).anyTimes(); 112 replay(installationContext); 113 114 XQuareBCBootstrapImpl xquareBCBootstrap = new XQuareBCBootstrapImpl(); 115 try { 117 xquareBCBootstrap.init(installationContext); 118 xquareBCBootstrap.onInstall(); 119 } catch (JBIException e) { 120 e.printStackTrace(); 121 fail("Error in XQuareBCBootstrapImpl init or onUninstall method"); 122 } 123 124 try { 126 xquareBCBootstrap.onUninstall(); 127 } catch (JBIException e) { 128 e.printStackTrace(); 129 fail("Error in XQuareBCBootstrapImpl onuninstall method"); 130 } 131 verify(installationContext); 132 File certDir = new File (installationRoot.getAbsolutePath() 133 + File.separator + "certificate"); 134 assertFalse(certDir.exists()); 135 } 136 137 @Override 138 protected void finalize() throws Throwable { 139 File file = installationRoot.getParentFile(); 140 File [] files = file.listFiles(); 141 for (File files2 : files) { 142 if (("bootstrap").equals(files2.getName())) { 143 if (files2.listFiles().length == 0) { 144 files2.delete(); 145 } 146 } 147 } 148 super.finalize(); 149 } 150 151 @Override 152 protected void setUp() throws Exception { 153 baseDir = this.getClass().getResource(".").toString(); 154 baseDir = baseDir.substring(0, baseDir.indexOf("target")); 155 baseDir = baseDir.substring(baseDir.indexOf(":") + 1); 156 installationRoot = new File (baseDir + File.separator + "src" 157 + File.separator + "test-data" + File.separator + "bootstrap"); 158 installationRoot.mkdirs(); 159 160 } 161 162 } 163 | Popular Tags |