1 24 25 package org.objectweb.jtests.jms.conform.selector; 26 27 import org.objectweb.jtests.jms.framework.*; 28 import junit.framework.*; 29 import org.objectweb.jtests.jms.admin.*; 30 31 import javax.jms.*; 32 import javax.naming.*; 33 34 40 public class SelectorSyntaxTest extends PTPTestCase { 41 42 49 public void testValidIdentifiersStart() { 50 String identifier = null; 51 try { 52 identifier = "_correct"; 53 assertTrue(identifier +" starts with an invalid Java identifier start character", 54 Character.isJavaIdentifierStart(identifier.charAt(0))); 55 receiver = receiverSession.createReceiver(receiverQueue, identifier +" IS NULL"); 56 57 identifier = "$correct"; 58 assertTrue(identifier +" starts with an invalid Java identifier start character", 59 Character.isJavaIdentifierStart(identifier.charAt(0))); 60 receiver = receiverSession.createReceiver(receiverQueue, identifier +" IS NULL"); 61 } catch (JMSException e) { 62 fail(identifier +" is a correct identifier. \n" +e); 63 } 64 } 65 66 71 public void testInvalidIdentifiersStart() { 72 String identifier = null; 73 try { 74 identifier = "1uncorrect"; 75 76 assertTrue(identifier +" starts with an invalid Java identifier start character", 77 !Character.isJavaIdentifierStart(identifier.charAt(0))); 78 receiver = receiverSession.createReceiver(receiverQueue, identifier +" IS NULL"); 79 fail(identifier +" starts with an invalid Java identifier start character"); 80 } catch (JMSException e) { 81 } 82 83 try { 84 identifier = "%uncorrect"; 85 86 assertTrue(identifier +" starts with an invalid Java identifier start character", 87 !Character.isJavaIdentifierStart(identifier.charAt(0))); 88 receiver = receiverSession.createReceiver(receiverQueue, identifier +" IS NULL"); 89 fail(identifier +" starts with an invalid Java identifier start character"); 90 } catch (JMSException e) { 91 } 92 93 } 94 95 98 public void testEmptyStringAsSelector() { 99 try { 100 receiver = receiverSession.createReceiver(receiverQueue, ""); 101 } catch (JMSException e) { 102 fail(e); 103 } 104 } 105 106 109 public void testIdentifierNULL() { 110 try { 111 receiver = receiverSession.createReceiver(receiverQueue, "NULL = ZERO"); 112 fail("NULL is not a valid identifier"); 113 } catch (InvalidSelectorException e) { 114 } catch (JMSException e) { 115 fail(e); 116 } 117 } 118 119 122 public void testIdentifierTRUE() { 123 try { 124 receiver = receiverSession.createReceiver(receiverQueue, "TRUE > 0"); 125 fail("TRUE is not a valid identifier"); 126 } catch (JMSException e) { 127 } 128 } 129 130 133 public void testIdentifierFALSE() { 134 try { 135 receiver = receiverSession.createReceiver(receiverQueue, "FALSE > 0"); 136 fail("FALSE is not a valid identifier"); 137 } catch (JMSException e) { 138 } 139 } 140 141 144 public void testIdentifierNOT() { 145 try { 146 receiver = receiverSession.createReceiver(receiverQueue, "NOT > 0"); 147 fail("NOT is not a valid identifier"); 148 } catch (JMSException e) { 149 } 150 } 151 152 155 public void testIdentifierAND() { 156 try { 157 receiver = receiverSession.createReceiver(receiverQueue, "AND > 0"); 158 fail("AND is not a valid identifier"); 159 } catch (JMSException e) { 160 } 161 } 162 163 166 public void testIdentifierOR() { 167 try { 168 receiver = receiverSession.createReceiver(receiverQueue, "OR > 0"); 169 fail("OR is not a valid identifier"); 170 } catch (JMSException e) { 171 } 172 } 173 174 175 178 public void testIdentifierBETWEEN() { 179 try { 180 receiver = receiverSession.createReceiver(receiverQueue, "BETWEEN > 0"); 181 fail("BETWEEN is not a valid identifier"); 182 } catch (JMSException e) { 183 } 184 } 185 186 187 190 public void testIdentifierLIKE() { 191 try { 192 receiver = receiverSession.createReceiver(receiverQueue, "LIKE > 0"); 193 fail("LIKE is not a valid identifier"); 194 } catch (JMSException e) { 195 } 196 } 197 198 199 202 public void testIdentifierIN() { 203 try { 204 receiver = receiverSession.createReceiver(receiverQueue, "IN > 0"); 205 fail("IN is not a valid identifier"); 206 } catch (JMSException e) { 207 } 208 } 209 210 211 214 public void testIdentifierIS() { 215 try { 216 receiver = receiverSession.createReceiver(receiverQueue, "IS > 0"); 217 fail("IS is not a valid identifier"); 218 } catch (JMSException e) { 219 } 220 } 221 222 223 226 public void testIdentifierESCAPE() { 227 try { 228 receiver = receiverSession.createReceiver(receiverQueue, "ESCAPE > 0"); 229 fail("ESCAPE is not a valid identifier"); 230 } catch (JMSException e) { 231 } 232 } 233 234 237 public void testNull() { 238 try { 239 receiver = receiverSession.createReceiver(receiverQueue, "prop_name IS NULL"); 240 receiver = receiverSession.createReceiver(receiverQueue, "prop_name IS NOT NULL"); 241 } catch (JMSException e) { 242 fail(e); 243 } 244 } 245 246 249 public void testLike() { 250 try { 251 receiver = receiverSession.createReceiver(receiverQueue, "phone LIKE '12%3'"); 252 receiver = receiverSession.createReceiver(receiverQueue, "word LIKE 'l_se'"); 253 receiver = receiverSession.createReceiver(receiverQueue, "underscored LIKE '\\_%' ESCAPE '\\'"); 254 receiver = receiverSession.createReceiver(receiverQueue, "phone NOT LIKE '12%3'"); 255 } catch (JMSException e) { 256 fail(e); 257 } 258 } 259 260 263 public void testIn() { 264 try { 265 receiver = receiverSession.createReceiver(receiverQueue, "Country IN ('UK', 'US', 'France')"); 266 receiver = receiverSession.createReceiver(receiverQueue, "Country NOT IN ('UK', 'US', 'France')"); 267 } catch (JMSException e) { 268 fail(e); 269 } 270 } 271 272 275 public void testBetween() { 276 try { 277 receiver = receiverSession.createReceiver(receiverQueue, "age BETWEEN 15 and 19"); 278 receiver = receiverSession.createReceiver(receiverQueue, "age NOT BETWEEN 15 and 19"); 279 } catch (JMSException e) { 280 fail(e); 281 } 282 } 283 284 287 public void testApproximateNumericLiteral() { 288 try { 289 receiver = receiverSession.createReceiver(receiverQueue, "average = +6.2"); 290 receiver = receiverSession.createReceiver(receiverQueue, "average = -95.7"); 291 receiver = receiverSession.createReceiver(receiverQueue, "average = 7."); 292 } catch (JMSException e) { 293 fail(e); 294 } 295 } 296 297 300 public void testExactNumericLiteral() { 301 try { 302 receiver = receiverSession.createReceiver(receiverQueue, "average = +62"); 303 receiver = receiverSession.createReceiver(receiverQueue, "max = -957"); 304 receiver = receiverSession.createReceiver(receiverQueue, "max = 57"); 305 } catch (JMSException e) { 306 fail(e); 307 } 308 } 309 310 313 public void testZero() { 314 try { 315 receiver = receiverSession.createReceiver(receiverQueue, "max = 0"); 316 receiver = receiverSession.createReceiver(receiverQueue, "max = 0.0"); 317 receiver = receiverSession.createReceiver(receiverQueue, "max = 0."); 318 } catch (JMSException e) { 319 fail(e); 320 } 321 } 322 323 326 public void testString() { 327 try { 328 receiver = receiverSession.createReceiver(receiverQueue, "string = 'literal'"); 329 receiver = receiverSession.createReceiver(receiverQueue, "string = 'literal''s'"); 330 } catch (JMSException e) { 331 fail(e); 332 } 333 } 334 335 338 public static Test suite() { 339 return new TestSuite(SelectorSyntaxTest.class); 340 } 341 342 public SelectorSyntaxTest(String name) { 343 super(name); 344 } 345 } 346 | Popular Tags |