KickJava   Java API By Example, From Geeks To Geeks.

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


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.ExchangeStatus;
20 import javax.jbi.messaging.InOnly;
21 import javax.jbi.messaging.InOptionalOut;
22 import javax.jbi.messaging.InOut;
23 import javax.jbi.messaging.RobustInOnly;
24 import javax.xml.namespace.QName JavaDoc;
25
26 import org.apache.servicemix.eip.patterns.StaticRecipientList;
27 import org.apache.servicemix.eip.support.ExchangeTarget;
28 import org.apache.servicemix.tck.ReceiverComponent;
29
30 public class StaticRecipientListTest extends AbstractEIPTest {
31
32     protected StaticRecipientList recipientList;
33     
34     protected void setUp() throws Exception JavaDoc {
35         super.setUp();
36
37         recipientList = new StaticRecipientList();
38         recipientList.setRecipients(
39                 new ExchangeTarget[] {
40                         createServiceExchangeTarget(new QName JavaDoc("recipient1")),
41                         createServiceExchangeTarget(new QName JavaDoc("recipient2")),
42                         createServiceExchangeTarget(new QName JavaDoc("recipient3"))
43                 });
44         configurePattern(recipientList);
45         activateComponent(recipientList, "recipientList");
46     }
47
48     public void testInOut() throws Exception JavaDoc {
49         InOut me = client.createInOutExchange();
50         me.setService(new QName JavaDoc("recipientList"));
51         me.getInMessage().setContent(createSource("<hello/>"));
52         client.sendSync(me);
53         assertEquals(ExchangeStatus.ERROR, me.getStatus());
54     }
55     
56     public void testInOptionalOut() throws Exception JavaDoc {
57         InOptionalOut me = client.createInOptionalOutExchange();
58         me.setService(new QName JavaDoc("recipientList"));
59         me.getInMessage().setContent(createSource("<hello/>"));
60         client.sendSync(me);
61         assertEquals(ExchangeStatus.ERROR, me.getStatus());
62     }
63     
64     public void testInOnly() throws Exception JavaDoc {
65         ReceiverComponent r1 = activateReceiver("recipient1");
66         ReceiverComponent r2 = activateReceiver("recipient2");
67         ReceiverComponent r3 = activateReceiver("recipient3");
68         
69         InOnly me = client.createInOnlyExchange();
70         me.setService(new QName JavaDoc("recipientList"));
71         me.getInMessage().setContent(createSource("<hello/>"));
72         client.sendSync(me);
73         assertEquals(ExchangeStatus.DONE, me.getStatus());
74         
75         r1.getMessageList().assertMessagesReceived(1);
76         r2.getMessageList().assertMessagesReceived(1);
77         r3.getMessageList().assertMessagesReceived(1);
78     }
79     
80     public void testRobustInOnly() throws Exception JavaDoc {
81         ReceiverComponent r1 = activateReceiver("recipient1");
82         ReceiverComponent r2 = activateReceiver("recipient2");
83         ReceiverComponent r3 = activateReceiver("recipient3");
84         
85         RobustInOnly me = client.createRobustInOnlyExchange();
86         me.setService(new QName JavaDoc("recipientList"));
87         me.getInMessage().setContent(createSource("<hello/>"));
88         client.sendSync(me);
89         assertEquals(ExchangeStatus.DONE, me.getStatus());
90         
91         r1.getMessageList().assertMessagesReceived(1);
92         r2.getMessageList().assertMessagesReceived(1);
93         r3.getMessageList().assertMessagesReceived(1);
94     }
95     
96 }
97
Popular Tags