KickJava   Java API By Example, From Geeks To Geeks.

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


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.transaction.Status JavaDoc;
25 import javax.xml.namespace.QName JavaDoc;
26
27 import org.apache.servicemix.eip.patterns.StaticRoutingSlip;
28 import org.apache.servicemix.eip.support.ExchangeTarget;
29
30
31 public class StaticRoutingSlipTxTest extends AbstractEIPTransactionalTest {
32
33     protected StaticRoutingSlip routingSlip;
34     
35     protected void setUp() throws Exception JavaDoc {
36         super.setUp();
37
38         routingSlip = new StaticRoutingSlip();
39         routingSlip.setTargets(
40                 new ExchangeTarget[] {
41                         createServiceExchangeTarget(new QName JavaDoc("target1")),
42                         createServiceExchangeTarget(new QName JavaDoc("target2")),
43                         createServiceExchangeTarget(new QName JavaDoc("target3"))
44                 });
45         configurePattern(routingSlip);
46         activateComponent(routingSlip, "routingSlip");
47     }
48
49     public void testSync() throws Exception JavaDoc {
50         activateComponent(new ReturnOutComponent(), "target1");
51         activateComponent(new ReturnOutComponent(), "target2");
52         activateComponent(new ReturnOutComponent(), "target3");
53
54         tm.begin();
55         
56         InOut me = client.createInOutExchange();
57         me.setService(new QName JavaDoc("routingSlip"));
58         me.getInMessage().setContent(createSource("<hello/>"));
59         client.sendSync(me);
60         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
61         assertNotNull(me.getOutMessage());
62         client.done(me);
63         
64         tm.commit();
65         
66         listener.assertExchangeCompleted();
67     }
68     
69     public void testAsync() throws Exception JavaDoc {
70         activateComponent(new ReturnOutComponent(), "target1");
71         activateComponent(new ReturnOutComponent(), "target2");
72         activateComponent(new ReturnOutComponent(), "target3");
73
74         tm.begin();
75         
76         InOut me = client.createInOutExchange();
77         me.setService(new QName JavaDoc("routingSlip"));
78         me.getInMessage().setContent(createSource("<hello/>"));
79         client.send(me);
80         
81         tm.commit();
82
83         me = (InOut) client.receive();
84         assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
85         assertEquals(Status.STATUS_ACTIVE, tm.getStatus());
86         assertNotNull(me.getOutMessage());
87         client.done(me);
88         
89         listener.assertExchangeCompleted();
90     }
91     
92 }
93
Popular Tags