KickJava   Java API By Example, From Geeks To Geeks.

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


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.Pipeline;
27 import org.apache.servicemix.tck.ReceiverComponent;
28
29 public class PipelineTest extends AbstractEIPTest {
30
31     protected Pipeline pipeline;
32     
33     protected void setUp() throws Exception JavaDoc {
34         super.setUp();
35
36         pipeline = new Pipeline();
37         pipeline.setTransformer(createServiceExchangeTarget(new QName JavaDoc("transformer")));
38         pipeline.setTarget(createServiceExchangeTarget(new QName JavaDoc("target")));
39         configurePattern(pipeline);
40         activateComponent(pipeline, "pipeline");
41     }
42     
43     public void testInOut() throws Exception JavaDoc {
44         InOut me = client.createInOutExchange();
45         me.setService(new QName JavaDoc("pipeline"));
46         me.getInMessage().setContent(createSource("<hello/>"));
47         client.sendSync(me);
48         assertEquals(ExchangeStatus.ERROR, me.getStatus());
49     }
50     
51     public void testInOptionalOut() throws Exception JavaDoc {
52         InOptionalOut me = client.createInOptionalOutExchange();
53         me.setService(new QName JavaDoc("pipeline"));
54         me.getInMessage().setContent(createSource("<hello/>"));
55         client.sendSync(me);
56         assertEquals(ExchangeStatus.ERROR, me.getStatus());
57     }
58     
59     public void testInOnly() throws Exception JavaDoc {
60         activateComponent(new ReturnOutComponent(), "transformer");
61         ReceiverComponent target = activateReceiver("target");
62
63         InOnly me = client.createInOnlyExchange();
64         me.setService(new QName JavaDoc("pipeline"));
65         me.getInMessage().setContent(createSource("<hello/>"));
66         client.sendSync(me);
67         assertEquals(ExchangeStatus.DONE, me.getStatus());
68         
69         target.getMessageList().assertMessagesReceived(1);
70         
71         listener.assertExchangeCompleted();
72     }
73     
74     public void testInOnlyWithTransformerFault() throws Exception JavaDoc {
75         activateComponent(new ReturnFaultComponent(), "transformer");
76         ReceiverComponent target = activateReceiver("target");
77
78         InOnly me = client.createInOnlyExchange();
79         me.setService(new QName JavaDoc("pipeline"));
80         me.getInMessage().setContent(createSource("<hello/>"));
81         client.sendSync(me);
82         assertEquals(ExchangeStatus.ERROR, me.getStatus());
83         
84         target.getMessageList().assertMessagesReceived(0);
85         
86         listener.assertExchangeCompleted();
87     }
88     
89     public void testInOnlyWithTransformerError() throws Exception JavaDoc {
90         activateComponent(new ReturnErrorComponent(), "transformer");
91         ReceiverComponent target = activateReceiver("target");
92
93         InOnly me = client.createInOnlyExchange();
94         me.setService(new QName JavaDoc("pipeline"));
95         me.getInMessage().setContent(createSource("<hello/>"));
96         client.sendSync(me);
97         assertEquals(ExchangeStatus.ERROR, me.getStatus());
98         
99         target.getMessageList().assertMessagesReceived(0);
100         
101         listener.assertExchangeCompleted();
102     }
103     
104     public void testInOnlyWithTargetError() throws Exception JavaDoc {
105         activateComponent(new ReturnOutComponent(), "transformer");
106         activateComponent(new ReturnErrorComponent(), "target");
107
108         InOnly me = client.createInOnlyExchange();
109         me.setService(new QName JavaDoc("pipeline"));
110         me.getInMessage().setContent(createSource("<hello/>"));
111         client.sendSync(me);
112         assertEquals(ExchangeStatus.ERROR, me.getStatus());
113         
114         listener.assertExchangeCompleted();
115     }
116     
117     public void testRobustInOnly() throws Exception JavaDoc {
118         activateComponent(new ReturnOutComponent(), "transformer");
119         ReceiverComponent target = activateReceiver("target");
120
121         RobustInOnly me = client.createRobustInOnlyExchange();
122         me.setService(new QName JavaDoc("pipeline"));
123         me.getInMessage().setContent(createSource("<hello/>"));
124         client.sendSync(me);
125         assertEquals(ExchangeStatus.DONE, me.getStatus());
126         
127         target.getMessageList().assertMessagesReceived(1);
128         
129         listener.assertExchangeCompleted();
130     }
131     
132     public void testRobustInOnlyWithTransformerFault() throws Exception JavaDoc {
133         activateComponent(new ReturnFaultComponent(), "transformer");
134         ReceiverComponent target = activateReceiver("target");
135
136         RobustInOnly me = client.createRobustInOnlyExchange();
137         me.setService(new QName JavaDoc("pipeline"));
138         me.getInMessage().setContent(createSource("<hello/>"));
139         client.sendSync(me);
140         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
141         assertNotNull(me.getFault());
142         client.done(me);
143         
144         target.getMessageList().assertMessagesReceived(0);
145         
146         listener.assertExchangeCompleted();
147     }
148     
149     public void testRobustInOnlyWithTransformerFaultAndError() throws Exception JavaDoc {
150         activateComponent(new ReturnFaultComponent(), "transformer");
151         ReceiverComponent target = activateReceiver("target");
152
153         RobustInOnly me = client.createRobustInOnlyExchange();
154         me.setService(new QName JavaDoc("pipeline"));
155         me.getInMessage().setContent(createSource("<hello/>"));
156         client.sendSync(me);
157         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
158         assertNotNull(me.getFault());
159         client.fail(me, new Exception JavaDoc("I do not like faults"));
160         
161         target.getMessageList().assertMessagesReceived(0);
162         
163         listener.assertExchangeCompleted();
164     }
165     
166     public void testRobustInOnlyWithTransformerError() throws Exception JavaDoc {
167         activateComponent(new ReturnErrorComponent(), "transformer");
168         ReceiverComponent target = activateReceiver("target");
169
170         RobustInOnly me = client.createRobustInOnlyExchange();
171         me.setService(new QName JavaDoc("pipeline"));
172         me.getInMessage().setContent(createSource("<hello/>"));
173         client.sendSync(me);
174         assertEquals(ExchangeStatus.ERROR, me.getStatus());
175         
176         target.getMessageList().assertMessagesReceived(0);
177         
178         listener.assertExchangeCompleted();
179     }
180     
181     public void testRobustInOnlyWithTargetFault() throws Exception JavaDoc {
182         activateComponent(new ReturnOutComponent(), "transformer");
183         activateComponent(new ReturnFaultComponent(), "target");
184
185         RobustInOnly me = client.createRobustInOnlyExchange();
186         me.setService(new QName JavaDoc("pipeline"));
187         me.getInMessage().setContent(createSource("<hello/>"));
188         client.sendSync(me);
189         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
190         assertNotNull(me.getFault());
191         client.done(me);
192         
193         listener.assertExchangeCompleted();
194     }
195     
196     public void testRobustInOnlyWithTargetFaultAndError() throws Exception JavaDoc {
197         activateComponent(new ReturnOutComponent(), "transformer");
198         activateComponent(new ReturnFaultComponent(), "target");
199
200         RobustInOnly me = client.createRobustInOnlyExchange();
201         me.setService(new QName JavaDoc("pipeline"));
202         me.getInMessage().setContent(createSource("<hello/>"));
203         client.sendSync(me);
204         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
205         assertNotNull(me.getFault());
206         client.fail(me, new Exception JavaDoc("I do not like faults"));
207         
208         listener.assertExchangeCompleted();
209     }
210     
211     public void testRobustInOnlyWithTargetError() throws Exception JavaDoc {
212         activateComponent(new ReturnOutComponent(), "transformer");
213         activateComponent(new ReturnErrorComponent(), "target");
214
215         RobustInOnly me = client.createRobustInOnlyExchange();
216         me.setService(new QName JavaDoc("pipeline"));
217         me.getInMessage().setContent(createSource("<hello/>"));
218         client.sendSync(me);
219         assertEquals(ExchangeStatus.ERROR, me.getStatus());
220         
221         listener.assertExchangeCompleted();
222     }
223     
224 }
225
Popular Tags