1 17 package org.apache.servicemix.components.script; 18 19 import java.util.List ; 20 21 import javax.jbi.component.Component; 22 import javax.jbi.messaging.NormalizedMessage; 23 24 import org.apache.servicemix.components.util.ComponentAdaptor; 25 import org.apache.servicemix.jbi.framework.ComponentMBeanImpl; 26 import org.apache.servicemix.tck.MessageList; 27 import org.apache.servicemix.tck.Receiver; 28 import org.apache.servicemix.tck.Sender; 29 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; 30 import org.springframework.context.support.AbstractXmlApplicationContext; 31 32 35 public class GroovyTransformTest extends org.apache.servicemix.tck.SpringTestSupport { 36 37 public void testSendingAndReceivingMessagesUsingSpring() throws Exception { 38 Sender sender = getSender(); 39 40 sender.sendMessages(messageCount); 41 42 MessageList messageList = getReceivedMessageList(); 43 messageList.assertMessagesReceived(messageCount); 44 45 List list = messageList.getMessages(); 47 NormalizedMessage message = (NormalizedMessage) list.get(0); 48 Object property = message.getProperty("foo"); 49 assertEquals("Message 'foo' header", "hello", property); 50 } 51 52 protected AbstractXmlApplicationContext createBeanFactory() { 53 return new ClassPathXmlApplicationContext("org/apache/servicemix/components/script/groovy-transform.xml"); 54 } 55 56 protected Sender getSender() { 57 Object cmp = getComponent("sender"); 58 if (cmp instanceof ComponentAdaptor) { 59 cmp = ((ComponentAdaptor) cmp).getLifeCycle(); 60 } 61 return (Sender) cmp; 62 } 63 64 protected Receiver getReceiver() { 65 Object cmp = getComponent("receiver"); 66 if (cmp instanceof ComponentAdaptor) { 67 cmp = ((ComponentAdaptor) cmp).getLifeCycle(); 68 } 69 return (Receiver) cmp; 70 } 71 72 protected MessageList getReceivedMessageList() { 73 return getReceiver().getMessageList(); 74 } 75 76 protected Component getComponent(String name) { 77 ComponentMBeanImpl lcc = jbi.getComponent(name); 78 return lcc != null ? lcc.getComponent() : null; 79 } 80 } 81 | Popular Tags |