KickJava   Java API By Example, From Geeks To Geeks.

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


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.InOut;
22 import javax.xml.namespace.QName JavaDoc;
23
24 import org.apache.servicemix.eip.patterns.WireTap;
25 import org.apache.servicemix.tck.ReceiverComponent;
26
27 public class WireTapTxTest extends AbstractEIPTransactionalTest {
28
29     protected ReceiverComponent inReceiver;
30     protected ReceiverComponent outReceiver;
31     protected ReceiverComponent faultReceiver;
32     protected WireTap wireTap;
33     
34     protected void setUp() throws Exception JavaDoc {
35         super.setUp();
36         
37         inReceiver = activateReceiver("in");
38         outReceiver = activateReceiver("out");
39         faultReceiver = activateReceiver("fault");
40         wireTap = new WireTap();
41         wireTap.setInListener(createServiceExchangeTarget(new QName JavaDoc("in")));
42         wireTap.setOutListener(createServiceExchangeTarget(new QName JavaDoc("out")));
43         wireTap.setFaultListener(createServiceExchangeTarget(new QName JavaDoc("fault")));
44         wireTap.setTarget(createServiceExchangeTarget(new QName JavaDoc("target")));
45         configurePattern(wireTap);
46         activateComponent(wireTap, "wireTap");
47     }
48     
49     public void testInOnlySync() throws Exception JavaDoc {
50         ReceiverComponent target = activateReceiver("target");
51
52         tm.begin();
53         
54         InOnly me = client.createInOnlyExchange();
55         me.setService(new QName JavaDoc("wireTap"));
56         me.getInMessage().setContent(createSource("<hello/>"));
57         client.sendSync(me);
58         assertEquals(ExchangeStatus.DONE, me.getStatus());
59         
60         tm.commit();
61         
62         target.getMessageList().assertMessagesReceived(1);
63         inReceiver.getMessageList().assertMessagesReceived(1);
64         outReceiver.getMessageList().assertMessagesReceived(0);
65         faultReceiver.getMessageList().assertMessagesReceived(0);
66     }
67     
68     public void testInOnlyAsync() throws Exception JavaDoc {
69         ReceiverComponent target = activateReceiver("target");
70
71         tm.begin();
72         
73         InOnly me = client.createInOnlyExchange();
74         me.setService(new QName JavaDoc("wireTap"));
75         me.getInMessage().setContent(createSource("<hello/>"));
76         client.send(me);
77         
78         tm.commit();
79         
80         me = (InOnly) client.receive();
81         assertEquals(ExchangeStatus.DONE, me.getStatus());
82         
83         target.getMessageList().assertMessagesReceived(1);
84         inReceiver.getMessageList().assertMessagesReceived(1);
85         outReceiver.getMessageList().assertMessagesReceived(0);
86         faultReceiver.getMessageList().assertMessagesReceived(0);
87     }
88     
89     public void testInOutSync() throws Exception JavaDoc {
90         activateComponent(new ReturnOutComponent(), "target");
91
92         tm.begin();
93         
94         InOut me = client.createInOutExchange();
95         me.setService(new QName JavaDoc("wireTap"));
96         me.getInMessage().setContent(createSource("<hello/>"));
97         client.sendSync(me);
98         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
99         client.done(me);
100         
101         tm.commit();
102     }
103     
104     public void testInOutAsync() throws Exception JavaDoc {
105         activateComponent(new ReturnOutComponent(), "target");
106
107         tm.begin();
108         
109         InOut me = client.createInOutExchange();
110         me.setService(new QName JavaDoc("wireTap"));
111         me.getInMessage().setContent(createSource("<hello/>"));
112         client.send(me);
113         
114         tm.commit();
115         
116         me = (InOut) client.receive();
117         client.done(me);
118     }
119     
120 }
121
Popular Tags