1   /*
2    * Copyright 2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.transport.jms.support;
18  
19  import java.net.URI;
20  import javax.jms.DeliveryMode;
21  import javax.jms.Message;
22  
23  import junit.framework.TestCase;
24  
25  import org.springframework.ws.transport.jms.JmsTransportConstants;
26  
27  public class JmsTransportUtilsTest extends TestCase {
28  
29      public void testGetDestinationName() throws Exception {
30          URI uri = new URI("jms:RequestQueue?replyToName=RESP_QUEUE");
31          String destinationName = JmsTransportUtils.getDestinationName(uri);
32          assertEquals("Invalid destination", "RequestQueue", destinationName);
33  
34          uri = new URI("jms:RequestQueue");
35          destinationName = JmsTransportUtils.getDestinationName(uri);
36          assertEquals("Invalid destination", "RequestQueue", destinationName);
37      }
38  
39      public void testGetDeliveryMode() throws Exception {
40          URI uri = new URI("jms:RequestQueue?deliveryMode=NON_PERSISTENT");
41          int deliveryMode = JmsTransportUtils.getDeliveryMode(uri);
42          assertEquals("Invalid deliveryMode", DeliveryMode.NON_PERSISTENT, deliveryMode);
43  
44          uri = new URI("jms:RequestQueue?deliveryMode=PERSISTENT");
45          deliveryMode = JmsTransportUtils.getDeliveryMode(uri);
46          assertEquals("Invalid deliveryMode", DeliveryMode.PERSISTENT, deliveryMode);
47  
48          uri = new URI("jms:RequestQueue?replyToName=RESP_QUEUE");
49          deliveryMode = JmsTransportUtils.getDeliveryMode(uri);
50          assertEquals("Invalid deliveryMode", Message.DEFAULT_DELIVERY_MODE, deliveryMode);
51      }
52  
53      public void testGetMessageType() throws Exception {
54          URI uri = new URI("jms:RequestQueue?messageType=BYTESMESSAGE");
55          int messageType = JmsTransportUtils.getMessageType(uri);
56          assertEquals("Invalid messageType", JmsTransportConstants.BYTES_MESSAGE_TYPE, messageType);
57  
58          uri = new URI("jms:RequestQueue?messageType=TEXT_MESSAGE");
59          messageType = JmsTransportUtils.getMessageType(uri);
60          assertEquals("Invalid messageType", JmsTransportConstants.TEXT_MESSAGE_TYPE, messageType);
61  
62          uri = new URI("jms:RequestQueue?replyToName=RESP_QUEUE");
63          messageType = JmsTransportUtils.getMessageType(uri);
64          assertEquals("Invalid messageType", JmsTransportConstants.BYTES_MESSAGE_TYPE, messageType);
65      }
66  
67      public void testGetTimeToLive() throws Exception {
68          URI uri = new URI("jms:RequestQueue?timeToLive=100");
69          long timeToLive = JmsTransportUtils.getTimeToLive(uri);
70          assertEquals("Invalid timeToLive", 100, timeToLive);
71  
72          uri = new URI("jms:RequestQueue?replyToName=RESP_QUEUE");
73          timeToLive = JmsTransportUtils.getTimeToLive(uri);
74          assertEquals("Invalid timeToLive", Message.DEFAULT_TIME_TO_LIVE, timeToLive);
75      }
76  
77      public void testGetPriority() throws Exception {
78          URI uri = new URI("jms:RequestQueue?priority=5");
79          int priority = JmsTransportUtils.getPriority(uri);
80          assertEquals("Invalid priority", 5, priority);
81  
82          uri = new URI("jms:RequestQueue?replyToName=RESP_QUEUE");
83          priority = JmsTransportUtils.getPriority(uri);
84          assertEquals("Invalid priority", Message.DEFAULT_PRIORITY, priority);
85      }
86  
87      public void testGetReplyToName() throws Exception {
88          URI uri = new URI("jms:RequestQueue?replyToName=RESP_QUEUE");
89          String replyToName = JmsTransportUtils.getReplyToName(uri);
90          assertEquals("Invalid replyToName", "RESP_QUEUE", replyToName);
91  
92          uri = new URI("jms:RequestQueue?priority=5");
93          replyToName = JmsTransportUtils.getReplyToName(uri);
94          assertNull("Invalid replyToName", replyToName);
95      }
96  
97      public void testJndi() throws Exception {
98          URI uri = new URI("jms:jms/REQUEST_QUEUE?replyToName=jms/REPLY_QUEUE");
99          String destination = JmsTransportUtils.getDestinationName(uri);
100         assertEquals("Invalid destination name", "jms/REQUEST_QUEUE", destination);
101 
102         String replyTo = JmsTransportUtils.getReplyToName(uri);
103         assertEquals("Invalid reply to name", "jms/REPLY_QUEUE", replyTo);
104     }
105 }