KickJava   Java API By Example, From Geeks To Geeks.

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


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.Fault;
21 import javax.jbi.messaging.InOnly;
22 import javax.jbi.messaging.InOptionalOut;
23 import javax.jbi.messaging.InOut;
24 import javax.jbi.messaging.RobustInOnly;
25 import javax.xml.namespace.QName JavaDoc;
26
27 import org.apache.servicemix.eip.patterns.WireTap;
28 import org.apache.servicemix.tck.ReceiverComponent;
29
30 public class WireTapTest extends AbstractEIPTest {
31
32     protected ReceiverComponent inReceiver;
33     protected ReceiverComponent outReceiver;
34     protected ReceiverComponent faultReceiver;
35     protected WireTap wireTap;
36     
37     protected void setUp() throws Exception JavaDoc {
38         super.setUp();
39         
40         inReceiver = activateReceiver("in");
41         outReceiver = activateReceiver("out");
42         faultReceiver = activateReceiver("fault");
43         wireTap = new WireTap();
44         wireTap.setInListener(createServiceExchangeTarget(new QName JavaDoc("in")));
45         wireTap.setOutListener(createServiceExchangeTarget(new QName JavaDoc("out")));
46         wireTap.setFaultListener(createServiceExchangeTarget(new QName JavaDoc("fault")));
47         wireTap.setTarget(createServiceExchangeTarget(new QName JavaDoc("target")));
48         configurePattern(wireTap);
49         activateComponent(wireTap, "wireTap");
50     }
51     
52     public void testInOnly() throws Exception JavaDoc {
53         ReceiverComponent target = activateReceiver("target");
54
55         InOnly me = client.createInOnlyExchange();
56         me.setService(new QName JavaDoc("wireTap"));
57         me.getInMessage().setContent(createSource("<hello/>"));
58         client.sendSync(me);
59         assertEquals(ExchangeStatus.DONE, me.getStatus());
60         
61         target.getMessageList().assertMessagesReceived(1);
62         inReceiver.getMessageList().assertMessagesReceived(1);
63         outReceiver.getMessageList().assertMessagesReceived(0);
64         faultReceiver.getMessageList().assertMessagesReceived(0);
65         
66         listener.assertExchangeCompleted();
67     }
68     
69     public void testInOnlyWithError() throws Exception JavaDoc {
70         activateComponent(new ReturnErrorComponent(), "target");
71
72         InOnly me = client.createInOnlyExchange();
73         me.setService(new QName JavaDoc("wireTap"));
74         me.getInMessage().setContent(createSource("<hello/>"));
75         client.sendSync(me);
76         assertEquals(ExchangeStatus.ERROR, me.getStatus());
77         
78         inReceiver.getMessageList().assertMessagesReceived(1);
79         outReceiver.getMessageList().assertMessagesReceived(0);
80         faultReceiver.getMessageList().assertMessagesReceived(0);
81         
82         listener.assertExchangeCompleted();
83     }
84     
85     public void testRobustInOnly() throws Exception JavaDoc {
86         ReceiverComponent target = activateReceiver("target");
87
88         RobustInOnly me = client.createRobustInOnlyExchange();
89         me.setService(new QName JavaDoc("wireTap"));
90         me.getInMessage().setContent(createSource("<hello/>"));
91         client.sendSync(me);
92         assertEquals(ExchangeStatus.DONE, me.getStatus());
93         
94         target.getMessageList().assertMessagesReceived(1);
95         inReceiver.getMessageList().assertMessagesReceived(1);
96         outReceiver.getMessageList().assertMessagesReceived(0);
97         faultReceiver.getMessageList().assertMessagesReceived(0);
98         
99         listener.assertExchangeCompleted();
100     }
101     
102     public void testRobustInOnlyWithError() throws Exception JavaDoc {
103         activateComponent(new ReturnErrorComponent(), "target");
104         
105         RobustInOnly me = client.createRobustInOnlyExchange();
106         me.setService(new QName JavaDoc("wireTap"));
107         me.getInMessage().setContent(createSource("<hello/>"));
108         client.sendSync(me);
109         assertEquals(ExchangeStatus.ERROR, me.getStatus());
110         
111         inReceiver.getMessageList().assertMessagesReceived(1);
112         outReceiver.getMessageList().assertMessagesReceived(0);
113         faultReceiver.getMessageList().assertMessagesReceived(0);
114         
115         listener.assertExchangeCompleted();
116     }
117     
118     public void testRobustInOnlyWithFault() throws Exception JavaDoc {
119         activateComponent(new ReturnFaultComponent(), "target");
120         
121         RobustInOnly me = client.createRobustInOnlyExchange();
122         me.setService(new QName JavaDoc("wireTap"));
123         me.getInMessage().setContent(createSource("<hello/>"));
124         client.sendSync(me);
125         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
126         assertNotNull(me.getFault());
127         client.done(me);
128         
129         inReceiver.getMessageList().assertMessagesReceived(1);
130         outReceiver.getMessageList().assertMessagesReceived(0);
131         faultReceiver.getMessageList().assertMessagesReceived(1);
132         
133         listener.assertExchangeCompleted();
134     }
135     
136     public void testRobustInOnlyWithFaultAndError() throws Exception JavaDoc {
137         activateComponent(new ReturnFaultComponent(), "target");
138         
139         RobustInOnly me = client.createRobustInOnlyExchange();
140         me.setService(new QName JavaDoc("wireTap"));
141         me.getInMessage().setContent(createSource("<hello/>"));
142         client.sendSync(me);
143         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
144         assertNotNull(me.getFault());
145         client.fail(me, new Exception JavaDoc("I do not like faults"));
146         
147         inReceiver.getMessageList().assertMessagesReceived(1);
148         outReceiver.getMessageList().assertMessagesReceived(0);
149         faultReceiver.getMessageList().assertMessagesReceived(1);
150         
151         listener.assertExchangeCompleted();
152     }
153     
154     public void testInOut() throws Exception JavaDoc {
155         activateComponent(new ReturnOutComponent(), "target");
156
157         InOut me = client.createInOutExchange();
158         me.setService(new QName JavaDoc("wireTap"));
159         me.getInMessage().setContent(createSource("<hello/>"));
160         client.sendSync(me);
161         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
162         assertNotNull(me.getOutMessage());
163         client.done(me);
164         
165         inReceiver.getMessageList().assertMessagesReceived(1);
166         outReceiver.getMessageList().assertMessagesReceived(1);
167         faultReceiver.getMessageList().assertMessagesReceived(0);
168         
169         listener.assertExchangeCompleted();
170     }
171     
172     public void testInOutWithError() throws Exception JavaDoc {
173         activateComponent(new ReturnErrorComponent(), "target");
174
175         InOut me = client.createInOutExchange();
176         me.setService(new QName JavaDoc("wireTap"));
177         me.getInMessage().setContent(createSource("<hello/>"));
178         client.sendSync(me);
179         assertEquals(ExchangeStatus.ERROR, me.getStatus());
180         
181         inReceiver.getMessageList().assertMessagesReceived(1);
182         outReceiver.getMessageList().assertMessagesReceived(0);
183         faultReceiver.getMessageList().assertMessagesReceived(0);
184         
185         listener.assertExchangeCompleted();
186     }
187     
188     public void testInOutWithFault() throws Exception JavaDoc {
189         activateComponent(new ReturnFaultComponent(), "target");
190
191         InOut me = client.createInOutExchange();
192         me.setService(new QName JavaDoc("wireTap"));
193         me.getInMessage().setContent(createSource("<hello/>"));
194         client.sendSync(me);
195         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
196         assertNotNull(me.getFault());
197         client.done(me);
198         
199         inReceiver.getMessageList().assertMessagesReceived(1);
200         outReceiver.getMessageList().assertMessagesReceived(0);
201         faultReceiver.getMessageList().assertMessagesReceived(1);
202         
203         listener.assertExchangeCompleted();
204     }
205     
206     public void testInOutAnswerAndError() throws Exception JavaDoc {
207         activateComponent(new ReturnOutComponent(), "target");
208
209         InOut me = client.createInOutExchange();
210         me.setService(new QName JavaDoc("wireTap"));
211         me.getInMessage().setContent(createSource("<hello/>"));
212         client.sendSync(me);
213         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
214         assertNotNull(me.getOutMessage());
215         client.fail(me, new Exception JavaDoc("I do not like your answer"));
216         
217         inReceiver.getMessageList().assertMessagesReceived(1);
218         outReceiver.getMessageList().assertMessagesReceived(1);
219         faultReceiver.getMessageList().assertMessagesReceived(0);
220         
221         listener.assertExchangeCompleted();
222     }
223     
224     public void testInOutFaultAndError() throws Exception JavaDoc {
225         activateComponent(new ReturnFaultComponent(), "target");
226
227         InOut me = client.createInOutExchange();
228         me.setService(new QName JavaDoc("wireTap"));
229         me.getInMessage().setContent(createSource("<hello/>"));
230         client.sendSync(me);
231         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
232         assertNotNull(me.getFault());
233         client.fail(me, new Exception JavaDoc("I do not like your fault"));
234         
235         inReceiver.getMessageList().assertMessagesReceived(1);
236         outReceiver.getMessageList().assertMessagesReceived(0);
237         faultReceiver.getMessageList().assertMessagesReceived(1);
238         
239         listener.assertExchangeCompleted();
240     }
241     
242     public void testInOptionalOutNoAnswer() throws Exception JavaDoc {
243         activateComponent(new ReceiverComponent(), "target");
244
245         InOptionalOut me = client.createInOptionalOutExchange();
246         me.setService(new QName JavaDoc("wireTap"));
247         me.getInMessage().setContent(createSource("<hello/>"));
248         client.sendSync(me);
249         assertEquals(ExchangeStatus.DONE, me.getStatus());
250         
251         inReceiver.getMessageList().assertMessagesReceived(1);
252         outReceiver.getMessageList().assertMessagesReceived(0);
253         faultReceiver.getMessageList().assertMessagesReceived(0);
254         
255         listener.assertExchangeCompleted();
256     }
257     
258     public void testInOptionalOutWithAnswer() throws Exception JavaDoc {
259         activateComponent(new ReturnOutComponent(), "target");
260
261         InOptionalOut me = client.createInOptionalOutExchange();
262         me.setService(new QName JavaDoc("wireTap"));
263         me.getInMessage().setContent(createSource("<hello/>"));
264         client.sendSync(me);
265         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
266         assertNotNull(me.getOutMessage());
267         client.done(me);
268         
269         inReceiver.getMessageList().assertMessagesReceived(1);
270         outReceiver.getMessageList().assertMessagesReceived(1);
271         faultReceiver.getMessageList().assertMessagesReceived(0);
272         
273         listener.assertExchangeCompleted();
274     }
275     
276     public void testInOptionalOutWithFault() throws Exception JavaDoc {
277         activateComponent(new ReturnFaultComponent(), "target");
278
279         InOptionalOut me = client.createInOptionalOutExchange();
280         me.setService(new QName JavaDoc("wireTap"));
281         me.getInMessage().setContent(createSource("<hello/>"));
282         client.sendSync(me);
283         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
284         assertNotNull(me.getFault());
285         client.done(me);
286         
287         inReceiver.getMessageList().assertMessagesReceived(1);
288         outReceiver.getMessageList().assertMessagesReceived(0);
289         faultReceiver.getMessageList().assertMessagesReceived(1);
290         
291         listener.assertExchangeCompleted();
292     }
293     
294     public void testInOptionalOutWithError() throws Exception JavaDoc {
295         activateComponent(new ReturnErrorComponent(), "target");
296
297         InOptionalOut me = client.createInOptionalOutExchange();
298         me.setService(new QName JavaDoc("wireTap"));
299         me.getInMessage().setContent(createSource("<hello/>"));
300         client.sendSync(me);
301         assertEquals(ExchangeStatus.ERROR, me.getStatus());
302         
303         inReceiver.getMessageList().assertMessagesReceived(1);
304         outReceiver.getMessageList().assertMessagesReceived(0);
305         faultReceiver.getMessageList().assertMessagesReceived(0);
306         
307         listener.assertExchangeCompleted();
308     }
309     
310     public void testInOptionalOutWithFaultAndError() throws Exception JavaDoc {
311         activateComponent(new ReturnFaultComponent(), "target");
312
313         InOptionalOut me = client.createInOptionalOutExchange();
314         me.setService(new QName JavaDoc("wireTap"));
315         me.getInMessage().setContent(createSource("<hello/>"));
316         client.sendSync(me);
317         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
318         assertNotNull(me.getFault());
319         client.fail(me, new Exception JavaDoc("I do not like faults"));
320         
321         inReceiver.getMessageList().assertMessagesReceived(1);
322         outReceiver.getMessageList().assertMessagesReceived(0);
323         faultReceiver.getMessageList().assertMessagesReceived(1);
324         
325         listener.assertExchangeCompleted();
326     }
327     
328     public void testInOptionalOutWithAnswerAndFault() throws Exception JavaDoc {
329         activateComponent(new ReturnOutComponent(), "target");
330
331         InOptionalOut me = client.createInOptionalOutExchange();
332         me.setService(new QName JavaDoc("wireTap"));
333         me.getInMessage().setContent(createSource("<hello/>"));
334         client.sendSync(me);
335         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
336         assertNotNull(me.getOutMessage());
337         Fault fault = me.createFault();
338         fault.setContent(createSource("<fault/>"));
339         me.setFault(fault);
340         client.sendSync(me);
341         assertEquals(ExchangeStatus.DONE, me.getStatus());
342         
343         inReceiver.getMessageList().assertMessagesReceived(1);
344         outReceiver.getMessageList().assertMessagesReceived(1);
345         faultReceiver.getMessageList().assertMessagesReceived(1);
346         
347         listener.assertExchangeCompleted();
348     }
349     
350     public void testInOptionalOutWithAnswerAndError() throws Exception JavaDoc {
351         activateComponent(new ReturnOutComponent(), "target");
352
353         InOptionalOut me = client.createInOptionalOutExchange();
354         me.setService(new QName JavaDoc("wireTap"));
355         me.getInMessage().setContent(createSource("<hello/>"));
356         client.sendSync(me);
357         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
358         assertNotNull(me.getOutMessage());
359         client.fail(me, new Exception JavaDoc("Dummy error"));
360         assertEquals(ExchangeStatus.ERROR, me.getStatus());
361         
362         inReceiver.getMessageList().assertMessagesReceived(1);
363         outReceiver.getMessageList().assertMessagesReceived(1);
364         faultReceiver.getMessageList().assertMessagesReceived(0);
365         
366         listener.assertExchangeCompleted();
367     }
368     
369     public void testInOptionalOutWithAnswerAndFaultAndError() throws Exception JavaDoc {
370         activateComponent(new ReturnOutAndErrorComponent(), "target");
371
372         InOptionalOut me = client.createInOptionalOutExchange();
373         me.setService(new QName JavaDoc("wireTap"));
374         me.getInMessage().setContent(createSource("<hello/>"));
375         client.sendSync(me);
376         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
377         assertNotNull(me.getOutMessage());
378         Fault fault = me.createFault();
379         fault.setContent(createSource("<fault/>"));
380         me.setFault(fault);
381         client.sendSync(me);
382         assertEquals(ExchangeStatus.ERROR, me.getStatus());
383         
384         inReceiver.getMessageList().assertMessagesReceived(1);
385         outReceiver.getMessageList().assertMessagesReceived(1);
386         faultReceiver.getMessageList().assertMessagesReceived(1);
387         
388         listener.assertExchangeCompleted();
389     }
390     
391 }
392
Popular Tags