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 2004 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: JMSCorrelationIDTest.java,v 1.2 2004/02/03 07:31:02 tanderson Exp $
44 */
45 package org.exolab.jmscts.test.message.header;
46
47 import java.util.Arrays;
48
49 import javax.jms.JMSException;
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.TestContext;
56 import org.exolab.jmscts.core.TestCreator;
57
58
59 /***
60 * This class tests the JMSCorrelationID message property
61 *
62 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
63 * @version $Revision: 1.2 $
64 * @see AbstractSendReceiveTestCase
65 */
66 public class JMSCorrelationIDTest extends AbstractSendReceiveTestCase {
67
68 /***
69 * The default destination
70 */
71 private static final String DESTINATION = "JMSCorrelationIDTest";
72
73 /***
74 * Construct a new <code>JMSCorrelationIDTest</code>
75 *
76 * @param name the name of test case
77 */
78 public JMSCorrelationIDTest(String name) {
79 super(name);
80 }
81
82 /***
83 * Sets up the test suite
84 *
85 * @return an instance of this class that may be run by
86 * {@link org.exolab.jmscts.core.JMSTestRunner}
87 */
88 public static Test suite() {
89 return TestCreator.createSendReceiveTest(JMSCorrelationIDTest.class);
90 }
91
92 /***
93 * Returns the list of destination names used by this test case. These
94 * are used to pre-administer destinations prior to running the test case.
95 *
96 * @return the list of destinations used by this test case
97 */
98 public String[] getDestinations() {
99 return new String[] {DESTINATION};
100 }
101
102 /***
103 * Verifies that the JMSCorrelationID header property can be set,
104 * and that the received message has the same JMSCorrelationID value
105 * as that sent
106 *
107 * @jmscts.requirement message.correlation
108 * @throws Exception for any error
109 */
110 public void testCorrelationID() throws Exception {
111 TestContext context = getContext();
112 Message message = context.getMessage();
113
114 assertNull("getJMSCorrelationID() should return null, as no value is "
115 + "set", message.getJMSCorrelationID());
116
117 String correlationID = "my correlation Id";
118 try {
119 message.setJMSCorrelationID(correlationID);
120 } catch (JMSException exception) {
121 fail("Failed to set a valid application specific correlation ID");
122 }
123
124 // send the message, and receive it from the same destination
125 Message received = sendReceive(message, DESTINATION);
126
127 // make sure the correlation ID properties are the same
128 assertEquals(
129 "JMSCorrelationID on received message doesn't match that sent",
130 correlationID, received.getJMSCorrelationID());
131 }
132
133 /***
134 * Verifies that a null can be assigned to JMSCorrelationID when:
135 * <ul>
136 * <li>a message is intially constructed</li>
137 * <li>a message is received with a non-null JMSCorrelationID</li>
138 * </ul>
139 *
140 * @jmscts.requirement message.correlation
141 * @jmscts.delivery consumer
142 * @throws Exception for any error
143 */
144 public void testNullCorrelationID() throws Exception {
145 TestContext context = getContext();
146 Message message = context.getMessage();
147
148 try {
149 message.setJMSCorrelationID(null);
150 } catch (JMSException exception) {
151 fail("Failed to set JMSCorrelationID to null");
152 }
153
154 String correlationID = "a correlation Id";
155 message.setJMSCorrelationID(correlationID);
156
157 // send the message, and receive it from the same destination
158 Message received1 = sendReceive(message, DESTINATION);
159 assertEquals(
160 "JMSCorrelationID on received message doesn't match that sent",
161 correlationID, received1.getJMSCorrelationID());
162
163 // resend the message, after settting its JMSCorrelationID to null,
164 // and verify that the received message also has a null
165 // JMSCorrelationID
166 try {
167 received1.setJMSCorrelationID(null);
168 } catch (JMSException exception) {
169 fail("Failed to set JMSCorrelationID on received message to null");
170 }
171 Message received2 = sendReceive(received1, DESTINATION);
172 assertNull("JMSCorrelationID on received message should be null",
173 received2.getJMSCorrelationID());
174 }
175
176 /***
177 * Verifies the behaviour of the JMSCorrelationIDAsBytes methods.
178 *
179 * @jmscts.requirement message.correlation.bytes
180 * @throws Exception for any error
181 */
182 public void testCorrelationIDAsBytes() throws Exception {
183 final int size = 10;
184 TestContext context = getContext();
185 Message message = context.getMessage();
186
187 byte[] masterId = new byte[size];
188 byte[] id = new byte[size];
189 for (int i = 0; i < size; ++i) {
190 masterId[i] = (byte) i;
191 id[i] = masterId[i];
192 }
193
194 try {
195 if (message.getJMSCorrelationIDAsBytes() != null) {
196 fail("getJMSCorrelationIDAsBytes() should return null, "
197 + "as no value is set");
198 }
199 message.setJMSCorrelationIDAsBytes(id);
200
201 // the method must take a copy of the byte array
202 Arrays.fill(id, (byte) 0);
203 assertTrue(message.getJMSCorrelationIDAsBytes() != id);
204 assertTrue(!Arrays.equals(
205 id, message.getJMSCorrelationIDAsBytes()));
206
207 // send the message, and receive it from the same destination
208 Message received = sendReceive(message, DESTINATION);
209
210 // verify that the correlation ids are identical
211 assertTrue(Arrays.equals(
212 masterId, received.getJMSCorrelationIDAsBytes()));
213 } catch (UnsupportedOperationException ignore) {
214 context.getCoverage().setUnsupported("message.correlation.bytes");
215 }
216 }
217
218 }
This page was automatically generated by Maven