1 17 package org.apache.servicemix.components.splitter; 18 19 import javax.xml.namespace.QName ; 20 21 import junit.framework.TestCase; 22 23 import org.apache.servicemix.jbi.container.ActivationSpec; 24 import org.apache.servicemix.jbi.container.JBIContainer; 25 import org.apache.servicemix.tck.ReceiverComponent; 26 import org.apache.servicemix.tck.SenderComponent; 27 28 public class SplitterComponentTest extends TestCase { 29 private JBIContainer jbiContainer; 30 31 protected SenderComponent sender; 32 33 protected ReceiverComponent receiver; 34 35 protected SplitterComponent fec; 36 37 protected void setUp() throws Exception { 38 jbiContainer = new JBIContainer(); 39 jbiContainer.setUseMBeanServer(false); 40 jbiContainer.setCreateMBeanServer(false); 41 jbiContainer.setFlowName("seda"); 42 jbiContainer.init(); 43 jbiContainer.start(); 44 setUpReceiver(); 45 setUpSender(); 46 setUpComponent(); 47 } 48 49 protected QName getComponentService() { 50 return new QName ("http://www.neogrid.com.br", "component"); 51 } 52 53 private void setUpSender() throws Exception { 54 sender = new SenderComponent(); 55 ActivationSpec as = new ActivationSpec(SenderComponent.ENDPOINT, sender); 56 as.setService(SenderComponent.SERVICE); 57 as.setDestinationService(getComponentService()); 58 jbiContainer.activateComponent(as); 59 } 60 61 private void setUpReceiver() throws Exception { 62 receiver = new ReceiverComponent(); 63 ActivationSpec as = new ActivationSpec(ReceiverComponent.ENDPOINT, 64 receiver); 65 as.setService(ReceiverComponent.SERVICE); 66 jbiContainer.activateComponent(as); 67 } 68 69 private void setUpComponent() throws Exception { 70 fec = new SplitterComponent(); 71 fec.setNodePath(""); 72 ActivationSpec as = new ActivationSpec("component", fec); 73 as.setService(getComponentService()); 74 as.setDestinationService(ReceiverComponent.SERVICE); 75 jbiContainer.activateComponent(as); 76 } 77 78 public void testForEach() throws Exception { 79 fec.setNodePath("ROOT/DOC[@att = 2]"); 80 sender 81 .setMessage("<ROOT><DOC att=\"1\"/><DOC att=\"2\"/><DOC att=\"2\"/></ROOT>"); 82 sender.sendMessages(1); 83 Thread.sleep(1000); 84 assertEquals(2, receiver.getMessageList().getMessageCount()); 85 } 86 87 protected void tearDown() throws Exception { 88 if (jbiContainer != null) 89 jbiContainer.shutDown(); 90 } 91 } 92 | Popular Tags |