1 24 25 package org.objectweb.jtests.jms.conform.message.properties; 26 27 import org.objectweb.jtests.jms.framework.*; 28 import javax.jms.*; 29 import junit.framework.*; 30 import java.util.Vector ; 31 import java.util.Enumeration ; 32 33 41 public class MessagePropertyTest extends PTPTestCase { 42 43 48 public void testSetObjectProperty_2() { 49 try { 50 Message message = senderSession.createMessage(); 51 message.setObjectProperty("prop", new Vector ()); 52 fail("§3.5.5 An attempt to use any other class [than Boolean, Byte,...,String] must throw " + 53 "a JMS MessageFormatException.\n"); 54 } catch (MessageFormatException e) { 55 } catch (JMSException e) { 56 fail("Should throw a javax.jms.MessageFormatException, not a "+ e); 57 } 58 } 59 60 64 public void testSetObjectProperty_1() { 65 try { 66 Message message = senderSession.createMessage(); 67 message.setObjectProperty("pi", new Float (3.14159f)); 68 assertEquals(3.14159f, message.getFloatProperty("pi"),0); 69 } catch (JMSException e) { 70 fail(e); 71 } 72 } 73 74 78 public void testGetObjectProperty() { 79 try { 80 Message message = senderSession.createMessage(); 81 assertEquals("§3.5.5 A null value is returned [by the getObjectProperty method] if a property by the specified " + 82 "name does not exits.\n", 83 null,message.getObjectProperty("prop")); 84 } catch (JMSException e) { 85 fail(e); 86 } 87 } 88 89 93 public void testGetStringProperty() { 94 try { 95 Message message = senderSession.createMessage(); 96 assertEquals("§3.5.5 A null value is returned [by the getStringProperty method] if a property by the specified " + 97 "name does not exits.\n", 98 null,message.getStringProperty("prop")); 99 } catch (JMSException e) { 100 fail(e); 101 } 102 } 103 104 108 public void testGetDoubleProperty() { 109 try { 110 Message message = senderSession.createMessage(); 111 message.getDoubleProperty("prop"); 112 fail("Should raise a NullPointerException.\n"); 113 } catch (NullPointerException e) { 114 } catch (JMSException e) { 115 fail(e); 116 } 117 } 118 119 123 public void testGetFloatProperty() { 124 try { 125 Message message = senderSession.createMessage(); 126 message.getFloatProperty("prop"); 127 fail("Should raise a NullPointerException.\n"); 128 } catch (NullPointerException e) { 129 } catch (JMSException e) { 130 fail(e); 131 } 132 } 133 134 138 public void testGetLongProperty() { 139 try { 140 Message message = senderSession.createMessage(); 141 message.getLongProperty("prop"); 142 fail("Should raise a NumberFormatException.\n"); 143 } catch (NumberFormatException e) { 144 } catch (JMSException e) { 145 fail(e); 146 } 147 } 148 149 153 public void testGetIntProperty() { 154 try { 155 Message message = senderSession.createMessage(); 156 message.getIntProperty("prop"); 157 fail("Should raise a NumberFormatException.\n"); 158 } catch (NumberFormatException e) { 159 } catch (JMSException e) { 160 fail(e); 161 } 162 } 163 164 168 public void testGetShortProperty() { 169 try { 170 Message message = senderSession.createMessage(); 171 message.getShortProperty("prop"); 172 fail("Should raise a NumberFormatException.\n"); 173 } catch (NumberFormatException e) { 174 } catch (JMSException e) { 175 fail(e); 176 } 177 } 178 179 183 public void testGetByteProperty() { 184 try { 185 Message message = senderSession.createMessage(); 186 message.getByteProperty("prop"); 187 fail("Should raise a NumberFormatException.\n"); 188 } catch (NumberFormatException e) { 189 } catch (JMSException e) { 190 fail(e); 191 } 192 } 193 194 198 public void testGetBooleanProperty() { 199 try { 200 Message message = senderSession.createMessage(); 201 assertEquals(false, message.getBooleanProperty("prop")); 202 } catch (JMSException e) { 203 fail(e); 204 } 205 } 206 207 211 public void testGetPropertyNames() { 212 try { 213 Message message = senderSession.createMessage(); 214 message.setJMSCorrelationID("foo"); 215 Enumeration i = message.getPropertyNames(); 216 assertTrue("§3.5.6 The getPropertyNames method does not return the names of " + 217 "the JMS standard header field [e.g. JMSCorrelationID].\n", 218 !i.hasMoreElements()); 219 } catch (JMSException e) { 220 fail(e); 221 } 222 } 223 224 230 public void testPropertyIteration() { 231 try { 232 Message message = senderSession.createMessage(); 233 Enumeration i = message.getPropertyNames(); 234 assertTrue("No property yet defined.\n", 235 !i.hasMoreElements()); 236 message.setDoubleProperty("pi", 3.14159); 237 i = message.getPropertyNames(); 238 assertEquals("One property defined of name 'pi'.\n", 239 "pi", (String )i.nextElement()); 240 } catch (JMSException e) { 241 fail(e); 242 } 243 } 244 245 249 public void testClearProperties_2() { 250 try { 251 TextMessage message = senderSession.createTextMessage(); 252 message.setText("foo"); 253 message.clearProperties(); 254 assertEquals("§3.5.7 Clearing a message's property entries does not clear the value of its body.\n", 255 "foo", message.getText()); 256 } catch (JMSException e) { 257 fail(e); 258 } 259 } 260 261 265 public void testClearProperties_1() { 266 try { 267 TextMessage message = senderSession.createTextMessage(); 268 message.setStringProperty("prop", "foo"); 269 message.clearProperties(); 270 assertEquals("§3.5.7 A message's properties are deleted by the clearProperties method.\n", 271 null, message.getStringProperty("prop")); 272 } catch (JMSException e) { 273 fail(e); 274 } 275 } 276 277 280 public static Test suite() { 281 return new TestSuite(MessagePropertyTest.class); 282 } 283 284 public MessagePropertyTest(String name) { 285 super(name); 286 } 287 } 288 289 | Popular Tags |