1 22 package org.objectweb.petals.engine.csv; 23 24 import static org.easymock.EasyMock.expect; 25 import static org.easymock.classextension.EasyMock.createMock; 26 import static org.easymock.classextension.EasyMock.replay; 27 import static org.easymock.classextension.EasyMock.verify; 28 29 import java.io.File ; 30 31 import javax.jbi.JBIException; 32 import javax.jbi.component.InstallationContext; 33 34 import org.objectweb.petals.engine.csv.CsvBootstrapImpl; 35 36 import junit.framework.TestCase; 37 38 39 46 public class CsvBootstrapImplTest extends TestCase { 47 48 File installationRoot = null; 49 50 private String baseDir; 51 52 53 public void testCleanUp() { 54 CsvBootstrapImpl csvBootstrap = new CsvBootstrapImpl(); 55 56 try { 58 csvBootstrap.cleanUp(); 59 } catch (JBIException e) { 60 e.printStackTrace(); 61 fail("Error in CsvBootstrap clean up"); 62 } 63 } 64 65 66 public void testGetExtensionMBeanName() { 67 CsvBootstrapImpl csvBootstrap = new CsvBootstrapImpl(); 69 70 Object result = null; 72 result = csvBootstrap.getExtensionMBeanName(); 73 assertNull("Result of invocation should be null", result); 74 } 75 76 77 public void testInit() { 78 InstallationContext installationContext = createMock(InstallationContext.class); 80 expect(installationContext.getInstallRoot()).andReturn( 82 installationRoot.getAbsolutePath()); 83 replay(installationContext); 84 85 CsvBootstrapImpl csvBootstrap = new CsvBootstrapImpl(); 86 try { 88 csvBootstrap.init(installationContext); 89 } catch (JBIException e) { 90 e.printStackTrace(); 91 fail("Error in CsvBootstrap init method"); 92 } 93 94 assertEquals(csvBootstrap.installContext , installationContext); 95 } 96 97 98 public void testOnInstall() { 99 InstallationContext installationContext = createMock(InstallationContext.class); 101 CsvBootstrapImpl csvBootstrap = new CsvBootstrapImpl(); 103 try { 105 csvBootstrap.init(installationContext); 106 } catch (JBIException e) { 107 e.printStackTrace(); 108 fail("Error in CsvBootstrap onInstall method"); 109 } 110 } 111 112 113 public void testOnUninstall() { 114 InstallationContext installationContext = createMock(InstallationContext.class); 116 expect(installationContext.getInstallRoot()).andReturn( 118 installationRoot.getAbsolutePath()).anyTimes(); 119 expect(installationContext.getInstallationDescriptorExtension()).andReturn( 120 null); 121 replay(installationContext); 122 123 CsvBootstrapImpl csvBootstrap = new CsvBootstrapImpl(); 124 try { 126 csvBootstrap.init(installationContext); 127 csvBootstrap.onInstall(); 128 } catch (JBIException e) { 129 e.printStackTrace(); 130 fail("Error in CsvBootstrap init or onUninstall method"); 131 } 132 133 try { 135 csvBootstrap.onUninstall(); 136 } catch (JBIException e) { 137 e.printStackTrace(); 138 fail("Error in CsvBootstrap onuninstall method"); 139 } 140 verify(installationContext); 141 } 142 143 144 @Override 145 protected void setUp() throws Exception { 146 baseDir = this.getClass().getResource(".").toString(); 147 baseDir = baseDir.substring(0, baseDir.indexOf("target")); 148 baseDir = baseDir.substring(baseDir.indexOf(":") + 1); 149 installationRoot = new File (baseDir + File.separator + "src" 150 + File.separator + "test-data" + File.separator + "bootstrap"); 151 } 152 153 } 154 155 156 | Popular Tags |