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: PropertyTypeTest.java,v 1.5 2004/02/03 07:31:03 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.test.message.properties; 46 47 import javax.jms.Message; 48 import javax.jms.MessageFormatException; 49 50 import junit.framework.Test; 51 52 import org.exolab.jmscts.core.AbstractMessageTestCase; 53 import org.exolab.jmscts.core.TestCreator; 54 import org.exolab.jmscts.test.message.util.PropertyValues; 55 56 57 /*** 58 * This class tests message property types 59 * 60 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 61 * @version $Revision: 1.5 $ 62 * @see AbstractMessageTestCase 63 */ 64 public class PropertyTypeTest extends AbstractMessageTestCase 65 implements PropertyValues { 66 67 /*** 68 * Construct a new <code>PropertyTypeTest</code> 69 * 70 * @param name the name of test case 71 */ 72 public PropertyTypeTest(String name) { 73 super(name); 74 } 75 76 /*** 77 * Sets up the test suite 78 * 79 * @return an instance of this class that may be run by 80 * {@link org.exolab.jmscts.core.JMSTestRunner} 81 */ 82 public static Test suite() { 83 return TestCreator.createMessageTest(PropertyTypeTest.class); 84 } 85 86 /*** 87 * Verifies the supported primitive property types. 88 * 89 * @jmscts.requirement properties.types 90 * @throws Exception for any error 91 */ 92 public void testPropertyTypes() throws Exception { 93 94 Message message = getContext().getMessage(); 95 final String name = "test"; 96 97 for (int i = 0; i < BOOLEANS.length; ++i) { 98 boolean value = BOOLEANS[i].booleanValue(); 99 message.setBooleanProperty(name, value); 100 assertEquals(value, message.getBooleanProperty(name)); 101 } 102 103 for (int i = 0; i < BYTES.length; ++i) { 104 byte value = BYTES[i].byteValue(); 105 message.setByteProperty(name, value); 106 assertEquals(value, message.getByteProperty(name)); 107 } 108 109 for (int i = 0; i < SHORTS.length; ++i) { 110 short value = SHORTS[i].shortValue(); 111 message.setShortProperty(name, value); 112 assertEquals(value, message.getShortProperty(name)); 113 } 114 115 for (int i = 0; i < INTS.length; ++i) { 116 int value = INTS[i].intValue(); 117 message.setIntProperty(name, value); 118 assertEquals(value, message.getIntProperty(name)); 119 } 120 121 for (int i = 0; i < LONGS.length; ++i) { 122 long value = LONGS[i].longValue(); 123 message.setLongProperty(name, value); 124 assertEquals(value, message.getLongProperty(name)); 125 } 126 127 for (int i = 0; i < FLOATS.length; ++i) { 128 float value = FLOATS[i].floatValue(); 129 message.setFloatProperty(name, value); 130 if (Float.isNaN(value)) { 131 assertTrue(Float.isNaN(message.getFloatProperty(name))); 132 } else { 133 assertEquals(value, message.getFloatProperty(name), 0.0); 134 } 135 } 136 137 for (int i = 0; i < DOUBLES.length; ++i) { 138 double value = DOUBLES[i].doubleValue(); 139 message.setDoubleProperty(name, value); 140 if (Double.isNaN(value)) { 141 assertTrue(Double.isNaN(message.getDoubleProperty(name))); 142 } else { 143 assertEquals(value, message.getDoubleProperty(name), 0.0); 144 } 145 } 146 147 for (int i = 0; i < STRINGS.length; ++i) { 148 String value = STRINGS[i]; 149 message.setStringProperty(name, value); 150 assertEquals(value, message.getStringProperty(name)); 151 } 152 } 153 154 /*** 155 * Verifies valid and invalid object property types. 156 * 157 * @jmscts.requirement properties.objects 158 * @throws Exception for any error 159 */ 160 public void testObjectPropertyTypes() throws Exception { 161 162 Message message = getContext().getMessage(); 163 final String name = "test"; 164 165 for (int i = 0; i < ALL_VALUES.length; ++i) { 166 Object[] values = ALL_VALUES[i]; 167 for (int j = 0; j < values.length; ++j) { 168 Object value = values[j]; 169 message.setObjectProperty(name, value); 170 171 // verify that the type is the same as that set 172 assertEquals(value.getClass(), 173 message.getObjectProperty(name).getClass()); 174 175 // test that set/get values are equal 176 if (value instanceof Float && ((Float) value).isNaN()) { 177 assertTrue( 178 ((Float) message.getObjectProperty(name)).isNaN()); 179 } else if (value instanceof Double 180 && ((Double) value).isNaN()) { 181 assertTrue( 182 ((Double) message.getObjectProperty(name)).isNaN()); 183 } else { 184 assertEquals(value, message.getObjectProperty(name)); 185 } 186 } 187 } 188 189 // test nulls 190 message.setObjectProperty(name, null); 191 assertEquals(null, message.getObjectProperty(name)); 192 193 // test an invalid object property 194 try { 195 message.setObjectProperty(name, new Character('A')); 196 fail("Managed to set invalid object property"); 197 } catch (MessageFormatException expected) { 198 // the expected behaviour 199 } 200 } 201 202 }

This page was automatically generated by Maven