KickJava   Java API By Example, From Geeks To Geeks.

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


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.StaticRoutingSlip;
27 import org.apache.servicemix.eip.support.ExchangeTarget;
28
29
30 public class StaticRoutingSlipTest extends AbstractEIPTest {
31
32     protected StaticRoutingSlip routingSlip;
33     
34     protected void setUp() throws Exception JavaDoc {
35         super.setUp();
36
37         routingSlip = new StaticRoutingSlip();
38         routingSlip.setTargets(
39                 new ExchangeTarget[] {
40                         createServiceExchangeTarget(new QName JavaDoc("target1")),
41                         createServiceExchangeTarget(new QName JavaDoc("target2")),
42                         createServiceExchangeTarget(new QName JavaDoc("target3"))
43                 });
44         configurePattern(routingSlip);
45         activateComponent(routingSlip, "routingSlip");
46     }
47
48     public void testInOnly() throws Exception JavaDoc {
49         InOnly me = client.createInOnlyExchange();
50         me.setService(new QName JavaDoc("routingSlip"));
51         me.getInMessage().setContent(createSource("<hello/>"));
52         client.sendSync(me);
53         assertEquals(ExchangeStatus.ERROR, me.getStatus());
54         assertNotNull(me.getError());
55         assertEquals("Use an InOut MEP", me.getError().getMessage());
56     }
57
58     public void testRobustInOnly() throws Exception JavaDoc {
59         RobustInOnly me = client.createRobustInOnlyExchange();
60         me.setService(new QName JavaDoc("routingSlip"));
61         me.getInMessage().setContent(createSource("<hello/>"));
62         client.sendSync(me);
63         assertEquals(ExchangeStatus.ERROR, me.getStatus());
64         assertNotNull(me.getError());
65         assertEquals("Use an InOut MEP", me.getError().getMessage());
66     }
67
68     public void testInOptionalOut() throws Exception JavaDoc {
69         InOptionalOut me = client.createInOptionalOutExchange();
70         me.setService(new QName JavaDoc("routingSlip"));
71         me.getInMessage().setContent(createSource("<hello/>"));
72         client.sendSync(me);
73         assertEquals(ExchangeStatus.ERROR, me.getStatus());
74         assertNotNull(me.getError());
75         assertEquals("Use an InOut MEP", me.getError().getMessage());
76     }
77
78     public void testDone() throws Exception JavaDoc {
79         activateComponent(new ReturnOutComponent(), "target1");
80         activateComponent(new ReturnOutComponent(), "target2");
81         activateComponent(new ReturnOutComponent(), "target3");
82
83         InOut me = client.createInOutExchange();
84         me.setService(new QName JavaDoc("routingSlip"));
85         me.getInMessage().setContent(createSource("<hello/>"));
86         client.sendSync(me);
87         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
88         assertNotNull(me.getOutMessage());
89         client.done(me);
90         
91         listener.assertExchangeCompleted();
92     }
93     
94     public void testFaultOnFirst() throws Exception JavaDoc {
95         activateComponent(new ReturnFaultComponent(), "target1");
96         activateComponent(new ReturnOutComponent(), "target2");
97         activateComponent(new ReturnOutComponent(), "target3");
98
99         InOut me = client.createInOutExchange();
100         me.setService(new QName JavaDoc("routingSlip"));
101         me.getInMessage().setContent(createSource("<hello/>"));
102         client.sendSync(me);
103         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
104         assertNotNull(me.getFault());
105         client.done(me);
106         
107         listener.assertExchangeCompleted();
108     }
109     
110     public void testErrorOnFirst() throws Exception JavaDoc {
111         activateComponent(new ReturnErrorComponent(), "target1");
112         activateComponent(new ReturnOutComponent(), "target2");
113         activateComponent(new ReturnOutComponent(), "target3");
114
115         InOut me = client.createInOutExchange();
116         me.setService(new QName JavaDoc("routingSlip"));
117         me.getInMessage().setContent(createSource("<hello/>"));
118         client.sendSync(me);
119         assertEquals(ExchangeStatus.ERROR, me.getStatus());
120         
121         listener.assertExchangeCompleted();
122     }
123     
124     public void testFaultOnSecond() throws Exception JavaDoc {
125         activateComponent(new ReturnOutComponent(), "target1");
126         activateComponent(new ReturnFaultComponent(), "target2");
127         activateComponent(new ReturnOutComponent(), "target3");
128
129         InOut me = client.createInOutExchange();
130         me.setService(new QName JavaDoc("routingSlip"));
131         me.getInMessage().setContent(createSource("<hello/>"));
132         client.sendSync(me);
133         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
134         assertNotNull(me.getFault());
135         client.done(me);
136         
137         listener.assertExchangeCompleted();
138     }
139     
140     public void testErrorOnSecond() throws Exception JavaDoc {
141         activateComponent(new ReturnOutComponent(), "target1");
142         activateComponent(new ReturnErrorComponent(), "target2");
143         activateComponent(new ReturnOutComponent(), "target3");
144
145         InOut me = client.createInOutExchange();
146         me.setService(new QName JavaDoc("routingSlip"));
147         me.getInMessage().setContent(createSource("<hello/>"));
148         client.sendSync(me);
149         assertEquals(ExchangeStatus.ERROR, me.getStatus());
150         
151         listener.assertExchangeCompleted();
152     }
153     
154     public void testFaultOnThird() throws Exception JavaDoc {
155         activateComponent(new ReturnOutComponent(), "target1");
156         activateComponent(new ReturnOutComponent(), "target2");
157         activateComponent(new ReturnFaultComponent(), "target3");
158
159         InOut me = client.createInOutExchange();
160         me.setService(new QName JavaDoc("routingSlip"));
161         me.getInMessage().setContent(createSource("<hello/>"));
162         client.sendSync(me);
163         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
164         assertNotNull(me.getFault());
165         client.done(me);
166         
167         listener.assertExchangeCompleted();
168     }
169     
170     public void testErrorOnThird() throws Exception JavaDoc {
171         activateComponent(new ReturnOutComponent(), "target1");
172         activateComponent(new ReturnOutComponent(), "target2");
173         activateComponent(new ReturnErrorComponent(), "target3");
174
175         InOut me = client.createInOutExchange();
176         me.setService(new QName JavaDoc("routingSlip"));
177         me.getInMessage().setContent(createSource("<hello/>"));
178         client.sendSync(me);
179         assertEquals(ExchangeStatus.ERROR, me.getStatus());
180         
181         listener.assertExchangeCompleted();
182     }
183     
184
185 }
186
Popular Tags