KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jms > JmsSpringJcaTest


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.jms;
18
19 import javax.jbi.messaging.ExchangeStatus;
20 import javax.jbi.messaging.InOnly;
21 import javax.jbi.messaging.InOut;
22 import javax.naming.Context JavaDoc;
23 import javax.transaction.TransactionManager JavaDoc;
24 import javax.xml.namespace.QName JavaDoc;
25
26 import org.apache.servicemix.client.DefaultServiceMixClient;
27 import org.apache.servicemix.client.Destination;
28 import org.apache.servicemix.jbi.jaxp.StringSource;
29 import org.apache.servicemix.tck.ExchangeCompletedListener;
30 import org.apache.servicemix.tck.Receiver;
31 import org.apache.servicemix.tck.SpringTestSupport;
32 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
33 import org.apache.xbean.spring.jndi.SpringInitialContextFactory;
34 import org.springframework.context.support.AbstractXmlApplicationContext;
35
36 public class JmsSpringJcaTest extends SpringTestSupport {
37
38     protected ExchangeCompletedListener listener;
39     protected DefaultServiceMixClient client;
40     protected Receiver receiver;
41     
42     protected void setUp() throws Exception JavaDoc {
43         super.setUp();
44         listener = new ExchangeCompletedListener(5000);
45         jbi.addListener(listener);
46         client = new DefaultServiceMixClient(jbi);
47         receiver = (Receiver) getBean("receiver");
48     }
49     
50     protected void tearDown() throws Exception JavaDoc {
51         listener.assertExchangeCompleted();
52         super.tearDown();
53     }
54     
55     public void testInOut() throws Exception JavaDoc {
56         TransactionManager JavaDoc tm = (TransactionManager JavaDoc) getBean("transactionManager");
57         tm.begin();
58         InOut me = client.createInOutExchange();
59         me.setService(new QName JavaDoc("http://test", "MyProviderService"));
60         me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
61         client.send(me);
62         tm.commit();
63         me = (InOut) client.receive();
64         assertEquals(ExchangeStatus.ERROR, me.getStatus());
65         assertNotNull(me.getError());
66         assertTrue(me.getError() instanceof UnsupportedOperationException JavaDoc);
67     }
68
69     public void testInOnlyWithAsyncConsumer() throws Exception JavaDoc {
70         TransactionManager JavaDoc tm = (TransactionManager JavaDoc) getBean("transactionManager");
71         tm.begin();
72         Destination dest = client.createDestination("endpoint:http://test/MyProviderService/async");
73         InOnly me = dest.createInOnlyExchange();
74         me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
75         client.send(me);
76         tm.commit();
77         me = (InOnly) client.receive();
78         assertEquals(ExchangeStatus.DONE, me.getStatus());
79         receiver.getMessageList().assertMessagesReceived(1);
80     }
81
82     public void testInOnlySyncWithAsyncConsumer() throws Exception JavaDoc {
83         TransactionManager JavaDoc tm = (TransactionManager JavaDoc) getBean("transactionManager");
84         tm.begin();
85         Destination dest = client.createDestination("endpoint:http://test/MyProviderService/async");
86         InOnly me = dest.createInOnlyExchange();
87         me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
88         client.sendSync(me);
89         assertEquals(ExchangeStatus.DONE, me.getStatus());
90         tm.commit();
91         receiver.getMessageList().assertMessagesReceived(1);
92     }
93
94     public void testInOnlyWithSyncConsumer() throws Exception JavaDoc {
95         TransactionManager JavaDoc tm = (TransactionManager JavaDoc) getBean("transactionManager");
96         tm.begin();
97         Destination dest = client.createDestination("endpoint:http://test/MyProviderService/synchronous");
98         InOnly me = dest.createInOnlyExchange();
99         me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
100         client.send(me);
101         tm.commit();
102         me = (InOnly) client.receive();
103         assertEquals(ExchangeStatus.DONE, me.getStatus());
104         receiver.getMessageList().assertMessagesReceived(1);
105     }
106
107     public void testInOnlySyncWithSyncConsumer() throws Exception JavaDoc {
108         TransactionManager JavaDoc tm = (TransactionManager JavaDoc) getBean("transactionManager");
109         tm.begin();
110         Destination dest = client.createDestination("endpoint:http://test/MyProviderService/synchronous");
111         InOnly me = dest.createInOnlyExchange();
112         me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
113         client.sendSync(me);
114         assertEquals(ExchangeStatus.DONE, me.getStatus());
115         tm.commit();
116         receiver.getMessageList().assertMessagesReceived(1);
117     }
118
119     protected AbstractXmlApplicationContext createBeanFactory() {
120         System.setProperty(Context.INITIAL_CONTEXT_FACTORY, SpringInitialContextFactory.class.getName());
121         System.setProperty(Context.PROVIDER_URL, "org/apache/servicemix/jms/jndi.xml");
122         return new ClassPathXmlApplicationContext("org/apache/servicemix/jms/spring-jca.xml");
123     }
124
125 }
126
Popular Tags