KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > messaging > MEPExchangeTest


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.jbi.messaging;
18
19 import org.apache.servicemix.JbiConstants;
20 import org.apache.servicemix.components.util.ComponentSupport;
21 import org.apache.servicemix.jbi.ExchangeTimeoutException;
22 import org.apache.servicemix.jbi.container.JBIContainer;
23 import org.apache.servicemix.jbi.jaxp.StringSource;
24 import org.apache.servicemix.tck.ExchangeCompletedListener;
25
26 import javax.jbi.messaging.DeliveryChannel;
27 import javax.jbi.messaging.ExchangeStatus;
28 import javax.jbi.messaging.Fault;
29 import javax.jbi.messaging.InOnly;
30 import javax.jbi.messaging.InOptionalOut;
31 import javax.jbi.messaging.InOut;
32 import javax.jbi.messaging.MessageExchangeFactory;
33 import javax.jbi.messaging.MessagingException;
34 import javax.jbi.messaging.NormalizedMessage;
35 import javax.jbi.messaging.RobustInOnly;
36 import javax.jbi.messaging.MessageExchange.Role;
37 import javax.xml.namespace.QName JavaDoc;
38
39 import junit.framework.TestCase;
40
41 public class MEPExchangeTest extends TestCase {
42
43     public static final String JavaDoc PAYLOAD = "<payload/>";
44     public static final String JavaDoc RESPONSE = "<response/>";
45     
46     private JBIContainer container;
47     private TestComponent provider;
48     private TestComponent consumer;
49     private ExchangeCompletedListener listener;
50     
51     public static class TestComponent extends ComponentSupport {
52         public TestComponent(QName JavaDoc service, String JavaDoc endpoint) {
53             super(service, endpoint);
54         }
55         public DeliveryChannel getChannel() throws MessagingException {
56             return getContext().getDeliveryChannel();
57         }
58     }
59     
60     public void setUp() throws Exception JavaDoc {
61         // Create jbi container
62
container = new JBIContainer();
63         container.setEmbedded(true);
64         container.setFlowName("st");
65         listener = new ExchangeCompletedListener();
66         container.addListener(listener);
67         container.init();
68         container.start();
69         // Create components
70
provider = new TestComponent(new QName JavaDoc("provider"), "endpoint");
71         consumer = new TestComponent(new QName JavaDoc("consumer"), "endpoint");
72         // Register components
73
container.activateComponent(provider, "provider");
74         container.activateComponent(consumer, "consumer");
75     }
76     
77     public void tearDown() throws Exception JavaDoc {
78         if (listener != null) {
79             listener.assertExchangeCompleted();
80         }
81         if (container != null) {
82             container.shutDown();
83         }
84         container = null;
85     }
86     
87     public void testInOnly() throws Exception JavaDoc {
88         // Send message exchange
89
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
90         InOnly mec = mef.createInOnlyExchange();
91         NormalizedMessage m = mec.createMessage();
92         m.setContent(new StringSource(PAYLOAD));
93         mec.setInMessage(m);
94         assertEquals(Role.CONSUMER, mec.getRole());
95         try {
96             mec.setMessage(null, "in");
97             fail("Message is null");
98         } catch (Exception JavaDoc e) {
99             // ok
100
}
101         try {
102             mec.setMessage(mec.createMessage(), "in");
103             fail("Message already set");
104         } catch (Exception JavaDoc e) {
105             // ok
106
}
107         try {
108             mec.setMessage(mec.createMessage(), "out");
109             fail("Out not supported");
110         } catch (Exception JavaDoc e) {
111             // ok
112
}
113         try {
114             mec.setMessage(mec.createFault(), "fault");
115             fail("Fault not supported");
116         } catch (Exception JavaDoc e) {
117             // ok
118
}
119         consumer.getChannel().send(mec);
120         try {
121             mec.setProperty("myprop", "myvalue");
122             fail("Component is not owner");
123         } catch (Exception JavaDoc e) {
124             // ok
125
}
126         // Provider side
127
InOnly mep = (InOnly) provider.getChannel().accept(1000L);
128         assertNotNull(mep);
129         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
130         assertEquals(Role.PROVIDER, mep.getRole());
131         mep.setStatus(ExchangeStatus.DONE);
132         provider.getChannel().send(mep);
133         // Consumer side
134
assertSame(mec, consumer.getChannel().accept(1000L));
135         assertEquals(ExchangeStatus.DONE, mec.getStatus());
136         assertEquals(Role.CONSUMER, mec.getRole());
137         // Nothing left
138
assertNull(consumer.getChannel().accept(100L)); // receive in
139
assertNull(provider.getChannel().accept(100L)); // receive in
140
}
141     
142     public void testInOnlyWithError() throws Exception JavaDoc {
143         MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
144         InOnly mec = mef.createInOnlyExchange();
145         NormalizedMessage m = mec.createMessage();
146         m.setContent(new StringSource(PAYLOAD));
147         mec.setInMessage(m);
148         assertEquals(Role.CONSUMER, mec.getRole());
149         consumer.getChannel().send(mec);
150         // Provider side
151
InOnly mep = (InOnly) provider.getChannel().accept(1000L);
152         assertNotNull(mep);
153         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
154         assertEquals(Role.PROVIDER, mep.getRole());
155         mep.setError(new Exception JavaDoc());
156         provider.getChannel().send(mep);
157         // Consumer side
158
assertSame(mec, consumer.getChannel().accept(1000L));
159         assertEquals(ExchangeStatus.ERROR, mec.getStatus());
160         assertEquals(Role.CONSUMER, mec.getRole());
161         // Check we can not send the exchange anymore
162
try {
163             mec.setStatus(ExchangeStatus.DONE);
164             consumer.getChannel().send(mec);
165             fail("Exchange status is ERROR");
166         } catch (Exception JavaDoc e) {
167             // ok
168
}
169         // Nothing left
170
assertNull(consumer.getChannel().accept(100L)); // receive in
171
assertNull(provider.getChannel().accept(100L)); // receive in
172
}
173     
174     public void testInOnlySync() throws Exception JavaDoc {
175         // Create thread to answer
176
new Thread JavaDoc(new Runnable JavaDoc() {
177             public void run() {
178                 try {
179                     // Provider side
180
InOnly mep = (InOnly) provider.getChannel().accept(10000L);
181                     assertNotNull(mep);
182                     assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
183                     assertEquals(Boolean.TRUE, mep.getProperty(JbiConstants.SEND_SYNC));
184                     mep.setStatus(ExchangeStatus.DONE);
185                     provider.getChannel().send(mep);
186                 } catch (Exception JavaDoc e) {
187                     e.printStackTrace();
188                     fail();
189                 }
190             }
191         }).start();
192         // Send message exchange
193
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
194         InOnly mec = mef.createInOnlyExchange();
195         NormalizedMessage m = mec.createMessage();
196         m.setContent(new StringSource(PAYLOAD));
197         mec.setInMessage(m);
198         boolean result = consumer.getChannel().sendSync(mec, 10000L);
199         assertTrue(result);
200         assertEquals(ExchangeStatus.DONE, mec.getStatus());
201         // Nothing left
202
assertNull(consumer.getChannel().accept(100L)); // receive in
203
assertNull(provider.getChannel().accept(100L)); // receive in
204
}
205     
206     public void testInOnlySyncWithTimeoutBeforeAccept() throws Exception JavaDoc {
207         // Send message exchange
208
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
209         InOnly mec = mef.createInOnlyExchange();
210         NormalizedMessage m = mec.createMessage();
211         m.setContent(new StringSource(PAYLOAD));
212         mec.setInMessage(m);
213         boolean result = consumer.getChannel().sendSync(mec, 100L);
214         assertFalse(result);
215         assertEquals(ExchangeStatus.ERROR, mec.getStatus());
216         // Nothing left
217
assertNull(consumer.getChannel().accept(100L)); // receive in
218
assertNull(provider.getChannel().accept(100L)); // receive in
219
}
220     
221     public void testInOnlySyncWithTimeoutAfterAccept() throws Exception JavaDoc {
222         // Create thread to answer
223
Thread JavaDoc t = new Thread JavaDoc(new Runnable JavaDoc() {
224             public void run() {
225                 try {
226                     // Provider side
227
InOnly mep = (InOnly) provider.getChannel().accept(10000L);
228                     assertNotNull(mep);
229                     assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
230                     assertEquals(Boolean.TRUE, mep.getProperty(JbiConstants.SEND_SYNC));
231                     Thread.sleep(100L);
232                     mep.setStatus(ExchangeStatus.DONE);
233                     provider.getChannel().send(mep);
234                 } catch (ExchangeTimeoutException e) {
235                     // ok
236
} catch (Exception JavaDoc e) {
237                     e.printStackTrace();
238                     fail();
239                 }
240             }
241         });
242         t.start();
243         // Send message exchange
244
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
245         InOnly mec = mef.createInOnlyExchange();
246         NormalizedMessage m = mec.createMessage();
247         m.setContent(new StringSource(PAYLOAD));
248         mec.setInMessage(m);
249         boolean result = consumer.getChannel().sendSync(mec, 50L);
250         
251         assertFalse(result);
252         assertEquals(ExchangeStatus.ERROR, mec.getStatus());
253         // Nothing left
254
assertNull(consumer.getChannel().accept(100L)); // receive in
255
t.join();
256     }
257     
258     public void testInOut() throws Exception JavaDoc {
259         // Send message exchange
260
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
261         InOut mec = mef.createInOutExchange();
262         NormalizedMessage m = mec.createMessage();
263         m.setContent(new StringSource(PAYLOAD));
264         mec.setInMessage(m);
265         consumer.getChannel().send(mec);
266         // Provider side
267
InOut mep = (InOut) provider.getChannel().accept(100L);
268         assertNotNull(mep);
269         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
270         m = mep.createMessage();
271         m.setContent(new StringSource(RESPONSE));
272         mep.setOutMessage(m);
273         provider.getChannel().send(mep);
274         // Consumer side
275
assertSame(mec, consumer.getChannel().accept(100L));
276         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
277         mec.setStatus(ExchangeStatus.DONE);
278         consumer.getChannel().send(mec);
279         // Provider site
280
assertSame(mep, provider.getChannel().accept(100L));
281         assertEquals(ExchangeStatus.DONE, mec.getStatus());
282         // Nothing left
283
assertNull(consumer.getChannel().accept(100L)); // receive in
284
assertNull(provider.getChannel().accept(100L)); // receive in
285
}
286     
287     public void testInOutSync() throws Exception JavaDoc {
288         // Create thread to answer
289
new Thread JavaDoc(new Runnable JavaDoc() {
290             public void run() {
291                 try {
292                     // Provider side
293
InOut mep = (InOut) provider.getChannel().accept(10000L);
294                     assertNotNull(mep);
295                     assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
296                     NormalizedMessage m = mep.createMessage();
297                     m.setContent(new StringSource(RESPONSE));
298                     mep.setOutMessage(m);
299                     provider.getChannel().send(mep);
300                 } catch (Exception JavaDoc e) {
301                     e.printStackTrace();
302                     fail();
303                 }
304             }
305         }).start();
306         // Send message exchange
307
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
308         InOut mec = mef.createInOutExchange();
309         NormalizedMessage m = mec.createMessage();
310         m.setContent(new StringSource(PAYLOAD));
311         mec.setInMessage(m);
312         consumer.getChannel().sendSync(mec, 10000L);
313         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
314         mec.setStatus(ExchangeStatus.DONE);
315         consumer.getChannel().send(mec);
316         // Provider site
317
assertNotNull(provider.getChannel().accept(100L));
318         assertEquals(ExchangeStatus.DONE, mec.getStatus());
319         // Nothing left
320
assertNull(consumer.getChannel().accept(100L)); // receive in
321
assertNull(provider.getChannel().accept(100L)); // receive in
322
}
323     
324     public void testInOutSyncSync() throws Exception JavaDoc {
325         // Create thread to answer
326
Thread JavaDoc t = new Thread JavaDoc(new Runnable JavaDoc() {
327             public void run() {
328                 try {
329                     // Provider side
330
InOut mep = (InOut) provider.getChannel().accept(10000L);
331                     assertNotNull(mep);
332                     assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
333                     NormalizedMessage m = mep.createMessage();
334                     m.setContent(new StringSource(RESPONSE));
335                     mep.setOutMessage(m);
336                     provider.getChannel().sendSync(mep);
337                     assertEquals(ExchangeStatus.DONE, mep.getStatus());
338                 } catch (Exception JavaDoc e) {
339                     e.printStackTrace();
340                     fail();
341                 }
342             }
343         });
344         t.start();
345         // Send message exchange
346
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
347         InOut mec = mef.createInOutExchange();
348         NormalizedMessage m = mec.createMessage();
349         m.setContent(new StringSource(PAYLOAD));
350         mec.setInMessage(m);
351         consumer.getChannel().sendSync(mec, 10000L);
352         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
353         mec.setStatus(ExchangeStatus.DONE);
354         consumer.getChannel().send(mec);
355         // Wait until other thread end
356
t.join(100L);
357         // Nothing left
358
assertNull(consumer.getChannel().accept(100L)); // receive in
359
assertNull(provider.getChannel().accept(100L)); // receive in
360
}
361     
362     public void testInOutWithFault() throws Exception JavaDoc {
363         // Send message exchange
364
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
365         InOut mec = mef.createInOutExchange();
366         NormalizedMessage m = mec.createMessage();
367         m.setContent(new StringSource(PAYLOAD));
368         mec.setInMessage(m);
369         consumer.getChannel().send(mec);
370         // Provider side
371
InOut mep = (InOut) provider.getChannel().accept(100L);
372         assertNotNull(mep);
373         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
374         Fault f = mep.createFault();
375         f.setContent(new StringSource(RESPONSE));
376         mep.setFault(f);
377         provider.getChannel().send(mep);
378         // Consumer side
379
assertSame(mec, consumer.getChannel().accept(100L));
380         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
381         assertNotNull(mec.getFault());
382         mec.setStatus(ExchangeStatus.DONE);
383         consumer.getChannel().send(mec);
384         // Provider site
385
assertSame(mep, provider.getChannel().accept(100L));
386         assertEquals(ExchangeStatus.DONE, mec.getStatus());
387         // Nothing left
388
assertNull(consumer.getChannel().accept(100L)); // receive in
389
assertNull(provider.getChannel().accept(100L)); // receive in
390
}
391     
392     public void testInOutWithFaultAndError() throws Exception JavaDoc {
393         // Send message exchange
394
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
395         InOut mec = mef.createInOutExchange();
396         NormalizedMessage m = mec.createMessage();
397         m.setContent(new StringSource(PAYLOAD));
398         mec.setInMessage(m);
399         consumer.getChannel().send(mec);
400         // Provider side
401
InOut mep = (InOut) provider.getChannel().accept(100L);
402         assertNotNull(mep);
403         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
404         Fault f = mep.createFault();
405         f.setContent(new StringSource(RESPONSE));
406         mep.setFault(f);
407         provider.getChannel().send(mep);
408         // Consumer side
409
assertSame(mec, consumer.getChannel().accept(100L));
410         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
411         assertNotNull(mec.getFault());
412         mec.setStatus(ExchangeStatus.ERROR);
413         consumer.getChannel().send(mec);
414         // Provider site
415
assertSame(mep, provider.getChannel().accept(100L));
416         assertEquals(ExchangeStatus.ERROR, mec.getStatus());
417         try {
418             consumer.getChannel().send(mec);
419             fail("Exchange status is ERROR");
420         } catch (Exception JavaDoc e) {
421             // ok
422
}
423         // Nothing left
424
assertNull(consumer.getChannel().accept(100L)); // receive in
425
assertNull(provider.getChannel().accept(100L)); // receive in
426
}
427     
428     public void testInOutWithError1() throws Exception JavaDoc {
429         // Send message exchange
430
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
431         InOut mec = mef.createInOutExchange();
432         NormalizedMessage m = mec.createMessage();
433         m.setContent(new StringSource(PAYLOAD));
434         mec.setInMessage(m);
435         consumer.getChannel().send(mec);
436         // Provider side
437
InOut mep = (InOut) provider.getChannel().accept(100L);
438         assertNotNull(mep);
439         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
440         m = mep.createMessage();
441         m.setContent(new StringSource(RESPONSE));
442         mep.setStatus(ExchangeStatus.ERROR);
443         provider.getChannel().send(mep);
444         // Consumer side
445
assertSame(mec, consumer.getChannel().accept(100L));
446         assertEquals(ExchangeStatus.ERROR, mec.getStatus());
447         try {
448             mec.setStatus(ExchangeStatus.DONE);
449             consumer.getChannel().send(mec);
450             fail("Exchange status is ERROR");
451         } catch (Exception JavaDoc e) {
452             // ok
453
}
454         // Nothing left
455
assertNull(consumer.getChannel().accept(100L)); // receive in
456
assertNull(provider.getChannel().accept(100L)); // receive in
457
}
458     
459     public void testInOutWithError2() throws Exception JavaDoc {
460         // Send message exchange
461
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
462         InOut mec = mef.createInOutExchange();
463         NormalizedMessage m = mec.createMessage();
464         m.setContent(new StringSource(PAYLOAD));
465         mec.setInMessage(m);
466         consumer.getChannel().send(mec);
467         // Provider side
468
InOut mep = (InOut) provider.getChannel().accept(100L);
469         assertNotNull(mep);
470         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
471         m = mep.createMessage();
472         m.setContent(new StringSource(RESPONSE));
473         provider.getChannel().send(mep);
474         // Consumer side
475
assertSame(mec, consumer.getChannel().accept(100L));
476         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
477         mec.setStatus(ExchangeStatus.ERROR);
478         consumer.getChannel().send(mec);
479         // Provider site
480
assertSame(mep, provider.getChannel().accept(100L));
481         assertEquals(ExchangeStatus.ERROR, mec.getStatus());
482         // Nothing left
483
assertNull(consumer.getChannel().accept(100L)); // receive in
484
assertNull(provider.getChannel().accept(100L)); // receive in
485
}
486     
487     public void testInOptOutWithRep() throws Exception JavaDoc {
488         // Send message exchange
489
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
490         InOptionalOut mec = mef.createInOptionalOutExchange();
491         NormalizedMessage m = mec.createMessage();
492         m.setContent(new StringSource(PAYLOAD));
493         mec.setInMessage(m);
494         consumer.getChannel().send(mec);
495         // Provider side
496
InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L);
497         assertNotNull(mep);
498         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
499         m = mep.createMessage();
500         m.setContent(new StringSource(RESPONSE));
501         mep.setOutMessage(m);
502         provider.getChannel().send(mep);
503         // Consumer side
504
assertSame(mec, consumer.getChannel().accept(100L));
505         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
506         mec.setStatus(ExchangeStatus.DONE);
507         consumer.getChannel().send(mec);
508         // Provider site
509
assertSame(mep, provider.getChannel().accept(100L));
510         assertEquals(ExchangeStatus.DONE, mec.getStatus());
511         // Nothing left
512
assertNull(consumer.getChannel().accept(100L)); // receive in
513
assertNull(provider.getChannel().accept(100L)); // receive in
514
}
515     
516     public void testInOptOutWithoutRep() throws Exception JavaDoc {
517         // Send message exchange
518
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
519         InOptionalOut mec = mef.createInOptionalOutExchange();
520         NormalizedMessage m = mec.createMessage();
521         m.setContent(new StringSource(PAYLOAD));
522         mec.setInMessage(m);
523         consumer.getChannel().send(mec);
524         // Provider side
525
InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L);
526         assertNotNull(mep);
527         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
528         mep.setStatus(ExchangeStatus.DONE);
529         provider.getChannel().send(mep);
530         // Consumer side
531
assertSame(mec, consumer.getChannel().accept(100L));
532         assertEquals(ExchangeStatus.DONE, mec.getStatus());
533         // Nothing left
534
assertNull(consumer.getChannel().accept(100L)); // receive in
535
assertNull(provider.getChannel().accept(100L)); // receive in
536
}
537     
538     public void testInOptOutWithProviderFault() throws Exception JavaDoc {
539         // Send message exchange
540
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
541         InOptionalOut mec = mef.createInOptionalOutExchange();
542         NormalizedMessage m = mec.createMessage();
543         m.setContent(new StringSource(PAYLOAD));
544         mec.setInMessage(m);
545         consumer.getChannel().send(mec);
546         // Provider side
547
InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L);
548         assertNotNull(mep);
549         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
550         mep.setFault(mep.createFault());
551         provider.getChannel().send(mep);
552         // Consumer side
553
assertSame(mec, consumer.getChannel().accept(100L));
554         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
555         assertNotNull(mec.getFault());
556         mec.setStatus(ExchangeStatus.DONE);
557         consumer.getChannel().send(mec);
558         // Provider site
559
assertSame(mep, provider.getChannel().accept(100L));
560         assertEquals(ExchangeStatus.DONE, mec.getStatus());
561         // Nothing left
562
assertNull(consumer.getChannel().accept(100L)); // receive in
563
assertNull(provider.getChannel().accept(100L)); // receive in
564
}
565     
566     public void testInOptOutWithProviderError() throws Exception JavaDoc {
567         // Send message exchange
568
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
569         InOptionalOut mec = mef.createInOptionalOutExchange();
570         NormalizedMessage m = mec.createMessage();
571         m.setContent(new StringSource(PAYLOAD));
572         mec.setInMessage(m);
573         consumer.getChannel().send(mec);
574         // Provider side
575
InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L);
576         assertNotNull(mep);
577         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
578         mep.setStatus(ExchangeStatus.ERROR);
579         provider.getChannel().send(mep);
580         // Consumer side
581
assertSame(mec, consumer.getChannel().accept(100L));
582         assertEquals(ExchangeStatus.ERROR, mec.getStatus());
583         try {
584             mec.setStatus(ExchangeStatus.DONE);
585             consumer.getChannel().send(mec);
586             fail("Exchange status is ERROR");
587         } catch (Exception JavaDoc e) {
588             // ok
589
}
590         // Nothing left
591
assertNull(consumer.getChannel().accept(100L)); // receive in
592
assertNull(provider.getChannel().accept(100L)); // receive in
593
}
594     
595     public void testInOptOutWithRepAndConsumerFault() throws Exception JavaDoc {
596         // Send message exchange
597
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
598         InOptionalOut mec = mef.createInOptionalOutExchange();
599         NormalizedMessage m = mec.createMessage();
600         m.setContent(new StringSource(PAYLOAD));
601         mec.setInMessage(m);
602         consumer.getChannel().send(mec);
603         // Provider side
604
InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L);
605         assertNotNull(mep);
606         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
607         m = mep.createMessage();
608         m.setContent(new StringSource(RESPONSE));
609         mep.setOutMessage(m);
610         provider.getChannel().send(mep);
611         // Consumer side
612
assertSame(mec, consumer.getChannel().accept(100L));
613         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
614         mec.setFault(mec.createFault());
615         consumer.getChannel().send(mec);
616         // Provider site
617
assertSame(mep, provider.getChannel().accept(100L));
618         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
619         assertNotNull(mep.getFault());
620         mep.setStatus(ExchangeStatus.DONE);
621         provider.getChannel().send(mep);
622         // Consumer side
623
assertSame(mec, consumer.getChannel().accept(100L));
624         assertEquals(ExchangeStatus.DONE, mec.getStatus());
625         // Nothing left
626
assertNull(consumer.getChannel().accept(100L)); // receive in
627
assertNull(provider.getChannel().accept(100L)); // receive in
628
}
629     
630     public void testInOptOutWithRepAndConsumerError() throws Exception JavaDoc {
631         // Send message exchange
632
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
633         InOptionalOut mec = mef.createInOptionalOutExchange();
634         NormalizedMessage m = mec.createMessage();
635         m.setContent(new StringSource(PAYLOAD));
636         mec.setInMessage(m);
637         consumer.getChannel().send(mec);
638         // Provider side
639
InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L);
640         assertNotNull(mep);
641         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
642         m = mep.createMessage();
643         m.setContent(new StringSource(RESPONSE));
644         mep.setOutMessage(m);
645         provider.getChannel().send(mep);
646         // Consumer side
647
assertSame(mec, consumer.getChannel().accept(100L));
648         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
649         mec.setStatus(ExchangeStatus.ERROR);
650         consumer.getChannel().send(mec);
651         // Provider site
652
assertSame(mep, provider.getChannel().accept(100L));
653         assertEquals(ExchangeStatus.ERROR, mep.getStatus());
654         try {
655             mep.setStatus(ExchangeStatus.DONE);
656             provider.getChannel().send(mep);
657             fail("Exchange status is ERROR");
658         } catch (Exception JavaDoc e) {
659             // ok
660
}
661         // Nothing left
662
assertNull(consumer.getChannel().accept(100L)); // receive in
663
assertNull(provider.getChannel().accept(100L)); // receive in
664
}
665     
666     public void testInOptOutWithRepFaultAndError() throws Exception JavaDoc {
667         // Send message exchange
668
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
669         InOptionalOut mec = mef.createInOptionalOutExchange();
670         NormalizedMessage m = mec.createMessage();
671         m.setContent(new StringSource(PAYLOAD));
672         mec.setInMessage(m);
673         consumer.getChannel().send(mec);
674         // Provider side
675
InOptionalOut mep = (InOptionalOut) provider.getChannel().accept(100L);
676         assertNotNull(mep);
677         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
678         m = mep.createMessage();
679         m.setContent(new StringSource(RESPONSE));
680         mep.setOutMessage(m);
681         provider.getChannel().send(mep);
682         // Consumer side
683
assertSame(mec, consumer.getChannel().accept(100L));
684         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
685         mec.setFault(mec.createFault());
686         consumer.getChannel().send(mec);
687         // Provider site
688
assertSame(mep, provider.getChannel().accept(100L));
689         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
690         assertNotNull(mep.getFault());
691         mep.setStatus(ExchangeStatus.ERROR);
692         provider.getChannel().send(mep);
693         // Consumer side
694
assertSame(mec, consumer.getChannel().accept(100L));
695         assertEquals(ExchangeStatus.ERROR, mec.getStatus());
696         try {
697             mec.setStatus(ExchangeStatus.DONE);
698             consumer.getChannel().send(mec);
699             fail("Exchange status is ERROR");
700         } catch (Exception JavaDoc e) {
701             // ok
702
}
703         // Nothing left
704
assertNull(consumer.getChannel().accept(100L)); // receive in
705
assertNull(provider.getChannel().accept(100L)); // receive in
706
}
707     
708     public void testRobustInOnly() throws Exception JavaDoc {
709         // Send message exchange
710
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
711         RobustInOnly mec = mef.createRobustInOnlyExchange();
712         NormalizedMessage m = mec.createMessage();
713         m.setContent(new StringSource(PAYLOAD));
714         mec.setInMessage(m);
715         consumer.getChannel().send(mec);
716         // Provider side
717
RobustInOnly mep = (RobustInOnly) provider.getChannel().accept(100L);
718         assertNotNull(mep);
719         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
720         mep.setStatus(ExchangeStatus.DONE);
721         provider.getChannel().send(mep);
722         // Consumer side
723
assertSame(mec, consumer.getChannel().accept(100L));
724         assertEquals(ExchangeStatus.DONE, mec.getStatus());
725         // Nothing left
726
assertNull(consumer.getChannel().accept(100L)); // receive in
727
assertNull(provider.getChannel().accept(100L)); // receive in
728
}
729     
730     public void testRobustInOnlyWithFault() throws Exception JavaDoc {
731         // Send message exchange
732
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
733         RobustInOnly mec = mef.createRobustInOnlyExchange();
734         NormalizedMessage m = mec.createMessage();
735         m.setContent(new StringSource(PAYLOAD));
736         mec.setInMessage(m);
737         consumer.getChannel().send(mec);
738         // Provider side
739
RobustInOnly mep = (RobustInOnly) provider.getChannel().accept(100L);
740         assertNotNull(mep);
741         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
742         mep.setFault(mep.createFault());
743         provider.getChannel().send(mep);
744         // Consumer side
745
assertSame(mec, consumer.getChannel().accept(100L));
746         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
747         assertNotNull(mec.getFault());
748         mec.setStatus(ExchangeStatus.DONE);
749         provider.getChannel().send(mec);
750         // Provider site
751
assertSame(mep, provider.getChannel().accept(100L));
752         assertEquals(ExchangeStatus.DONE, mep.getStatus());
753         // Nothing left
754
assertNull(consumer.getChannel().accept(100L)); // receive in
755
assertNull(provider.getChannel().accept(100L)); // receive in
756
}
757     
758     public void testRobustInOnlyWithError() throws Exception JavaDoc {
759         // Send message exchange
760
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
761         RobustInOnly mec = mef.createRobustInOnlyExchange();
762         NormalizedMessage m = mec.createMessage();
763         m.setContent(new StringSource(PAYLOAD));
764         mec.setInMessage(m);
765         consumer.getChannel().send(mec);
766         // Provider side
767
RobustInOnly mep = (RobustInOnly) provider.getChannel().accept(100L);
768         assertNotNull(mep);
769         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
770         mep.setStatus(ExchangeStatus.ERROR);
771         provider.getChannel().send(mep);
772         // Consumer side
773
assertSame(mec, consumer.getChannel().accept(100L));
774         assertEquals(ExchangeStatus.ERROR, mec.getStatus());
775         try {
776             mec.setStatus(ExchangeStatus.DONE);
777             provider.getChannel().send(mec);
778             fail("Exchange status is ERROR");
779         } catch (Exception JavaDoc e) {
780             // ok
781
}
782         // Nothing left
783
assertNull(consumer.getChannel().accept(100L)); // receive in
784
assertNull(provider.getChannel().accept(100L)); // receive in
785
}
786     
787     public void testRobustInOnlyWithFaultAndError() throws Exception JavaDoc {
788         // Send message exchange
789
MessageExchangeFactory mef = consumer.getChannel().createExchangeFactoryForService(new QName JavaDoc("provider"));
790         RobustInOnly mec = mef.createRobustInOnlyExchange();
791         NormalizedMessage m = mec.createMessage();
792         m.setContent(new StringSource(PAYLOAD));
793         mec.setInMessage(m);
794         consumer.getChannel().send(mec);
795         // Provider side
796
RobustInOnly mep = (RobustInOnly) provider.getChannel().accept(100L);
797         assertNotNull(mep);
798         assertEquals(ExchangeStatus.ACTIVE, mep.getStatus());
799         mep.setFault(mep.createFault());
800         provider.getChannel().send(mep);
801         // Consumer side
802
assertSame(mec, consumer.getChannel().accept(100L));
803         assertEquals(ExchangeStatus.ACTIVE, mec.getStatus());
804         assertNotNull(mec.getFault());
805         mec.setError(new Exception JavaDoc());
806         provider.getChannel().send(mec);
807         // Provider site
808
assertSame(mep, provider.getChannel().accept(100L));
809         assertEquals(ExchangeStatus.ERROR, mep.getStatus());
810         try {
811             mep.setStatus(ExchangeStatus.DONE);
812             provider.getChannel().send(mep);
813             fail("Exchange status is ERROR");
814         } catch (Exception JavaDoc e) {
815             // ok
816
}
817         // Nothing left
818
assertNull(consumer.getChannel().accept(100L)); // receive in
819
assertNull(provider.getChannel().accept(100L)); // receive in
820
}
821     
822 }
823
Popular Tags