1 17 package org.apache.servicemix.lwcontainer; 18 19 import org.apache.servicemix.client.DefaultServiceMixClient; 20 import org.apache.servicemix.client.ServiceMixClient; 21 import org.apache.servicemix.jbi.container.JBIContainer; 22 import org.apache.servicemix.lwcontainer.LwContainerComponent; 23 24 import javax.jbi.messaging.InOut; 25 import javax.jbi.messaging.MessagingException; 26 import javax.xml.namespace.QName ; 27 28 import java.io.File ; 29 import java.net.URI ; 30 import java.net.URL ; 31 32 import junit.framework.TestCase; 33 34 38 public class LwContainerComponentTest extends TestCase { 39 protected JBIContainer container = new JBIContainer(); 40 41 private File tempRootDir; 42 43 46 protected void setUp() throws Exception { 47 super.setUp(); 48 container.setCreateMBeanServer(false); 49 container.setMonitorInstallationDirectory(false); 50 tempRootDir = File.createTempFile("servicemix", "rootDir"); 51 tempRootDir.delete(); 52 File tempTemp = new File (tempRootDir.getAbsolutePath() + "/temp"); 53 if (!tempTemp.mkdirs()) 54 fail("Unable to create temporary working root directory [" 55 + tempTemp.getAbsolutePath() + "]"); 56 57 System.out.println("Using temporary root directory [" 58 + tempRootDir.getAbsolutePath() + "]"); 59 60 container.setRootDir(tempRootDir.getAbsolutePath()); 61 container.setMonitorInstallationDirectory(false); 62 container.setUseMBeanServer(false); 63 container.setCreateMBeanServer(false); 64 container.setFlowName("st"); 65 container.init(); 66 container.start(); 67 } 68 69 public void testComponentInstallation() throws Exception { 70 LwContainerComponent component = new LwContainerComponent(); 71 container.activateComponent(component, "#ServiceMixComponent#"); 72 URL url = getClass().getResource("su1-src/servicemix.xml"); 73 File path = new File (new URI (url.toString())); 74 path = path.getParentFile(); 75 ServiceMixClient client = new DefaultServiceMixClient(container); 76 77 for (int i = 0; i < 2; i++) { 78 component.getServiceUnitManager().deploy("su1", path.getAbsolutePath()); 80 component.getServiceUnitManager().init("su1", path.getAbsolutePath()); 81 component.getServiceUnitManager().start("su1"); 82 83 InOut inout = client.createInOutExchange(); 85 inout.setService(new QName ("http://servicemix.apache.org/demo/", "chained")); 86 client.send(inout); 87 88 component.getServiceUnitManager().stop("su1"); 90 component.getServiceUnitManager().shutDown("su1"); 91 component.getServiceUnitManager().undeploy("su1", path.getAbsolutePath()); 92 93 inout = client.createInOutExchange(); 95 inout.setService(new QName ("http://servicemix.apache.org/demo/", "chained")); 96 try { 97 client.send(inout); 98 } catch (MessagingException e) { 99 } 101 102 } 103 } 104 105 108 109 protected void tearDown() throws Exception { 110 super.tearDown(); 111 container.stop(); 112 container.shutDown(); 113 deleteDir(tempRootDir); 114 } 115 116 public static boolean deleteDir(File dir) { 117 System.out.println("Deleting directory : " + dir.getAbsolutePath()); 118 if (dir.isDirectory()) { 119 String [] children = dir.list(); 120 for (int i = 0; i < children.length; i++) { 121 boolean success = deleteDir(new File (dir, children[i])); 122 if (!success) { 123 return false; 124 } 125 } 126 } 127 return dir.delete(); 129 } 130 } 131 | Popular Tags |