1 17 package org.apache.servicemix.components.groovy; 18 19 import java.io.StringReader ; 20 21 import javax.jbi.messaging.InOut; 22 import javax.jbi.messaging.NormalizedMessage; 23 import javax.xml.namespace.QName ; 24 import javax.xml.transform.stream.StreamSource ; 25 26 import junit.framework.TestCase; 27 28 import org.apache.servicemix.client.ServiceMixClient; 29 import org.apache.servicemix.jbi.container.SpringJBIContainer; 30 import org.apache.servicemix.jbi.jaxp.SourceTransformer; 31 import org.apache.servicemix.tck.Receiver; 32 import org.springframework.context.support.AbstractXmlApplicationContext; 33 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; 34 35 38 public class GroovyChainTest extends TestCase { 39 protected AbstractXmlApplicationContext context; 40 protected ServiceMixClient client; 41 protected Receiver receiver; 42 43 protected SourceTransformer transformer = new SourceTransformer(); 44 45 46 public void testChain() throws Exception { 49 50 InOut exchange = client.createInOutExchange(); 51 52 NormalizedMessage message = exchange.getInMessage(); 53 message.setContent(new StreamSource (new StringReader ("<hello>world</hello>"))); 54 55 QName service = new QName ("http://servicemix.org/cheese/", "receiver"); 56 exchange.setService(service); 57 client.sendSync(exchange); 58 59 System.out.println(transformer.toString(exchange.getMessage("out").getContent())); 60 } 61 62 63 protected void setUp() throws Exception { 64 context = createBeanFactory(); 65 67 client = (ServiceMixClient) getBean("client"); 68 69 72 SpringJBIContainer jbi = (SpringJBIContainer) getBean("jbi"); 73 assertNotNull(jbi); 74 } 75 76 protected void tearDown() throws Exception { 77 super.tearDown(); 78 79 if (context != null) { 80 context.close(); 81 } 82 } 83 84 protected Object getBean(String name) { 85 Object answer = context.getBean(name); 86 assertNotNull("Could not find object in Spring for key: " + name, answer); 87 return answer; 88 } 89 90 protected AbstractXmlApplicationContext createBeanFactory() { 91 return new ClassPathXmlApplicationContext("org/apache/servicemix/components/groovy/groovy-chain.xml"); 92 93 } 94 } 95 | Popular Tags |