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: BytesMessageVerifier.java,v 1.2 2004/02/03 07:31:04 tanderson Exp $
44 */
45 package org.exolab.jmscts.test.message.util;
46
47 import javax.jms.BytesMessage;
48
49 import org.exolab.jmscts.core.MethodCache;
50
51
52 /***
53 * A helper class for populating and verifying the content of BytesMessage
54 * instances.
55 *
56 * @version $Revision: 1.2 $ $Date: 2004/02/03 07:31:04 $
57 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
58 * @see MessagePopulatorVerifier
59 */
60 class BytesMessageVerifier extends MessagePopulatorVerifier {
61
62 /***
63 * Method cache for BytesMessage
64 */
65 private static MethodCache _methods = null;
66
67 /***
68 * Byte array size
69 */
70 private static final int BYTE_ARRAY_SIZE = 10;
71
72
73 /***
74 * Construct a new instance. No exceptions are expected to be thrown
75 * when invoking methods
76 */
77 public BytesMessageVerifier() {
78 }
79
80 /***
81 * Construct an instance with the expected exception thrown when
82 * methods are invoked
83 *
84 * @param exception the expected exception type when methods are invoked
85 */
86 public BytesMessageVerifier(Class exception) {
87 super(exception);
88 }
89
90 /***
91 * Attempt to populate a BytesMessage instance with data
92 *
93 * @param message the message to populate
94 * @throws Exception for any error
95 */
96 public void populateBytesMessage(BytesMessage message) throws Exception {
97 byte[] bytes = populateByteArray(BYTE_ARRAY_SIZE, 0);
98 invoke(message, "writeBoolean", Boolean.TRUE);
99 invoke(message, "writeByte", new Byte(Byte.MIN_VALUE));
100 invoke(message, "writeByte", new Byte((byte) 0xFF));
101 invoke(message, "writeBytes", bytes);
102
103 Object[] args = {bytes, new Integer(1), new Integer(bytes.length - 2)};
104 invoke(message, "writeBytes", args);
105 invoke(message, "writeShort", new Short(Short.MIN_VALUE));
106 invoke(message, "writeShort", new Short((short) 0xFFFF));
107 invoke(message, "writeChar", new Character(Character.MIN_VALUE));
108 invoke(message, "writeInt", new Integer(Integer.MIN_VALUE));
109 invoke(message, "writeLong", new Long(Long.MIN_VALUE));
110 invoke(message, "writeFloat", new Float(Float.MIN_VALUE));
111 invoke(message, "writeDouble", new Double(Double.MIN_VALUE));
112 invoke(message, "writeUTF", "ABC");
113
114 invoke(message, "writeObject", Boolean.TRUE);
115 invoke(message, "writeObject", new Byte(Byte.MAX_VALUE));
116 invoke(message, "writeObject", bytes);
117 invoke(message, "writeObject", new Short(Short.MAX_VALUE));
118 invoke(message, "writeObject", new Character(Character.MAX_VALUE));
119 invoke(message, "writeObject", new Integer(Integer.MAX_VALUE));
120 invoke(message, "writeObject", new Long(Long.MAX_VALUE));
121 invoke(message, "writeObject", new Float(Float.MAX_VALUE));
122 invoke(message, "writeObject", new Double(Double.MAX_VALUE));
123 invoke(message, "writeObject", "ABC");
124 }
125
126 /***
127 * Attempt to verify the content of a BytesMessage populated via the above
128 * {@link #populateBytesMessage}.
129 *
130 * @param message the message to verify
131 * @throws Exception for any error
132 */
133 public void verifyBytesMessage(BytesMessage message) throws Exception {
134 expect(message, "readBoolean", Boolean.TRUE);
135 expect(message, "readByte", new Byte(Byte.MIN_VALUE));
136 expect(message, "readUnsignedByte", new Integer(0xFF));
137
138 byte[] buffer1 = new byte[BYTE_ARRAY_SIZE];
139 expect(message, "readBytes", buffer1, new Integer(buffer1.length));
140 equal(buffer1, populateByteArray(buffer1.length, 0));
141
142 byte[] buffer2 = new byte[BYTE_ARRAY_SIZE - 2];
143 Object[] args = {buffer2, new Integer(buffer2.length)};
144 expect(message, "readBytes", args, new Integer(buffer2.length));
145 equal(buffer2, populateByteArray(buffer2.length, 1));
146
147 expect(message, "readShort", new Short(Short.MIN_VALUE));
148 expect(message, "readUnsignedShort", new Integer(0xFFFF));
149 expect(message, "readChar", new Character(Character.MIN_VALUE));
150 expect(message, "readInt", new Integer(Integer.MIN_VALUE));
151 expect(message, "readLong", new Long(Long.MIN_VALUE));
152 expect(message, "readFloat", new Float(Float.MIN_VALUE));
153 expect(message, "readDouble", new Double(Double.MIN_VALUE));
154 expect(message, "readUTF", "ABC");
155
156 expect(message, "readBoolean", Boolean.TRUE);
157 expect(message, "readByte", new Byte(Byte.MAX_VALUE));
158
159 byte[] buffer3 = new byte[BYTE_ARRAY_SIZE];
160 expect(message, "readBytes", buffer3, new Integer(buffer3.length));
161 equal(buffer3, populateByteArray(buffer3.length, 0));
162
163 expect(message, "readShort", new Short(Short.MAX_VALUE));
164 expect(message, "readChar", new Character(Character.MAX_VALUE));
165 expect(message, "readInt", new Integer(Integer.MAX_VALUE));
166 expect(message, "readLong", new Long(Long.MAX_VALUE));
167 expect(message, "readFloat", new Float(Float.MAX_VALUE));
168 expect(message, "readDouble", new Double(Double.MAX_VALUE));
169 expect(message, "readUTF", "ABC");
170 }
171
172 /***
173 * Returns a cache of the <code>BytesMessage</code> methods
174 *
175 * @return a cache of the <code>BytesMessage</code> methods
176 */
177 protected synchronized MethodCache getMethods() {
178 if (_methods == null) {
179 _methods = new MethodCache(BytesMessage.class);
180 }
181 return _methods;
182 }
183
184 }
This page was automatically generated by Maven