1 17 package org.apache.servicemix.jbi.management.task; 18 19 import java.io.File ; 20 import java.io.FileOutputStream ; 21 import java.io.InputStream ; 22 import java.util.jar.JarOutputStream ; 23 import java.util.zip.ZipEntry ; 24 25 import javax.jbi.JBIException; 26 import javax.jbi.component.Bootstrap; 27 import javax.jbi.component.InstallationContext; 28 import javax.management.ObjectName ; 29 30 import org.apache.servicemix.jbi.installation.AbstractManagementTest; 31 import org.apache.servicemix.jbi.installation.Bootstrap1; 32 import org.apache.servicemix.jbi.util.FileUtil; 33 import org.apache.tools.ant.Project; 34 35 39 public class InstallComponentTaskTest extends JbiTaskSupport { 40 41 42 private InstallComponentTask installComponentTask; 43 private File rootDir = new File ("target/testWDIR"); 44 47 protected void setUp() throws Exception { 48 FileUtil.deleteFile(rootDir); 49 this.container.setRootDir(rootDir.getPath()); 50 super.setUp(); 51 installComponentTask = new InstallComponentTask(){}; 52 installComponentTask.setProject(new Project()); 53 installComponentTask.init(); 54 } 55 56 59 protected void tearDown() throws Exception { 60 installComponentTask.close(); 61 super.tearDown(); 62 } 63 64 public void testInstallation() throws Exception { 65 Bootstrap1.setDelegate(new Bootstrap() { 66 public void cleanUp() throws JBIException { 67 } 68 public ObjectName getExtensionMBeanName() { 69 return null; 70 } 71 public void init(InstallationContext installContext) throws JBIException { 72 } 73 public void onInstall() throws JBIException { 74 } 75 public void onUninstall() throws JBIException { 76 } 77 }); 78 String installJarUrl = createInstallerArchive("component1").getAbsolutePath(); 79 installComponentTask.setFile(installJarUrl); 80 installComponentTask.init(); 81 installComponentTask.execute(); 82 File testFile = new File (rootDir, "components" + File.separator 83 + "component1"); 84 assertTrue(testFile.exists()); 85 FileUtil.deleteFile(rootDir); 86 } 87 88 protected File createInstallerArchive(String jbi) throws Exception { 89 InputStream is = AbstractManagementTest.class.getResourceAsStream(jbi + "-jbi.xml"); 90 File jar = File.createTempFile("jbi", ".zip"); 91 JarOutputStream jos = new JarOutputStream (new FileOutputStream (jar)); 92 jos.putNextEntry(new ZipEntry ("META-INF/jbi.xml")); 93 byte[] buffer = new byte[is.available()]; 94 is.read(buffer); 95 jos.write(buffer); 96 jos.closeEntry(); 97 jos.close(); 98 is.close(); 99 return jar; 100 } 101 } 102 | Popular Tags |