1 17 package org.apache.servicemix.examples; 18 19 import javax.jbi.component.Component; 20 21 import junit.framework.TestCase; 22 23 import org.apache.servicemix.components.util.ComponentAdaptor; 24 import org.apache.servicemix.jbi.container.SpringJBIContainer; 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.springframework.context.support.AbstractXmlApplicationContext; 30 31 36 public abstract class AbstractSpringTestSupport extends TestCase { 37 protected SpringJBIContainer jbi; 38 protected AbstractXmlApplicationContext context; 39 protected int messageCount = 1; 40 41 protected void setUp() throws Exception { 42 43 context = createBeanFactory(); 44 46 jbi = (SpringJBIContainer) context.getBean("jbi"); 48 assertNotNull("JBI Container not found in spring!", jbi); 49 50 } 51 52 protected void tearDown() throws Exception { 53 if (context != null) { 54 context.close(); 55 } 56 } 57 58 protected abstract AbstractXmlApplicationContext createBeanFactory(); 59 60 public void testSendingAndReceivingMessagesUsingSpring() throws Exception { 61 Sender sender = getSender(); 62 assertNotNull(sender); 63 assertNotNull(getReceiver()); 64 65 sender.sendMessages(messageCount); 66 67 MessageList messageList = getReceivedMessageList(); 68 messageList.assertMessagesReceived(messageCount); 69 } 70 71 protected Sender getSender() { 72 Object cmp = getComponent("sender"); 73 if (cmp instanceof ComponentAdaptor) { 74 cmp = ((ComponentAdaptor) cmp).getLifeCycle(); 75 } 76 return (Sender) cmp; 77 } 78 79 protected Receiver getReceiver() { 80 Object cmp = getComponent("receiver"); 81 if (cmp instanceof ComponentAdaptor) { 82 cmp = ((ComponentAdaptor) cmp).getLifeCycle(); 83 } 84 return (Receiver) cmp; 85 } 86 87 protected MessageList getReceivedMessageList() { 88 return getReceiver().getMessageList(); 89 } 90 91 protected Component getComponent(String name) { 92 ComponentMBeanImpl lcc = jbi.getComponent(name); 93 return lcc != null ? lcc.getComponent() : null; 94 } 95 96 protected Object getBean(String name) { 97 Object value = jbi.getBean(name); 98 if (value == null) { 99 value = context.getBean(name); 100 } 101 assertNotNull(name + " not found in JBI container!", value); 102 return value; 103 } 104 } 105 | Popular Tags |