1 24 25 package org.objectweb.jtests.jms.conform.selector; 26 27 import org.objectweb.jtests.jms.framework.*; 28 import junit.framework.*; 29 30 import javax.jms.*; 31 32 38 public class SelectorTest extends PTPTestCase { 39 40 44 public void testEmptyStringAsSelector() { 45 try { 46 receiverConnection.stop(); 47 receiver = receiverSession.createReceiver(receiverQueue, ""); 48 receiverConnection.start(); 49 50 TextMessage message = senderSession.createTextMessage(); 51 message.setText("testEmptyStringAsSelector"); 52 sender.send(message); 53 54 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 55 assertTrue("No message was received", msg != null); 56 assertEquals("testEmptyStringAsSelector", msg.getText()); 57 } catch (JMSException e) { 58 fail(e); 59 } 60 } 61 62 69 70 public void testStringLiterals() { 71 try { 72 receiverConnection.stop(); 73 receiver = receiverSession.createReceiver(receiverQueue, "string = 'literal''s'"); 74 receiverConnection.start(); 75 76 TextMessage dummyMessage = senderSession.createTextMessage(); 77 dummyMessage.setStringProperty("string", "literal"); 78 dummyMessage.setText("testStringLiterals:1"); 79 sender.send(dummyMessage); 80 81 TextMessage message = senderSession.createTextMessage(); 82 message.setStringProperty("string", "literal's"); 83 message.setText("testStringLiterals:2"); 84 sender.send(message); 85 86 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 87 assertTrue("No message was received", msg != null); 88 assertEquals("testStringLiterals:2", msg.getText()); 89 } catch (JMSException e) { 90 fail(e); 91 } 92 } 93 94 98 public void testJMSDeliveryModeInSelector() { 99 try { 100 receiverConnection.stop(); 101 receiver = receiverSession.createReceiver(receiverQueue, "JMSDeliveryMode = 'PERSISTENT'"); 102 receiverConnection.start(); 103 104 TextMessage dummyMessage = senderSession.createTextMessage(); 105 dummyMessage.setText("testJMSDeliveryModeInSelector:1"); 106 sender.send(dummyMessage, DeliveryMode.NON_PERSISTENT, sender.getPriority(), sender.getTimeToLive()); 108 109 TextMessage message = senderSession.createTextMessage(); 110 message.setText("testJMSDeliveryModeInSelector:2"); 111 sender.send(message, DeliveryMode.PERSISTENT, sender.getPriority(), sender.getTimeToLive()); 113 114 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 115 assertTrue("No message was received", msg != null); 116 assertEquals(DeliveryMode.PERSISTENT, msg.getJMSDeliveryMode()); 118 assertEquals("testJMSDeliveryModeInSelector:2", msg.getText()); 119 } catch (JMSException e) { 120 fail(e); 121 } 122 } 123 124 129 public void testIdentifierConversion() { 130 try { 131 receiverConnection.stop(); 132 receiver = receiverSession.createReceiver(receiverQueue, "NumberOfOrders > 1"); 133 receiverConnection.start(); 134 135 TextMessage dummyMessage = senderSession.createTextMessage(); 136 dummyMessage.setStringProperty("NumberOfOrders", "2"); 137 dummyMessage.setText("testIdentifierConversion:1"); 138 sender.send(dummyMessage); 139 140 TextMessage message = senderSession.createTextMessage(); 141 message.setIntProperty("NumberOfOrders", 2); 142 message.setText("testIdentifierConversion:2"); 143 sender.send(message); 144 145 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 146 assertEquals("testIdentifierConversion:2", msg.getText()); 147 } catch (JMSException e) { 148 fail(e); 149 } 150 } 151 152 159 public void testSelectorExampleFromSpecs() { 160 try { 161 receiverConnection.stop(); 162 receiver = receiverSession.createReceiver(receiverQueue, "JMSType = 'car' AND color = 'blue' AND weight > 2500"); 163 receiverConnection.start(); 164 165 TextMessage dummyMessage = senderSession.createTextMessage(); 166 dummyMessage.setJMSType("car"); 167 dummyMessage.setStringProperty("color", "red"); 168 dummyMessage.setLongProperty("weight", 3000); 169 dummyMessage.setText("testSelectorExampleFromSpecs:1"); 170 sender.send(dummyMessage); 171 172 TextMessage message = senderSession.createTextMessage(); 173 message.setJMSType("car"); 174 message.setStringProperty("color", "blue"); 175 message.setLongProperty("weight", 3000); 176 message.setText("testSelectorExampleFromSpecs:2"); 177 sender.send(message); 178 179 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 180 assertEquals("testSelectorExampleFromSpecs:2", msg.getText()); 181 } catch (JMSException e) { 182 fail(e); 183 } 184 } 185 186 193 public void testGreaterThan() { 194 try { 195 receiverConnection.stop(); 196 receiver = receiverSession.createReceiver(receiverQueue, "weight > 2500"); 197 receiverConnection.start(); 198 199 TextMessage dummyMessage = senderSession.createTextMessage(); 200 dummyMessage.setLongProperty("weight", 1000); 201 dummyMessage.setText("testGreaterThan:1"); 202 sender.send(dummyMessage); 203 204 TextMessage message = senderSession.createTextMessage(); 205 message.setLongProperty("weight", 3000); 206 message.setText("testGreaterThan:2"); 207 sender.send(message); 208 209 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 210 assertEquals("testGreaterThan:2", msg.getText()); 211 } catch (JMSException e) { 212 fail(e); 213 } 214 } 215 216 223 public void testEquals() { 224 try { 225 receiverConnection.stop(); 226 receiver = receiverSession.createReceiver(receiverQueue, "weight = 2500"); 227 receiverConnection.start(); 228 229 TextMessage dummyMessage = senderSession.createTextMessage(); 230 dummyMessage.setLongProperty("weight", 1000); 231 dummyMessage.setText("testEquals:1"); 232 sender.send(dummyMessage); 233 234 TextMessage message = senderSession.createTextMessage(); 235 message.setLongProperty("weight", 2500); 236 message.setText("testEquals:2"); 237 sender.send(message); 238 239 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 240 assertEquals("testEquals:2", msg.getText()); 241 } catch (JMSException e) { 242 fail(e); 243 } 244 } 245 246 253 public void testNotEquals() { 254 try { 255 receiverConnection.stop(); 256 receiver = receiverSession.createReceiver(receiverQueue, "weight <> 2500"); 257 receiverConnection.start(); 258 259 TextMessage dummyMessage = senderSession.createTextMessage(); 260 dummyMessage.setLongProperty("weight", 2500); 261 dummyMessage.setText("testEquals:1"); 262 sender.send(dummyMessage); 263 264 TextMessage message = senderSession.createTextMessage(); 265 message.setLongProperty("weight", 1000); 266 message.setText("testEquals:2"); 267 sender.send(message); 268 269 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 270 assertEquals("testEquals:2", msg.getText()); 271 } catch (JMSException e) { 272 fail(e); 273 } 274 } 275 276 277 284 public void testBetween() { 285 try { 286 receiverConnection.stop(); 287 receiver = receiverSession.createReceiver(receiverQueue, "age BETWEEN 15 and 19"); 288 receiverConnection.start(); 289 290 TextMessage dummyMessage = senderSession.createTextMessage(); 291 dummyMessage.setIntProperty("age", 20); 292 dummyMessage.setText("testBetween:1"); 293 sender.send(dummyMessage); 294 295 TextMessage message = senderSession.createTextMessage(); 296 message.setIntProperty("age", 17); 297 message.setText("testBetween:2"); 298 sender.send(message); 299 300 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 301 assertTrue("Message not received", 302 msg != null); 303 assertTrue("Message of another test: "+ msg.getText(), 304 msg.getText().startsWith("testBetween")); 305 assertEquals("testBetween:2", msg.getText()); 306 307 } catch (JMSException e) { 308 fail(e); 309 } 310 } 311 312 319 public void testIn() { 320 try { 321 receiverConnection.stop(); 322 receiver = receiverSession.createReceiver(receiverQueue, "Country IN ('UK', 'US', 'France')"); 323 receiverConnection.start(); 324 325 TextMessage dummyMessage = senderSession.createTextMessage(); 326 dummyMessage.setStringProperty("Country", "Peru"); 327 dummyMessage.setText("testIn:1"); 328 sender.send(dummyMessage); 329 330 TextMessage message = senderSession.createTextMessage(); 331 message.setStringProperty("Country", "UK"); 332 message.setText("testIn:2"); 333 sender.send(message); 334 335 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 336 assertTrue("Message not received", 337 msg != null); 338 assertTrue("Message of another test: "+ msg.getText(), 339 msg.getText().startsWith("testIn")); 340 assertEquals("testIn:2", msg.getText()); 341 342 } catch (JMSException e) { 343 fail(e); 344 } 345 } 346 347 354 public void testLikeEscape() { 355 try { 356 receiverConnection.stop(); 357 receiver = receiverSession.createReceiver(receiverQueue, "underscored LIKE '\\_%' ESCAPE '\\'"); 358 receiverConnection.start(); 359 360 TextMessage dummyMessage = senderSession.createTextMessage(); 361 dummyMessage.setStringProperty("underscored", "bar"); 362 dummyMessage.setText("testLikeEscape:1"); 363 sender.send(dummyMessage); 364 365 TextMessage message = senderSession.createTextMessage(); 366 message.setStringProperty("underscored", "_foo"); 367 message.setText("testLikeEscape:2"); 368 sender.send(message); 369 370 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 371 assertTrue("Message not received", 372 msg != null); 373 assertTrue("Message of another test: "+ msg.getText(), 374 msg.getText().startsWith("testLikeEscape")); 375 assertEquals("testLikeEscape:2", msg.getText()); 376 377 } catch (JMSException e) { 378 fail(e); 379 } 380 } 381 382 389 public void testLike_2() { 390 try { 391 receiverConnection.stop(); 392 receiver = receiverSession.createReceiver(receiverQueue, "word LIKE 'l_se'"); 393 receiverConnection.start(); 394 395 TextMessage dummyMessage = senderSession.createTextMessage(); 396 dummyMessage.setStringProperty("word", "loose"); 397 dummyMessage.setText("testLike_2:1"); 398 sender.send(dummyMessage); 399 400 TextMessage message = senderSession.createTextMessage(); 401 message.setStringProperty("word", "lose"); 402 message.setText("testLike_2:2"); 403 sender.send(message); 404 405 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 406 assertTrue("Message not received", 407 msg != null); 408 assertTrue("Message of another test: "+ msg.getText(), 409 msg.getText().startsWith("testLike_2")); 410 assertEquals("testLike_2:2", msg.getText()); 411 412 } catch (JMSException e) { 413 fail(e); 414 } 415 } 416 417 424 public void testLike_1() { 425 try { 426 receiverConnection.stop(); 427 receiver = receiverSession.createReceiver(receiverQueue, "phone LIKE '12%3'"); 428 receiverConnection.start(); 429 430 TextMessage dummyMessage = senderSession.createTextMessage(); 431 dummyMessage.setStringProperty("phone", "1234"); 432 dummyMessage.setText("testLike_1:1"); 433 sender.send(dummyMessage); 434 435 TextMessage message = senderSession.createTextMessage(); 436 message.setStringProperty("phone", "12993"); 437 message.setText("testLike_1:2"); 438 sender.send(message); 439 440 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 441 assertTrue("Message not received", msg != null); 442 assertTrue("Message of another test: "+ msg.getText(), 443 msg.getText().startsWith("testLike_1")); 444 assertEquals("testLike_1:2", msg.getText()); 445 446 } catch (JMSException e) { 447 fail(e); 448 } 449 } 450 451 458 public void testNull() { 459 try { 460 receiverConnection.stop(); 461 receiver = receiverSession.createReceiver(receiverQueue, "prop_name IS NULL"); 462 receiverConnection.start(); 463 464 TextMessage dummyMessage = senderSession.createTextMessage(); 465 dummyMessage.setStringProperty("prop_name", "not null"); 466 dummyMessage.setText("testNull:1"); 467 sender.send(dummyMessage); 468 469 TextMessage message = senderSession.createTextMessage(); 470 message.setText("testNull:2"); 471 sender.send(message); 472 473 TextMessage msg = (TextMessage)receiver.receive(TestConfig.TIMEOUT); 474 assertTrue(msg != null); 475 assertEquals("testNull:2", msg.getText()); 476 } catch (JMSException e) { 477 fail(e); 478 } 479 } 480 481 484 public static Test suite() { 485 return new TestSuite(SelectorTest.class); 486 } 487 488 public SelectorTest(String name) { 489 super(name); 490 } 491 } 492 493 | Popular Tags |