View Javadoc
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: MapMessageVerifier.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.MapMessage; 48 import javax.jms.Message; 49 50 import org.exolab.jmscts.core.MethodCache; 51 52 53 /*** 54 * A helper class for populating and verifying the content of MapMessage 55 * instances. 56 * 57 * @version $Revision: 1.2 $ $Date: 2004/02/03 07:31:04 $ 58 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 59 * @see MessagePopulatorVerifier 60 */ 61 class MapMessageVerifier extends MessagePopulatorVerifier { 62 63 /*** 64 * Method cache for MapMessage 65 */ 66 private static MethodCache _methods = null; 67 68 /*** 69 * Seed value used for value names 70 */ 71 private int _seed = 0; 72 73 /*** 74 * Byte array size 75 */ 76 private static final int BYTE_ARRAY_SIZE = 10; 77 78 79 /*** 80 * Construct a new instance. No exceptions are expected to be thrown 81 * when invoking methods 82 */ 83 public MapMessageVerifier() { 84 } 85 86 /*** 87 * Construct an instance with the expected exception thrown when 88 * methods are invoked 89 * 90 * @param exception the expected exception type when methods are invoked 91 */ 92 public MapMessageVerifier(Class exception) { 93 super(exception); 94 } 95 96 /*** 97 * Attempt to populate a MapMessage instance with data 98 * 99 * @param message the message to populate 100 * @throws Exception for any error 101 */ 102 public void populateMapMessage(MapMessage message) throws Exception { 103 byte[] bytes = new byte[BYTE_ARRAY_SIZE]; 104 _seed = 0; 105 set(message, "setBoolean", Boolean.TRUE); 106 set(message, "setByte", new Byte(Byte.MIN_VALUE)); 107 set(message, "setBytes", bytes); 108 109 Object[] args = {bytes, new Integer(1), new Integer(bytes.length - 2)}; 110 set(message, "setBytes", args); 111 set(message, "setChar", new Character(Character.MIN_VALUE)); 112 set(message, "setDouble", new Double(Double.MIN_VALUE)); 113 set(message, "setFloat", new Float(Float.MIN_VALUE)); 114 set(message, "setInt", new Integer(Integer.MIN_VALUE)); 115 set(message, "setLong", new Long(Long.MIN_VALUE)); 116 set(message, "setShort", new Short(Short.MIN_VALUE)); 117 set(message, "setString", "ABC"); 118 119 set(message, "setObject", Boolean.TRUE); 120 set(message, "setObject", new Byte(Byte.MAX_VALUE)); 121 set(message, "setObject", bytes); 122 set(message, "setObject", new Character(Character.MAX_VALUE)); 123 set(message, "setObject", new Double(Double.MAX_VALUE)); 124 set(message, "setObject", new Float(Float.MAX_VALUE)); 125 set(message, "setObject", new Integer(Integer.MAX_VALUE)); 126 set(message, "setObject", new Long(Long.MAX_VALUE)); 127 set(message, "setObject", new Short(Short.MAX_VALUE)); 128 set(message, "setObject", "ABC"); 129 } 130 131 /*** 132 * Attempt to verify the content of a MapMessage populated via the above 133 * {@link #populateMapMessage}. 134 * 135 * @param message the message to verify 136 * @throws Exception for any error 137 */ 138 public void verifyMapMessage(MapMessage message) throws Exception { 139 _seed = 0; 140 get(message, "getBoolean", Boolean.TRUE); 141 get(message, "getByte", new Byte(Byte.MIN_VALUE)); 142 get(message, "getBytes", new byte[BYTE_ARRAY_SIZE]); 143 144 get(message, "getBytes", new byte[BYTE_ARRAY_SIZE - 2]); 145 get(message, "getChar", new Character(Character.MIN_VALUE)); 146 get(message, "getDouble", new Double(Double.MIN_VALUE)); 147 get(message, "getFloat", new Float(Float.MIN_VALUE)); 148 get(message, "getInt", new Integer(Integer.MIN_VALUE)); 149 get(message, "getLong", new Long(Long.MIN_VALUE)); 150 get(message, "getShort", new Short(Short.MIN_VALUE)); 151 get(message, "getString", "ABC"); 152 153 get(message, "getObject", Boolean.TRUE); 154 get(message, "getObject", new Byte(Byte.MAX_VALUE)); 155 get(message, "getObject", new byte[BYTE_ARRAY_SIZE]); 156 get(message, "getObject", new Character(Character.MAX_VALUE)); 157 get(message, "getObject", new Double(Double.MAX_VALUE)); 158 get(message, "getObject", new Float(Float.MAX_VALUE)); 159 get(message, "getObject", new Integer(Integer.MAX_VALUE)); 160 get(message, "getObject", new Long(Long.MAX_VALUE)); 161 get(message, "getObject", new Short(Short.MAX_VALUE)); 162 get(message, "getObject", "ABC"); 163 } 164 165 /*** 166 * Set a message property 167 * 168 * @param message the message 169 * @param method the method to invoke 170 * @param value the value to set 171 * @throws Exception for any error 172 */ 173 protected void set(Message message, String method, Object value) 174 throws Exception { 175 Object[] args = {"name" + ++_seed, value}; 176 invoke(message, method, args); 177 } 178 179 /*** 180 * Set a message array property 181 * 182 * @param message the message 183 * @param method the method to invoke 184 * @param values the values to set 185 * @throws Exception for any error 186 */ 187 protected void set(Message message, String method, Object[] values) 188 throws Exception { 189 Object[] args = new Object[values.length + 1]; 190 args[0] = "name" + ++_seed; 191 System.arraycopy(values, 0, args, 1, values.length); 192 invoke(message, method, args); 193 } 194 195 /*** 196 * Get a message property, verifying it against the expected value 197 * 198 * @param message the message 199 * @param method the method to invoke 200 * @param expected the expected value 201 * @throws Exception for any error 202 */ 203 protected void get(Message message, String method, Object expected) 204 throws Exception { 205 Object[] args = {"name" + ++_seed}; 206 expect(message, method, args, expected); 207 } 208 209 /*** 210 * Get a message array property, verifying it against the expected value 211 * 212 * @param message the message 213 * @param method the method to invoke 214 * @param values the array to buffer the property value 215 * @param expected the expected value 216 * @throws Exception for any error 217 */ 218 protected void get(Message message, String method, Object[] values, 219 Object expected) throws Exception { 220 Object[] args = new Object[values.length + 1]; 221 args[0] = "name" + ++_seed; 222 System.arraycopy(values, 0, args, 1, values.length); 223 expect(message, method, args, expected); 224 } 225 226 /*** 227 * Returns a cache of the <code>MapMessage</code> methods 228 * 229 * @return a cache of the <code>MapMessage</code> methods 230 */ 231 protected synchronized MethodCache getMethods() { 232 if (_methods == null) { 233 _methods = new MethodCache(MapMessage.class); 234 } 235 return _methods; 236 } 237 238 }

This page was automatically generated by Maven