1 17 package org.apache.servicemix.eip; 18 19 import javax.jbi.messaging.InOnly; 20 import javax.jbi.messaging.NormalizedMessage; 21 import javax.xml.namespace.QName ; 22 23 import org.apache.servicemix.eip.patterns.SplitAggregator; 24 import org.apache.servicemix.eip.support.AbstractSplitter; 25 import org.apache.servicemix.tck.ReceiverComponent; 26 27 public class SplitAggregatorTest extends AbstractEIPTest { 28 29 private SplitAggregator aggregator; 30 31 protected void setUp() throws Exception { 32 super.setUp(); 33 34 aggregator = new SplitAggregator(); 35 aggregator.setTarget(createServiceExchangeTarget(new QName ("target"))); 36 configurePattern(aggregator); 37 activateComponent(aggregator, "aggregator"); 38 } 39 40 protected NormalizedMessage testRun(boolean[] msgs) throws Exception { 41 ReceiverComponent rec = activateReceiver("target"); 42 43 int nbMessages = 3; 44 String corrId = Long.toString(System.currentTimeMillis()); 45 for (int i = 0; i < 3; i++) { 46 if (msgs == null || msgs[i]) { 47 InOnly me = client.createInOnlyExchange(); 48 me.setService(new QName ("aggregator")); 49 me.getInMessage().setContent(createSource("<hello id='" + i + "' />")); 50 me.getInMessage().setProperty(AbstractSplitter.SPLITTER_COUNT, new Integer (nbMessages)); 51 me.getInMessage().setProperty(AbstractSplitter.SPLITTER_INDEX, new Integer (i)); 52 me.getInMessage().setProperty(AbstractSplitter.SPLITTER_CORRID, corrId); 53 client.send(me); 54 } 55 } 56 57 rec.getMessageList().assertMessagesReceived(1); 58 return (NormalizedMessage) rec.getMessageList().flushMessages().get(0); 59 } 60 61 public void testSimple() throws Exception { 62 aggregator.setTimeout(500); 63 testRun(null); 64 } 65 66 public void testSimpleWithQNames() throws Exception { 67 aggregator.setAggregateElementName(new QName ("uri:test", "agg", "sm")); 68 aggregator.setMessageElementName(new QName ("uri:test", "msg", "sm")); 69 testRun(null); 70 } 71 72 public void testWithTimeout() throws Exception { 73 aggregator.setTimeout(500); 74 testRun(new boolean[] { true, false, true }); 75 } 76 } 77 | Popular Tags |