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: JMSXGroupTest.java,v 1.5 2004/02/03 07:31:03 tanderson Exp $
44 */
45 package org.exolab.jmscts.test.message.properties;
46
47 import javax.jms.JMSException;
48 import javax.jms.Message;
49 import javax.jms.MessageFormatException;
50
51 import junit.framework.Test;
52
53 import org.exolab.jmscts.core.AbstractMessageTestCase;
54 import org.exolab.jmscts.core.ClassHelper;
55 import org.exolab.jmscts.core.TestCreator;
56
57
58 /***
59 * This class tests that connections support JMSXGroupID and JMSXGroupSeq
60 * properties <br/>
61 * NOTE: the specification is not clear on the behaviour of null values
62 * for these properties.
63 *
64 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
65 * @version $Revision: 1.5 $
66 * @see AbstractMessageTestCase
67 */
68 public class JMSXGroupTest extends AbstractMessageTestCase {
69
70 /***
71 * The JMSXGroupID property name
72 */
73 private static final String GROUP_ID = "JMSXGroupID";
74
75 /***
76 * The JMSXGroupSeq property name
77 */
78 private static final String GROUP_SEQ = "JMSXGroupSeq";
79
80 /***
81 * Invalid values for JMSXGroupID
82 */
83 private static final Object[] INVALID_GROUP_ID_VALUES = {
84 Boolean.TRUE, new Byte(Byte.MIN_VALUE), new Short(Short.MIN_VALUE),
85 new Character(Character.MIN_VALUE), new Integer(Integer.MIN_VALUE),
86 new Float(Float.MIN_VALUE), new Double(Double.MIN_VALUE)};
87
88 /***
89 * Invalid values for JMSGroupSeq
90 */
91 private static final Object[] INVALID_GROUP_SEQ_VALUES = {
92 Boolean.TRUE, new Byte(Byte.MIN_VALUE), new Short(Short.MIN_VALUE),
93 new Character(Character.MIN_VALUE), new Float(Float.MIN_VALUE),
94 new Double(Double.MIN_VALUE), "abc"};
95
96
97 /***
98 * Construct a new <code>JMSXGroupTest</code>
99 *
100 * @param name the name of test case
101 */
102 public JMSXGroupTest(String name) {
103 super(name);
104 }
105
106 /***
107 * Sets up the test suite
108 *
109 * @return an instance of this class that may be run by
110 * {@link org.exolab.jmscts.core.JMSTestRunner}
111 */
112 public static Test suite() {
113 return TestCreator.createMessageTest(JMSXGroupTest.class);
114 }
115
116 /***
117 * Verifies that the only allowed type for JMSXGroupID is a String.
118 *
119 * @jmscts.requirement properties.group
120 * @throws Exception for any error
121 */
122 public void testJMSXGroupID() throws Exception {
123 Message message = getContext().getMessage();
124 for (int i = 0; i < INVALID_GROUP_ID_VALUES.length; ++i) {
125 Object value = INVALID_GROUP_ID_VALUES[i];
126 checkProperty(message, GROUP_ID, value);
127 }
128 }
129
130 /***
131 * Verifies that the only allowed type for JMSXGroupID is an int.
132 *
133 * @jmscts.requirement properties.group
134 * @throws Exception for any error
135 */
136 public void testJMSGroupSeq() throws Exception {
137 Message message = getContext().getMessage();
138 for (int i = 0; i < INVALID_GROUP_SEQ_VALUES.length; ++i) {
139 Object value = INVALID_GROUP_SEQ_VALUES[i];
140 checkProperty(message, GROUP_SEQ, value);
141 }
142 }
143
144 /***
145 * Verifies that JMSXGroupSeq only handles ints > 0
146 * @todo - not sure if this test case is valid in terms of the
147 * specification
148 *
149 * @jmscts.requirement properties.group
150 * @throws Exception for any error
151 */
152 public void testJMSGroupSeqRange() throws Exception {
153 Message message = getContext().getMessage();
154 checkSequenceValue(message, -1, false);
155 checkSequenceValue(message, 0, false);
156 checkSequenceValue(message, 1, true);
157 checkSequenceValue(message, Integer.MAX_VALUE, true);
158 }
159
160 /***
161 * Verifies that atttempting to use an invalid property value
162 * throws <code>MessageFormatException</code>
163 *
164 * @param message the message to populate
165 * @param name the property name
166 * @param value the property value
167 * @throws Exception for any error
168 */
169 private void checkProperty(Message message, String name, Object value)
170 throws Exception {
171
172 // javax.jms.Message doesn't provide an interface for populating
173 // char primitives. The setObjectProperty method should throw
174 // MessageFormatException for Character instances.
175
176 if (!(value instanceof Character)) {
177 try {
178 PropertyHelper.setPrimitiveProperty(message, name, value);
179 fail("Managed to use invalid type="
180 + ClassHelper.getPrimitiveName(value.getClass())
181 + " for property=" + name);
182 } catch (MessageFormatException expected) {
183 // the expected behaviour
184 } catch (Exception exception) {
185 fail("Expected MessageFormatException to be thrown when "
186 + "setting property=" + name + " with type="
187 + ClassHelper.getPrimitiveName(value.getClass())
188 + " but got exception=" + exception.getClass().getName()
189 + ", message=" + exception.getMessage());
190 }
191 }
192
193 try {
194 message.setObjectProperty(name, value);
195 fail("Managed to use invalid type="
196 + ClassHelper.getPrimitiveName(value.getClass())
197 + " for property=" + name);
198 } catch (MessageFormatException expected) {
199 // the expected behaviour
200 } catch (Exception exception) {
201 fail("Expected MessageFormatException to be thrown when "
202 + "setting property=" + name + " with type="
203 + ClassHelper.getPrimitiveName(value.getClass())
204 + " but got exception=" + exception.getClass().getName()
205 + ", message=" + exception.getMessage());
206 }
207 }
208
209 /***
210 * Verifies a value for the JMSXGroupSeq property
211 *
212 * @param message the message to populate
213 * @param value the value to populate
214 * @param valid determines if the value is a valid
215 * @throws Exception for any error
216 */
217 private void checkSequenceValue(Message message, int value, boolean valid)
218 throws Exception {
219
220 checkSequenceValue(message, value, valid, true);
221 checkSequenceValue(message, value, valid, false);
222 }
223
224 /***
225 * Verifies a value for the JMSXGroupSeq property
226 *
227 * @param message the message to populate
228 * @param value the value to populate
229 * @param valid determines if the value is a valid
230 * @param primitive if <code>true</code> uses setIntProperty() to populate
231 * the value, else uses setObjectProperty()
232 * @throws Exception for any error
233 */
234 private void checkSequenceValue(Message message, int value, boolean valid,
235 boolean primitive) throws Exception {
236 try {
237 if (primitive) {
238 message.setIntProperty(GROUP_SEQ, value);
239 } else {
240 message.setObjectProperty(GROUP_SEQ, new Integer(value));
241 }
242 if (!valid) {
243 fail("Managed to use invalid int=" + value + " for property="
244 + GROUP_SEQ);
245 }
246 } catch (JMSException exception) {
247 if (valid) {
248 fail("Valid int value=" + value + " for property=" + GROUP_SEQ
249 + " threw exception=" + exception.getClass()
250 + ", message=" + exception.getMessage());
251 }
252 } catch (Exception exception) {
253 if (valid) {
254 fail("Valid int value=" + value + " for property="
255 + GROUP_SEQ + " threw exception=" + exception.getClass()
256 + ", message=" + exception.getMessage());
257 } else {
258 fail("Expected JMSException to be thrown when "
259 + "setting property=" + GROUP_SEQ + " with value=" + value
260 + " but got exception=" + exception.getClass().getName()
261 + ", message=" + exception.getMessage());
262 }
263 }
264 }
265
266 }
This page was automatically generated by Maven