1 17 package org.apache.servicemix.jbi.nmr; 18 19 import javax.jbi.messaging.MessageExchange; 20 import javax.xml.namespace.QName ; 21 22 import junit.framework.TestCase; 23 24 import org.apache.servicemix.jbi.container.ActivationSpec; 25 import org.apache.servicemix.jbi.container.JBIContainer; 26 import org.apache.servicemix.jbi.container.SubscriptionSpec; 27 import org.apache.servicemix.jbi.resolver.SubscriptionFilter; 28 import org.apache.servicemix.tck.ReceiverComponent; 29 import org.apache.servicemix.tck.SenderComponent; 30 31 public class PubSubTest extends TestCase { 32 33 private SenderComponent sender; 34 private JBIContainer container; 35 36 protected void setUp() throws Exception { 37 container = new JBIContainer(); 38 container.setEmbedded(true); 39 container.setFlowName("seda"); 40 container.init(); 41 container.start(); 42 43 sender = new SenderComponent(); 44 ActivationSpec as = new ActivationSpec("source",sender); 45 as.setService(new QName ("http://www.test.com","source")); 46 as.setFailIfNoDestinationEndpoint(false); 47 container.activateComponent(as); 48 } 49 50 protected void tearDown() throws Exception { 51 container.shutDown(); 52 } 53 54 public void testPubSub() throws Exception { 55 ReceiverComponent recListener = new ReceiverComponent(); 56 container.activateComponent(createReceiverAS("receiver",recListener)); 57 sender.sendMessages(1); 58 recListener.getMessageList().assertMessagesReceived(1); 59 } 60 61 public void testPubSubFiltered() throws Exception { 62 ReceiverComponent recListener = new ReceiverComponent(); 63 container.activateComponent(createReceiverASFiltered("receiver",recListener)); 64 sender.sendMessages(1, false); 65 recListener.getMessageList().assertMessagesReceived(1); 66 } 67 68 private ActivationSpec createReceiverAS(String id, Object component) { 69 ActivationSpec as = new ActivationSpec(id, component); 70 SubscriptionSpec ss = new SubscriptionSpec(); 71 ss.setService(new QName ("http://www.test.com","source")); 72 as.setSubscriptions(new SubscriptionSpec[] { ss }); 73 as.setFailIfNoDestinationEndpoint(false); 74 return as; 75 } 76 77 private ActivationSpec createReceiverASFiltered(String id, Object component) { 78 ActivationSpec as = new ActivationSpec(id, component); 79 SubscriptionSpec ss = new SubscriptionSpec(); 80 ss.setService(new QName ("http://www.test.com","source")); 81 ss.setFilter(new Filter()); 82 as.setSubscriptions(new SubscriptionSpec[] { ss }); 83 as.setFailIfNoDestinationEndpoint(false); 84 return as; 85 } 86 87 public static class Filter implements SubscriptionFilter { 88 89 public boolean matches(MessageExchange arg0) { 90 System.out.println("Matches"); 91 return true; 92 } 93 94 } 95 } 96 | Popular Tags |