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: StreamMessageTest.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.StreamMessage;
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 import org.exolab.jmscts.test.message.util.MessageValues;
58
59
60 /***
61 * This class verifies that <code>StreamMessage</code> copies content
62 *
63 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
64 * @version $Revision: 1.6 $
65 * @see javax.jms.StreamMessage
66 * @see AbstractMessageTestCase
67 * @see org.exolab.jmscts.core.MessageTestRunner
68 * @jmscts.message StreamMessage
69 */
70 public class StreamMessageTest extends AbstractMessageTestCase
71 implements MessageValues {
72
73 /***
74 * Construct a new <code>StreamMessageTest</code>
75 *
76 * @param name the name of test case
77 */
78 public StreamMessageTest(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(StreamMessageTest.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>StreamMessage.writeBytes(byte[])</code> takes a copy
103 * of the byte array.
104 *
105 * @jmscts.requirement message.copy
106 * @throws Exception for any error
107 */
108 public void testWriteBytesCopy() throws Exception {
109 final int size = 10;
110 TestContext context = getContext();
111 StreamMessage message = (StreamMessage) context.getMessage();
112
113 byte[] bytes = new byte[size];
114 Arrays.fill(bytes, (byte) 0);
115 message.writeBytes(bytes);
116 message.reset();
117
118 // verify that the input was copied, by modifying it
119 Arrays.fill(bytes, (byte) 1);
120 byte[] buffer = new byte[size];
121 message.readBytes(buffer);
122 assertTrue("StreamMessage.writeBytes(byte[]) did not copy the array",
123 !Arrays.equals(buffer, bytes));
124 }
125
126 /***
127 * Verifies that <code>StreamMessage.writeBytes(byte[], int, int)</code>
128 * takes a copy of the byte array.
129 *
130 * @jmscts.requirement message.copy
131 * @throws Exception for any error
132 */
133 public void testPartialWriteBytesCopy() throws Exception {
134 final int size = 10;
135 TestContext context = getContext();
136 StreamMessage message = (StreamMessage) context.getMessage();
137
138 byte[] bytes = new byte[size];
139 Arrays.fill(bytes, (byte) 0);
140 message.writeBytes(bytes, 1, size - 1);
141 message.reset();
142
143 // verify that the input was copied, by modifying it
144 Arrays.fill(bytes, (byte) 1);
145 byte[] buffer = new byte[size];
146 message.readBytes(buffer);
147 assertTrue("StreamMessage.writeBytes(byte[], int, int) did not copy "
148 + "the array", !Arrays.equals(buffer, bytes));
149 }
150
151 /***
152 * Verifies that <code>StreamMessage.setObject()</code> copies byte arrays
153 *
154 * @jmscts.requirement message.copy
155 * @throws Exception for any error
156 */
157 public void testByteArrayCopy() throws Exception {
158 final int size = 10;
159 TestContext context = getContext();
160 StreamMessage message = (StreamMessage) context.getMessage();
161
162 byte[] bytes = new byte[size];
163 Arrays.fill(bytes, (byte) 0);
164 message.writeObject(bytes);
165 message.reset();
166
167 // verify that the input was copied, by modifying it
168 Arrays.fill(bytes, (byte) 1);
169 byte[] buffer = (byte[]) message.readObject();
170 assertTrue("StreamMessage.writeObject() did not copy the array",
171 !Arrays.equals(buffer, bytes));
172 }
173
174 }
This page was automatically generated by Maven