KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > nmr > flow > jms > SimpleClusterSendSyncTest


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.nmr.flow.jms;
18
19 import javax.jbi.messaging.InOut;
20 import javax.jbi.messaging.NormalizedMessage;
21 import javax.xml.namespace.QName JavaDoc;
22
23 import junit.framework.TestCase;
24
25 import org.apache.servicemix.client.ServiceMixClient;
26 import org.apache.servicemix.jbi.container.SpringJBIContainer;
27 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
28 import org.apache.servicemix.jbi.jaxp.StringSource;
29 import org.springframework.context.support.AbstractXmlApplicationContext;
30 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
31
32 /**
33  * JMSCluster Test for SendSync
34  */

35 public class SimpleClusterSendSyncTest extends TestCase {
36     protected SpringJBIContainer jbi;
37     protected AbstractXmlApplicationContext context;
38
39     /*
40      * @see TestCase#setUp()
41      */

42     protected void setUp() throws Exception JavaDoc {
43         context = new ClassPathXmlApplicationContext("org/apache/servicemix/jbi/nmr/flow/jms/broker.xml");
44         jbi = (SpringJBIContainer) context.getBean("jbi");
45         assertNotNull("JBI Container not found in spring!", jbi);
46
47     }
48
49     protected void tearDown() throws Exception JavaDoc {
50         context.close();
51     }
52
53     public void testSendSync() throws Exception JavaDoc {
54         AbstractXmlApplicationContext ctx = new ClassPathXmlApplicationContext("org/apache/servicemix/jbi/nmr/flow/jms/client.xml");
55         try {
56             ServiceMixClient client = (ServiceMixClient) ctx.getBean("client");
57             Thread.sleep(2000);
58             InOut exchange = client.createInOutExchange();
59             exchange.setService(new QName JavaDoc("http://www.habuma.com/foo", "pingService"));
60             NormalizedMessage in = exchange.getInMessage();
61             in.setContent(new StringSource("<ping>Pinging you</ping>"));
62             System.out.println("SENDING; exchange.status=" + exchange.getStatus());
63             client.sendSync(exchange);
64             assertNotNull(exchange.getOutMessage());
65             System.out.println("GOT RESPONSE; exchange.out=" + new SourceTransformer().toString(exchange.getOutMessage().getContent()));
66             client.done(exchange);
67             // Wait for done to be delivered
68
Thread.sleep(50);
69         } finally {
70             ctx.close();
71         }
72     }
73 }
74
Popular Tags