KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > eip > SplitAggregatorTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

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 JavaDoc;
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 JavaDoc {
32         super.setUp();
33
34         aggregator = new SplitAggregator();
35         aggregator.setTarget(createServiceExchangeTarget(new QName JavaDoc("target")));
36         configurePattern(aggregator);
37         activateComponent(aggregator, "aggregator");
38     }
39     
40     protected NormalizedMessage testRun(boolean[] msgs) throws Exception JavaDoc {
41         ReceiverComponent rec = activateReceiver("target");
42         
43         int nbMessages = 3;
44         String JavaDoc 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 JavaDoc("aggregator"));
49                 me.getInMessage().setContent(createSource("<hello id='" + i + "' />"));
50                 me.getInMessage().setProperty(AbstractSplitter.SPLITTER_COUNT, new Integer JavaDoc(nbMessages));
51                 me.getInMessage().setProperty(AbstractSplitter.SPLITTER_INDEX, new Integer JavaDoc(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 JavaDoc {
62         aggregator.setTimeout(500);
63         testRun(null);
64     }
65     
66     public void testSimpleWithQNames() throws Exception JavaDoc {
67         aggregator.setAggregateElementName(new QName JavaDoc("uri:test", "agg", "sm"));
68         aggregator.setMessageElementName(new QName JavaDoc("uri:test", "msg", "sm"));
69         testRun(null);
70     }
71     
72     public void testWithTimeout() throws Exception JavaDoc {
73         aggregator.setTimeout(500);
74         testRun(new boolean[] { true, false, true });
75     }
76 }
77
Popular Tags