1 17 package org.apache.servicemix.jsr181; 18 19 import java.io.File ; 20 import java.net.URL ; 21 22 import javax.jbi.messaging.ExchangeStatus; 23 import javax.jbi.messaging.InOut; 24 import javax.naming.InitialContext ; 25 import javax.xml.namespace.QName ; 26 27 import junit.framework.TestCase; 28 29 import org.apache.servicemix.client.DefaultServiceMixClient; 30 import org.apache.servicemix.jbi.container.JBIContainer; 31 import org.apache.servicemix.jbi.jaxp.StringSource; 32 33 public class Jsr181ProxySUTest extends TestCase { 34 35 protected JBIContainer container; 36 37 protected void setUp() throws Exception { 38 container = new JBIContainer(); 39 container.setUseMBeanServer(false); 40 container.setCreateMBeanServer(false); 41 container.setMonitorInstallationDirectory(false); 42 container.setNamingContext(new InitialContext ()); 43 container.setEmbedded(true); 44 container.init(); 45 } 46 47 protected void tearDown() throws Exception { 48 if (container != null) { 49 container.shutDown(); 50 } 51 } 52 53 public void test() throws Exception { 54 Jsr181Component component = new Jsr181Component(); 55 container.activateComponent(component, "JSR181Component"); 56 57 container.start(); 59 60 component.getServiceUnitManager().deploy("target", getServiceUnitPath("target")); 62 component.getServiceUnitManager().init("target", getServiceUnitPath("target")); 63 component.getServiceUnitManager().start("target"); 64 65 component.getServiceUnitManager().deploy("proxy", getServiceUnitPath("proxy")); 66 component.getServiceUnitManager().init("proxy", getServiceUnitPath("proxy")); 67 component.getServiceUnitManager().start("proxy"); 68 69 DefaultServiceMixClient client = new DefaultServiceMixClient(container); 70 InOut me = client.createInOutExchange(new QName ("http://test", "Echo"), null, null); 71 me.setInMessage(me.createMessage()); 72 me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><msg>world</msg></echo>")); 73 client.sendSync(me); 74 assertEquals(ExchangeStatus.ACTIVE, me.getStatus()); 75 assertNotNull(me.getOutMessage()); 76 client.done(me); 77 } 78 79 protected String getServiceUnitPath(String name) { 80 URL url = getClass().getClassLoader().getResource(name + "/xbean.xml"); 81 File path = new File (url.getFile()); 82 path = path.getParentFile(); 83 return path.getAbsolutePath(); 84 } 85 86 } 87 | Popular Tags |