1 17 package org.apache.servicemix.jbi.installation; 18 19 import org.apache.servicemix.jbi.container.JBIContainer; 20 21 import java.io.File ; 22 import java.net.URL ; 23 24 import junit.framework.TestCase; 25 26 34 public class ComponentInstallationTest extends TestCase { 35 protected JBIContainer container = new JBIContainer(); 36 37 private File tempRootDir; 38 39 42 protected void setUp() throws Exception { 43 super.setUp(); 44 container.setCreateMBeanServer(true); 45 container.setMonitorInstallationDirectory(true); 46 tempRootDir = File.createTempFile("servicemix", "rootDir"); 47 tempRootDir.delete(); 48 File tempTemp = new File (tempRootDir.getAbsolutePath() + "/temp"); 49 if (!tempTemp.mkdirs()) 50 fail("Unable to create temporary working root directory [" 51 + tempTemp.getAbsolutePath() + "]"); 52 53 System.out.println("Using temporary root directory [" 54 + tempRootDir.getAbsolutePath() + "]"); 55 56 container.setRootDir(tempRootDir.getAbsolutePath()); 57 container.init(); 58 container.start(); 59 60 } 61 62 public void testInstallation() throws Exception { 63 try { 64 URL componentResource = getClass().getClassLoader().getResource( 66 "component-dummy-1.0-jbi-installer.jar"); 67 assertNotNull( 68 "The component JAR component-dummy-1.0-jbi-installer.jar is missing from the classpath", 69 componentResource); 70 container.installArchive(componentResource.toExternalForm()); 71 72 URL assemblyResource = getClass().getClassLoader().getResource( 73 "dummy-assembly.jar"); 74 assertNotNull( 75 "The assembly JAR dummy-assembly.jar is missing from the classpath", 76 assemblyResource); 77 container.installArchive(getClass().getClassLoader().getResource( 78 "dummy-assembly.jar").toExternalForm()); 79 80 } catch (Exception e) { 81 e.printStackTrace(); 82 fail(e.getMessage()); 83 } 84 } 87 88 protected void tearDown() throws Exception { 89 super.tearDown(); 90 container.shutDown(); 91 deleteDir(tempRootDir); 92 } 93 94 public static boolean deleteDir(File dir) { 95 System.out.println("Deleting directory : "+dir.getAbsolutePath()); 96 if (dir.isDirectory()) { 97 String [] children = dir.list(); 98 for (int i = 0; i < children.length; i++) { 99 boolean success = deleteDir(new File (dir, children[i])); 100 if (!success) { 101 return false; 102 } 103 } 104 } 105 106 return dir.delete(); 108 } 109 } 110 | Popular Tags |