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: MapMessageTest.java,v 1.6 2004/02/03 07:31:02 tanderson Exp $
44 */
45 package org.exolab.jmscts.test.message.copy;
46
47 import java.util.Arrays;
48
49 import javax.jms.MapMessage;
50
51 import junit.framework.Test;
52
53 import org.exolab.jmscts.core.AbstractMessageTestCase;
54 import org.exolab.jmscts.core.MessagePopulator;
55 import org.exolab.jmscts.core.TestContext;
56 import org.exolab.jmscts.core.TestCreator;
57
58 import org.exolab.jmscts.test.message.util.MessageValues;
59
60
61 /***
62 * This class tests that <code>MapMessage</code> copies byte array content
63 *
64 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
65 * @version $Revision: 1.6 $
66 * @see javax.jms.MapMessage
67 * @see AbstractMessageTestCase
68 * @jmscts.message MapMessage
69 */
70 public class MapMessageTest extends AbstractMessageTestCase
71 implements MessageValues {
72
73 /***
74 * Construct a new <code>MapMessageTest</code>
75 *
76 * @param name the name of test case
77 */
78 public MapMessageTest(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.createMessageTest(MapMessageTest.class);
90 }
91
92 /***
93 * Get the message populator. This implementation always returns null
94 *
95 * @return null
96 */
97 public MessagePopulator getMessagePopulator() {
98 return null;
99 }
100
101 /***
102 * Verifies that <code>MapMessage.setBytes(byte[])</code> takes a copy of
103 * the byte array.
104 *
105 * @jmscts.requirement message.copy
106 * @throws Exception for any error
107 */
108 public void testSetBytesCopy() throws Exception {
109 final int size = 10;
110 final String name = "test";
111 TestContext context = getContext();
112 MapMessage message = (MapMessage) context.getMessage();
113
114 byte[] bytes = new byte[size];
115 Arrays.fill(bytes, (byte) 0);
116 message.setBytes(name, bytes);
117
118 // verify that the input was copied, by modifying it
119 Arrays.fill(bytes, (byte) 1);
120 assertTrue("MapMessage.setBytes(byte[]) did not copy the array",
121 !Arrays.equals(message.getBytes(name), bytes));
122
123 // verify that the return value is not the same each time
124 byte[] value1 = message.getBytes(name);
125 byte[] value2 = message.getBytes(name);
126 assertTrue("MapMessage.getBytes() did not copy the array",
127 value1 != value2);
128 }
129
130 /***
131 * Verifies that <code>MapMessage.setBytes(byte[], int, int)</code> takes
132 * a copy of the byte array.
133 *
134 * @jmscts.requirement message.copy
135 * @throws Exception for any error
136 */
137 public void testPartialSetBytesCopy() throws Exception {
138 final int size = 10;
139 final String name = "test";
140 TestContext context = getContext();
141 MapMessage message = (MapMessage) context.getMessage();
142
143 byte[] bytes = new byte[size];
144 Arrays.fill(bytes, (byte) 0);
145 message.setBytes(name, bytes, 1, size - 1);
146
147 // verify that the input was copied, by modifying it
148 Arrays.fill(bytes, (byte) 1);
149 assertTrue("MapMessage.setBytes(byte[], int, int) did not copy the "
150 + "array", !Arrays.equals(message.getBytes(name), bytes));
151
152 // verify that the return value is not the same each time
153 byte[] value1 = message.getBytes(name);
154 byte[] value2 = message.getBytes(name);
155 assertTrue("MapMessage.getBytes() did not copy the array",
156 value1 != value2);
157 }
158
159 /***
160 * Verifies that <code>MapMessage.setObject()</code> copies byte arrays
161 *
162 * @jmscts.requirement message.copy
163 * @throws Exception for any error
164 */
165 public void testByteArrayCopy() throws Exception {
166 final int size = 10;
167 final String name = "test";
168 TestContext context = getContext();
169 MapMessage message = (MapMessage) context.getMessage();
170
171 byte[] bytes = new byte[size];
172 Arrays.fill(bytes, (byte) 0);
173 message.setObject(name, bytes);
174
175 // verify that the input was copied, by modifying it
176 Arrays.fill(bytes, (byte) 1);
177 byte[] value = (byte[]) message.getObject(name);
178 assertTrue("MapMessage.setObject() did not copy the byte array",
179 !Arrays.equals(value, bytes));
180
181 // verify that the return value is not the same each time
182 byte[] value1 = (byte[]) message.getObject(name);
183 byte[] value2 = (byte[]) message.getObject(name);
184 assertTrue("MapMessage.getObject() did not copy the byte array",
185 value1 != value2);
186 }
187
188 }
This page was automatically generated by Maven