1 17 package org.apache.servicemix.client; 18 19 import javax.jbi.messaging.ExchangeStatus; 20 import javax.jbi.messaging.InOut; 21 import javax.xml.namespace.QName ; 22 23 import junit.framework.TestCase; 24 25 import org.apache.servicemix.components.util.EchoComponent; 26 import org.apache.servicemix.jbi.container.ActivationSpec; 27 import org.apache.servicemix.jbi.container.JBIContainer; 28 import org.apache.servicemix.jbi.jaxp.StringSource; 29 import org.springframework.jndi.JndiObjectFactoryBean; 30 31 34 public class ClientFactoryTest extends TestCase { 35 36 private JBIContainer jbi; 37 38 protected void setUp() throws Exception { 39 jbi = new JBIContainer(); 40 jbi.setEmbedded(true); 41 jbi.init(); 42 jbi.start(); 43 } 44 45 protected void shutDown() throws Exception { 46 jbi.shutDown(); 47 } 48 49 public void testClientFactory() throws Exception { 50 ActivationSpec as = new ActivationSpec(); 51 as.setId("echo"); 52 as.setComponent(new EchoComponent()); 53 as.setService(new QName ("echo")); 54 jbi.activateComponent(as); 55 56 JndiObjectFactoryBean fb = new JndiObjectFactoryBean(); 57 fb.setJndiName(ClientFactory.DEFAULT_JNDI_NAME); 58 fb.afterPropertiesSet(); 59 ClientFactory cf = (ClientFactory) fb.getObject(); 60 ServiceMixClient client = cf.createClient(); 61 62 Destination dest = client.createDestination("service::echo"); 63 InOut me = dest.createInOutExchange(); 64 me.getInMessage().setContent(new StringSource("<hello>world</hello>")); 65 client.sendSync(me); 66 assertEquals(ExchangeStatus.ACTIVE, me.getStatus()); 67 client.done(me); 68 client.close(); 69 } 70 } 71 | Popular Tags |