01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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;
22:
23: import junit.framework.TestCase;
24:
25: import org.apache.commons.logging.Log;
26: import org.apache.commons.logging.LogFactory;
27: import org.apache.servicemix.client.ServiceMixClient;
28: import org.apache.servicemix.jbi.container.SpringJBIContainer;
29: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
30: import org.apache.servicemix.jbi.jaxp.StringSource;
31: import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
32: import org.springframework.context.support.AbstractXmlApplicationContext;
33:
34: /**
35: * JMSCluster Test for SendSync
36: */
37: public class SimpleClusterSendSyncTest extends TestCase {
38: private static transient Log log = LogFactory
39: .getLog(SimpleClusterSendSyncTest.class);
40:
41: protected SpringJBIContainer jbi;
42: protected AbstractXmlApplicationContext context;
43:
44: /*
45: * @see TestCase#setUp()
46: */
47: protected void setUp() throws Exception {
48: context = new ClassPathXmlApplicationContext(
49: "org/apache/servicemix/jbi/nmr/flow/jms/broker.xml");
50: jbi = (SpringJBIContainer) context.getBean("jbi");
51: assertNotNull("JBI Container not found in spring!", jbi);
52:
53: }
54:
55: protected void tearDown() throws Exception {
56: context.close();
57: }
58:
59: public void testSendSync() throws Exception {
60: AbstractXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
61: "org/apache/servicemix/jbi/nmr/flow/jms/client.xml");
62: try {
63: ServiceMixClient client = (ServiceMixClient) ctx
64: .getBean("client");
65: Thread.sleep(2000);
66: InOut exchange = client.createInOutExchange();
67: exchange.setService(new QName("http://www.habuma.com/foo",
68: "pingService"));
69: NormalizedMessage in = exchange.getInMessage();
70: in.setContent(new StringSource("<ping>Pinging you</ping>"));
71: log
72: .info("SENDING; exchange.status="
73: + exchange.getStatus());
74: client.sendSync(exchange);
75: assertNotNull(exchange.getOutMessage());
76: log.info("GOT RESPONSE; exchange.out="
77: + new SourceTransformer().toString(exchange
78: .getOutMessage().getContent()));
79: client.done(exchange);
80: // Wait for done to be delivered
81: Thread.sleep(50);
82: } finally {
83: ctx.close();
84: }
85: }
86: }
|