001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.transport.jms;
019:
020: import java.io.ByteArrayInputStream;
021: import java.io.IOException;
022: import java.io.InputStream;
023: import java.io.OutputStream;
024:
025: import org.apache.cxf.BusFactory;
026: import org.apache.cxf.bus.spring.SpringBusFactory;
027: import org.apache.cxf.message.Message;
028: import org.apache.cxf.message.MessageImpl;
029: import org.junit.BeforeClass;
030: import org.junit.Test;
031:
032: public class JMSConduitTest extends AbstractJMSTester {
033:
034: @BeforeClass
035: public static void createAndStartBroker() throws Exception {
036: startBroker(new JMSBrokerSetup("tcp://localhost:61500"));
037: }
038:
039: @Test
040: public void testGetConfiguration() throws Exception {
041: // setup the new bus to get the configuration file
042: SpringBusFactory bf = new SpringBusFactory();
043: BusFactory.setDefaultBus(null);
044: bus = bf.createBus("/jms_test_config.xml");
045: BusFactory.setDefaultBus(bus);
046: setupServiceInfo("http://cxf.apache.org/jms_conf_test",
047: "/wsdl/jms_test_no_addr.wsdl",
048: "HelloWorldQueueBinMsgService",
049: "HelloWorldQueueBinMsgPort");
050: JMSConduit conduit = setupJMSConduit(false, false);
051: assertEquals("Can't get the right ClientReceiveTimeout", 500L,
052: conduit.getClientConfig().getClientReceiveTimeout());
053: assertEquals(
054: "Can't get the right SessionPoolConfig's LowWaterMark",
055: 10, conduit.getSessionPool().getLowWaterMark());
056: assertEquals(
057: "Can't get the right AddressPolicy's ConnectionPassword",
058: "testPassword", conduit.getJMSAddress()
059: .getConnectionPassword());
060: bus.shutdown(false);
061: BusFactory.setDefaultBus(null);
062:
063: }
064:
065: @Test
066: public void testPrepareSend() throws Exception {
067: setupServiceInfo("http://cxf.apache.org/hello_world_jms",
068: "/wsdl/jms_test.wsdl", "HelloWorldService",
069: "HelloWorldPort");
070:
071: JMSConduit conduit = setupJMSConduit(false, false);
072: Message message = new MessageImpl();
073: try {
074: conduit.prepare(message);
075: } catch (Exception ex) {
076: ex.printStackTrace();
077: }
078: verifySentMessage(false, message);
079: }
080:
081: public void verifySentMessage(boolean send, Message message) {
082: PooledSession pooledSession = (PooledSession) message
083: .get(JMSConstants.JMS_POOLEDSESSION);
084: OutputStream os = message.getContent(OutputStream.class);
085: assertTrue("pooled Session should not be null ",
086: pooledSession != null);
087: assertTrue("OutputStream should not be null", os != null);
088:
089: }
090:
091: @Test
092: public void testSendOut() throws Exception {
093: setupServiceInfo("http://cxf.apache.org/hello_world_jms",
094: "/wsdl/jms_test.wsdl", "HelloWorldServiceLoop",
095: "HelloWorldPortLoop");
096:
097: JMSConduit conduit = setupJMSConduit(true, false);
098: Message message = new MessageImpl();
099: // set the isOneWay to false
100: sendoutMessage(conduit, message, false);
101: verifyReceivedMessage(message);
102: }
103:
104: public void verifyReceivedMessage(Message message) {
105: ByteArrayInputStream bis = (ByteArrayInputStream) inMessage
106: .getContent(InputStream.class);
107: byte bytes[] = new byte[bis.available()];
108: try {
109: bis.read(bytes);
110: } catch (IOException ex) {
111: ex.printStackTrace();
112: }
113: String reponse = new String(bytes);
114: assertEquals("The reponse date should be equals", reponse,
115: "HelloWorld");
116:
117: JMSMessageHeadersType inHeader = (JMSMessageHeadersType) inMessage
118: .get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
119:
120: assertTrue("The inMessage JMS Header should not be null",
121: inHeader != null);
122:
123: }
124:
125: }
|