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: MessagePropertyVerifier.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.Message; 48 49 import org.exolab.jmscts.core.MethodCache; 50 51 52 /*** 53 * A helper class for exercising the interfaces of messages 54 * 55 * @version $Revision: 1.2 $ $Date: 2004/02/03 07:31:04 $ 56 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 57 * @see MessagePopulatorVerifier 58 * @see PropertyValues 59 */ 60 public class MessagePropertyVerifier extends MessagePopulatorVerifier 61 implements PropertyValues { 62 63 /*** 64 * Method cache for Message 65 */ 66 private static MethodCache _methods = null; 67 68 69 /*** 70 * Construct a new instance. No exceptions are expected to be thrown 71 * when invoking methods 72 */ 73 public MessagePropertyVerifier() { 74 } 75 76 /*** 77 * Construct an instance with the expected exception thrown when 78 * methods are invoked 79 * 80 * @param exception the expected exception type when methods are invoked 81 */ 82 public MessagePropertyVerifier(Class exception) { 83 super(exception); 84 } 85 86 /*** 87 * Populate a message's user properties 88 * 89 * @param message the message to verify 90 * @throws Exception for any error 91 */ 92 public void populate(Message message) throws Exception { 93 int seed = 0; 94 for (int i = 0; i < BOOLEANS.length; ++i) { 95 set(message, "setBooleanProperty", BOOLEANS[i], ++seed); 96 set(message, "setObjectProperty", BOOLEANS[i], ++seed); 97 } 98 for (int i = 0; i < BYTES.length; ++i) { 99 set(message, "setByteProperty", BYTES[i], ++seed); 100 set(message, "setObjectProperty", BYTES[i], ++seed); 101 } 102 for (int i = 0; i < SHORTS.length; ++i) { 103 set(message, "setShortProperty", SHORTS[i], ++seed); 104 set(message, "setObjectProperty", SHORTS[i], ++seed); 105 } 106 for (int i = 0; i < INTS.length; ++i) { 107 set(message, "setIntProperty", INTS[i], ++seed); 108 set(message, "setObjectProperty", INTS[i], ++seed); 109 } 110 for (int i = 0; i < LONGS.length; ++i) { 111 set(message, "setLongProperty", LONGS[i], ++seed); 112 set(message, "setObjectProperty", LONGS[i], ++seed); 113 } 114 for (int i = 0; i < FLOATS.length; ++i) { 115 set(message, "setFloatProperty", FLOATS[i], ++seed); 116 set(message, "setObjectProperty", FLOATS[i], ++seed); 117 } 118 for (int i = 0; i < DOUBLES.length; ++i) { 119 set(message, "setDoubleProperty", DOUBLES[i], ++seed); 120 set(message, "setObjectProperty", DOUBLES[i], ++seed); 121 } 122 for (int i = 0; i < STRINGS.length; ++i) { 123 set(message, "setStringProperty", STRINGS[i], ++seed); 124 set(message, "setObjectProperty", STRINGS[i], ++seed); 125 } 126 } 127 128 /*** 129 * Verify a message's user properties, populated by the {@link #populate} 130 * 131 * @param message the message to verify 132 * @throws Exception for any error 133 */ 134 public void verify(Message message) throws Exception { 135 int seed = 0; 136 for (int i = 0; i < BOOLEANS.length; ++i) { 137 get(message, "getBooleanProperty", BOOLEANS[i], ++seed); 138 get(message, "getObjectProperty", BOOLEANS[i], ++seed); 139 } 140 for (int i = 0; i < BYTES.length; ++i) { 141 get(message, "getByteProperty", BYTES[i], ++seed); 142 get(message, "getObjectProperty", BYTES[i], ++seed); 143 } 144 for (int i = 0; i < SHORTS.length; ++i) { 145 get(message, "getShortProperty", SHORTS[i], ++seed); 146 get(message, "getObjectProperty", SHORTS[i], ++seed); 147 } 148 for (int i = 0; i < INTS.length; ++i) { 149 get(message, "getIntProperty", INTS[i], ++seed); 150 get(message, "getObjectProperty", INTS[i], ++seed); 151 } 152 for (int i = 0; i < LONGS.length; ++i) { 153 get(message, "getLongProperty", LONGS[i], ++seed); 154 get(message, "getObjectProperty", LONGS[i], ++seed); 155 } 156 for (int i = 0; i < FLOATS.length; ++i) { 157 get(message, "getFloatProperty", FLOATS[i], ++seed); 158 get(message, "getObjectProperty", FLOATS[i], ++seed); 159 } 160 for (int i = 0; i < DOUBLES.length; ++i) { 161 get(message, "getDoubleProperty", DOUBLES[i], ++seed); 162 get(message, "getObjectProperty", DOUBLES[i], ++seed); 163 } 164 for (int i = 0; i < STRINGS.length; ++i) { 165 get(message, "getStringProperty", STRINGS[i], ++seed); 166 get(message, "getObjectProperty", STRINGS[i], ++seed); 167 } 168 } 169 170 /*** 171 * Set a message property 172 * 173 * @param message the message to populate 174 * @param method the method to invoke 175 * @param value the property value 176 * @param seed seed value used to generate the property name 177 * @throws Exception for any error 178 */ 179 private void set(Message message, String method, Object value, int seed) 180 throws Exception { 181 Object[] args = new Object[]{"property" + seed, value}; 182 invoke(message, method, args); 183 } 184 185 /*** 186 * Get a message property, verifying it against the expected value 187 * 188 * @param message the message 189 * @param method the method to invoke 190 * @param expected the expected property value 191 * @param seed seed value used to generate the property name 192 * @throws Exception for any error 193 */ 194 private void get(Message message, String method, Object expected, int seed) 195 throws Exception { 196 Object[] args = new Object[]{"property" + seed}; 197 expect(message, method, args, expected); 198 } 199 200 /*** 201 * Returns a cache of the <code>Message</code> methods 202 * 203 * @return a cache of the <code>Message</code> methods 204 */ 205 protected synchronized MethodCache getMethods() { 206 if (_methods == null) { 207 _methods = new MethodCache(Message.class); 208 } 209 return _methods; 210 } 211 212 }

This page was automatically generated by Maven