1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact tma@netspace.net.au.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2001-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: PropertyTest.java,v 1.5 2004/02/03 07:31:03 tanderson Exp $
44 */
45 package org.exolab.jmscts.test.message.properties;
46
47 import java.util.Map;
48 import java.util.Set;
49
50 import javax.jms.Message;
51
52 import junit.framework.Test;
53
54 import org.exolab.jmscts.core.AbstractSendReceiveTestCase;
55 import org.exolab.jmscts.core.TestCreator;
56
57
58 /***
59 * This class tests that message properties set before a message is sent are
60 * identical to those received.
61 *
62 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
63 * @version $Revision: 1.5 $
64 * @see AbstractSendReceiveTestCase
65 */
66 public class PropertyTest extends AbstractSendReceiveTestCase {
67
68 /***
69 * The destination used by this test case
70 */
71 private static final String DESTINATION = "PropertyTest";
72
73
74 /***
75 * Construct a new <code>PropertyTest</code>
76 *
77 * @param name the name of test case
78 */
79 public PropertyTest(String name) {
80 super(name);
81 }
82
83 /***
84 * Sets up the test suite
85 *
86 * @return an instance of this class that may be run by
87 * {@link org.exolab.jmscts.core.JMSTestRunner}
88 */
89 public static Test suite() {
90 return TestCreator.createSendReceiveTest(PropertyTest.class);
91 }
92
93 /***
94 * Returns the list of destination names used by this test case. These
95 * are used to pre-create destinations prior to running the test case.
96 *
97 * @return the list of destinations used by this test case
98 */
99 public String[] getDestinations() {
100 return new String[] {DESTINATION};
101 }
102
103 /***
104 * Verifies that user properties are not modified when a message is sent
105 * and subsequently received.
106 *
107 * @jmscts.requirement properties.integrity
108 * @jmscts.requirement properties.method.getPropertyNames
109 * @throws Exception for any error
110 */
111 public void testPropertyIntegrity() throws Exception {
112 Message message = getContext().getMessage();
113
114 // the properties prior to the message being sent
115 Map beforeProperties = null;
116
117 // the properties after the message is sent
118 Map afterProperties = null;
119
120 // the properties of the received message
121 Map receivedProperties = null;
122
123 Set names = PropertyHelper.setProperties(message);
124 beforeProperties = PropertyHelper.getProperties(message);
125
126 // verify that all of the expected properties are available
127 if (!names.equals(beforeProperties.keySet())) {
128 fail("The list of property names returned by getPropertyNames() "
129 + "is different to that set");
130 }
131
132 // send the message to the provider, and wait to receive it back
133 Message received = sendReceive(message, DESTINATION);
134
135 // check the properties of the message after it was sent
136 afterProperties = PropertyHelper.getProperties(message);
137 if (!beforeProperties.equals(afterProperties)) {
138 fail("The list of property names returned by getPropertyNames() "
139 + "on the received message is different to that set");
140 }
141
142 // check the properties of the received message, after removing
143 // any provider properties
144 receivedProperties = PropertyHelper.getProperties(received);
145 Object[] keys = receivedProperties.keySet().toArray();
146 for (int i = 0; i < keys.length; ++i) {
147 String name = (String) keys[i];
148 if (name.startsWith("JMSX") || name.startsWith("JMS_")) {
149 receivedProperties.remove(name);
150 }
151 }
152
153 if (!beforeProperties.equals(receivedProperties)) {
154 String msg = "Properties sent don't match those received";
155 fail(msg);
156 }
157
158 // check that the properties can be set after they are cleared
159 received.clearProperties();
160 PropertyHelper.setProperties(received);
161 }
162
163 /***
164 * Verifies that JMS standard header fields are not returned by
165 * getPropertyNames().
166 *
167 * @jmscts.requirement properties.method.getPropertyNames
168 * @throws Exception for any error
169 */
170 public void testPropertyNames() throws Exception {
171 // the list of JMS header field names
172 final String[] headerNames = {
173 "JMSDestination", "JMSDeliveryMode", "JMSExpiration",
174 "JMSPriority", "JMSMessageID", "JMSTimestamp", "JMSCorrelationID",
175 "JMSReplyTo", "JMSType", "JMSRedelivered"};
176
177 // make sure no header properties are available prior to sending
178 Message message = getContext().getMessage();
179 for (int i = 0; i < headerNames.length; ++i) {
180 if (message.propertyExists(headerNames[i])) {
181 fail("Message.propertyExists() returned true for JMS header "
182 + "field=" + headerNames[i]);
183 }
184 }
185
186 // make sure no header properties are available after sending, and on
187 // receipt
188 Message received = sendReceive(message, DESTINATION);
189 for (int i = 0; i < headerNames.length; ++i) {
190 if (message.propertyExists(headerNames[i])) {
191 fail("Message.propertyExists() returned true for JMS header "
192 + "field=" + headerNames[i] + " after the message "
193 + "was sent");
194 }
195 if (received.propertyExists(headerNames[i])) {
196 fail("Message.propertyExists() returned true for JMS header "
197 + "field=" + headerNames[i] + " for a received message");
198 }
199 }
200 }
201
202 }
This page was automatically generated by Maven