This project has retired. For details please refer to its
Attic page.
TestParserStrict xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.server.support.query;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26
27
28
29
30
31 public class TestParserStrict extends AbstractParserTest{
32
33 private static final Log log = LogFactory.getLog(TestParserStrict.class);
34
35 @Before
36 public void setUp() {
37 super.setUp(CmisQlStrictLexer.class, CmisQlStrictParser.class, "CmisBaseGrammar");
38 }
39
40 @Override
41 @After
42 public void tearDown() {
43 super.tearDown();
44 }
45
46
47
48
49 @Test
50 public void testID1() {
51 testLexerOk("ID", "a");
52 }
53
54
55 @Test
56 public void testID2() {
57 testLexerFail("ID", "!");
58 }
59
60 @Test
61 public void testID3() {
62 testLexerOk("ID", "toto");
63 }
64
65
66 @Test
67 public void testID4() throws Exception {
68 testLexerOk("ID", "toto123");
69 }
70
71
72 @Test
73 public void testID5() throws Exception {
74 testLexerOk("ID", "toto123_");
75 }
76
77
78 @Test
79 public void testID6() throws Exception {
80 testLexerOk("ID", "_foo");
81 }
82
83
84 @Test
85 public void testID7() throws Exception {
86 testLexerOk("ID", "foo:bar");
87 }
88
89
90 @Test
91 public void testID8() throws Exception {
92 testLexerFail("ID", "123");
93 }
94
95 @Test
96 public void testID9() throws Exception {
97 testLexerFail("ID", "123abc");
98 }
99
100
101
102 @Test
103 public void testNUM_LIT1() throws Exception {
104 testLexerOk("NUM_LIT", "123");
105 }
106
107
108 @Test
109 public void testNUM_LIT2() throws Exception {
110 testLexerOk("NUM_LIT", "0");
111 }
112
113
114 @Test
115 public void testNUM_LIT3() throws Exception {
116 testLexerOk("NUM_LIT", "-0");
117 }
118
119
120 @Test
121 public void testNUM_LIT4() throws Exception {
122 testLexerOk("NUM_LIT", "1");
123 }
124
125
126 @Test
127 public void testNUM_LIT5() throws Exception {
128 testLexerOk("NUM_LIT", "-1");
129 }
130
131
132 @Test
133 public void testNUM_LIT6() throws Exception {
134 testLexerOk("NUM_LIT", "123");
135 }
136
137
138 @Test
139 public void testNUM_LIT7() throws Exception {
140 testLexerOk("NUM_LIT", "0123");
141 }
142
143
144 @Test
145 public void testNUM_LIT8() throws Exception {
146 testLexerOk("NUM_LIT", "-0123");
147 }
148
149
150 @Test
151 public void testNUM_LIT9() throws Exception {
152 testLexerFail("NUM_LIT", "123abc");
153 }
154
155
156 @Test
157 public void testNUM_LIT10() throws Exception {
158 testLexerFail("NUM_LIT", "123E");
159 }
160
161
162 @Test
163 public void testNUM_LIT11() throws Exception {
164 testLexerOk("NUM_LIT", "123.456");
165 }
166
167
168 @Test
169 public void testNUM_LIT12() throws Exception {
170 testLexerOk("NUM_LIT", "+123.456");
171 }
172
173
174 @Test
175 public void testNUM_LIT13() throws Exception {
176 testLexerOk("NUM_LIT", "-123.456");
177 }
178
179
180 @Test
181 public void testNUM_LIT14() throws Exception {
182 testLexerOk("NUM_LIT", ".456");
183 }
184
185
186 @Test
187 public void testNUM_LIT15() throws Exception {
188 testLexerOk("NUM_LIT", "+.456");
189 }
190
191
192 @Test
193 public void testNUM_LIT16() throws Exception {
194 testLexerOk("NUM_LIT", "-.456");
195 }
196
197
198 @Test
199 public void testNUM_LIT17() throws Exception {
200 testLexerOk("NUM_LIT", "123.");
201 }
202
203
204 @Test
205 public void testNUM_LIT18() throws Exception {
206 testLexerOk("NUM_LIT", "+123.");
207 }
208
209
210 @Test
211 public void testNUM_LIT19() throws Exception {
212 testLexerOk("NUM_LIT", "-123.");
213 }
214
215
216 @Test
217 public void testNUM_LIT20() throws Exception {
218 testLexerOk("NUM_LIT", "+123.456E78");
219 }
220
221
222 @Test
223 public void testNUM_LIT21() throws Exception {
224 testLexerOk("NUM_LIT", "-123.456E-78");
225 }
226
227
228 @Test
229 public void testNUM_LIT22() throws Exception {
230 testLexerOk("NUM_LIT", ".456E78");
231 }
232
233
234 @Test
235 public void testNUM_LIT23() throws Exception {
236 testLexerOk("NUM_LIT", "+123.E+78");
237 }
238
239
240
241 @Test
242 public void testSTRING_LIT1() throws Exception {
243 testLexerOk("STRING_LIT", "'abc'");
244 }
245
246
247 @Test
248 public void testSTRING_LIT2() throws Exception {
249 testLexerOk("STRING_LIT", "'a''bc'");
250 }
251
252
253 @Test
254 public void testSTRING_LIT3() throws Exception {
255 testLexerFail("STRING_LIT", "'abc");
256 }
257
258
259 @Test
260 public void testSTRING_LIT4() throws Exception {
261 testLexerFail("STRING_LIT", "abc'");
262 }
263
264
265 @Test
266 public void testSTRING_LIT5() throws Exception {
267 testLexerFail("STRING_LIT", "'ab'c'");
268 }
269
270 @Test
271 public void testSTRING_LIT6() throws Exception {
272 testLexerOk("STRING_LIT", "'That''s'");
273 testLexerOk("STRING_LIT", "'Gus'''");
274 }
275
276 @Test
277 public void testSTRING_LIT7() throws Exception {
278 testLexerOk("STRING_LIT", "'That\\\'s'");
279 testLexerOk("STRING_LIT", "'Gus\\\'\'");
280 }
281
282 @Test
283 public void testSTRING_LIT8() throws Exception {
284 testLexerOk("STRING_LIT", "'c:\\\\temp'");
285 }
286
287 @Test
288 public void testSTRING_LIT9() throws Exception {
289 testLexerOk("STRING_LIT", "'Like%String'");
290 }
291
292 @Test
293 public void testSTRING_LIT10() throws Exception {
294 testLexerOk("STRING_LIT", "'Like_String'");
295 }
296
297 @Test
298 public void testSTRING_LIT11() throws Exception {
299 testLexerOk("STRING_LIT", "'Like\\%String'");
300 }
301
302 @Test
303 public void testSTRING_LIT12() throws Exception {
304 testLexerOk("STRING_LIT", "'Like\\_String'");
305 }
306
307
308
309
310 @Test
311 public void testBOOL_LIT1() throws Exception {
312 testLexerOk("BOOL_LIT", "TRUE");
313 }
314
315
316 @Test
317 public void testSBOOL_LIT2() throws Exception {
318 testLexerOk("BOOL_LIT", "true");
319 }
320
321
322 @Test
323 public void testBOOL_LIT3() throws Exception {
324 testLexerOk("BOOL_LIT", "FALSE");
325 }
326
327
328 @Test
329 public void testBOOL_LIT4() throws Exception {
330 testLexerOk("BOOL_LIT", "false");
331 }
332
333
334
335
336 @Test
337 public void testTIME_LIT1() throws Exception {
338 testLexerOk("TIME_LIT", "TIMESTAMP '2010-01-01Z01:01:01.000Z'");
339 }
340
341
342 @Test
343 public void testTIME_LIT2() throws Exception {
344 testLexerOk("TIME_LIT", "timestamp '123'");
345 }
346
347
348 @Test
349 public void testTIME_LIT3() throws Exception {
350 testLexerFail("TIME_LIT", "TIMESTAMP 123");
351 }
352
353
354
355
356
357
358 @Test
359 public void testLiteral1() throws Exception {
360 testParserOk("literal", "123");
361 }
362
363
364 @Test
365 public void testLiteral2() throws Exception {
366 testParserOk("literal", "123");
367 }
368
369
370 @Test
371 public void testLiteral3() throws Exception {
372 testParserOk("literal", "0");
373 }
374
375
376 @Test
377 public void testLiteral4() throws Exception {
378 testParserOk("literal", "0123");
379 }
380
381
382
383 @Test
384 public void testLiteral5() throws Exception {
385 testParserFail("literal", "123abc");
386 }
387
388
389 @Test
390 public void testLiteral6() throws Exception {
391 testParserOk("literal", "'abc'");
392 }
393
394
395 @Test
396 public void testLiteral7() throws Exception {
397 testParserOk("literal", "123.345E78");
398 }
399
400
401
402
403 @Test
404 public void testOrderBy1() throws Exception {
405 testParser("order_by_clause", "ORDER BY foo", "(ORDER_BY (COL foo) ASC)");
406 }
407
408
409 @Test
410 public void testOrderBy2() throws Exception {
411 testParser("order_by_clause", "ORDER BY foo ASC", "ORDER_BY (COL foo) ASC)");
412 }
413
414
415 @Test
416 public void testOrderBy3() throws Exception {
417 testParser("order_by_clause", "ORDER BY foo DESC", "(ORDER_BY (COL foo) DESC)");
418 }
419
420
421 @Test
422 public void testOrderBy4() throws Exception {
423 testParser("order_by_clause", "ORDER BY t.foo, bar DESC", "(ORDER_BY (COL t foo) ASC (COL bar) DESC)");
424 }
425
426
427
428
429 @Test
430 public void test_column_reference1() throws Exception {
431 testParser("column_reference", "foo", "(COL foo)");
432 }
433
434
435 @Test
436 public void test_column_reference2() throws Exception {
437 testParser("column_reference", "bar.foo", "(COL bar foo)");
438 }
439
440
441
442
443 @Test
444 public void testFrom() throws Exception {
445 testParser("from_clause", "FROM foo JOIN bar ON x = y", "(FROM (TABLE foo) (JOIN INNER (TABLE bar) (ON (COL x) = (COL y))))");
446 }
447
448
449
450 @Test
451 public void test_column_reference11() throws Exception {
452 testParser("table_join", "LEFT OUTER JOIN foo ON x = y", "(JOIN LEFT (TABLE foo) (ON (COL x) = (COL y)))");
453 }
454
455
456 @Test
457 public void test_column_reference12() throws Exception {
458 testParser("table_join", "INNER JOIN foo" , "(JOIN INNER (TABLE foo))");
459 }
460
461
462
463 @Test
464 public void test_column_reference3() throws Exception {
465 testParser("one_table", "foo", "(TABLE foo)");
466 }
467
468
469 @Test
470 public void test_column_reference4() throws Exception {
471 testParser("one_table", "foo bar", "(TABLE foo bar)");
472 }
473
474
475 @Test
476 public void test_column_reference5() throws Exception {
477 testParser("one_table", "foo AS bar", "(TABLE foo bar)");
478 }
479
480
481 @Test
482 public void test_column_reference6() throws Exception {
483 testParser("one_table", "(foo)", "(TABLE foo)");
484 }
485
486
487
488 @Test
489 public void test_in_predicate1() throws Exception {
490 testParser("in_predicate", "foo IN ( 'a', 'b', 'c')", "(IN (COL foo) (IN_LIST 'a' 'b' 'c'))");
491 }
492
493
494 @Test
495 public void test_in_predicate2() throws Exception {
496 testParser("in_predicate", "foo NOT IN ( 1, 2, 3)", "(NOT_IN (COL foo) (IN_LIST 1 2 3))");
497 }
498
499
500
501
502 @Test
503 public void tes_quantified_in_predicate() throws Exception {
504 testParser("quantified_in_predicate", "ANY foo IN ('a', 1)", "(IN_ANY (COL foo) (IN_LIST 'a' 1))");
505 }
506
507
508
509
510 @Test
511 public void test_comparison_predicate1() throws Exception {
512 testParser("comparison_predicate", "foo = 1", "(= (COL foo) 1)");
513 }
514
515
516 @Test
517 public void test_comparison_predicate2() throws Exception {
518 testParser("comparison_predicate", "foo <> 1", "(<> (COL foo) 1)");
519 }
520
521
522
523
524 @Test
525 public void test_predicate1() throws Exception {
526 testParser("predicate", "foo = 1", "(= (COL foo) 1)");
527 }
528
529
530 @Test
531 public void test_predicate2() throws Exception {
532 testParser("predicate", "foo IN ('bar')", "(IN (COL foo) (IN_LIST 'bar'))");
533 }
534
535
536 @Test
537 public void test_predicate3() throws Exception {
538 testParser("predicate","foo IS NULL", "(IS_NULL (COL foo))");
539 }
540
541
542 @Test
543 public void test_predicate4() throws Exception {
544 testParser("predicate", "foo IS NOT NULL", "(IS_NOT_NULL (COL foo))");
545 }
546
547
548 @Test
549 public void test_predicate5() throws Exception {
550 testParser("predicate", "1 = ANY foo", "(EQ_ANY 1 (COL foo))");
551 }
552
553
554 @Test
555 public void test_predicate6() throws Exception {
556 testParser("predicate", "SCORE() = 'bar'", "(= SCORE 'bar')");
557 }
558
559
560
561
562 @Test
563 public void boolean_term1() throws Exception {
564 testParser("boolean_term", "c >= 3 AND d <= 4", "(AND (>= (COL c) 3) (<= (COL d) 4))");
565 }
566
567
568 @Test
569 public void boolean_term2() throws Exception {
570 testParser("boolean_term", "c >= 3 AND NOT d <= 4", "(AND (>= (COL c) 3) (NOT (<= (COL d) 4)))");
571 }
572
573
574
575
576 @Test
577 public void folder_predicate1() throws Exception {
578 testParser("folder_predicate", "IN_FOLDER(foo,'ID123')", "(IN_FOLDER foo 'ID123')");
579 }
580
581
582 @Test
583 public void folder_predicate2() throws Exception {
584 testParser("folder_predicate", "IN_FOLDER('ID123')", "(IN_FOLDER 'ID123')");
585 }
586
587
588 @Test
589 public void folder_predicate3() throws Exception {
590 testParser("folder_predicate", "IN_TREE(foo,'ID123')", "(IN_FOLDER 'ID123')");
591 }
592
593
594 @Test
595 public void folder_predicate4() throws Exception {
596 testParser("folder_predicate","IN_TREE('ID123')" , " (IN_TREE 'ID123')");
597 }
598
599
600
601
602 @Test
603 public void text_search_predicate1() throws Exception {
604 testParser("text_search_predicate", "CONTAINS('foo')", "(CONTAINS 'foo')");
605 }
606
607
608 @Test
609 public void text_search_predicate2() throws Exception {
610 testParser("text_search_predicate", "CONTAINS(bar, 'foo')", "(CONTAINS bar 'foo')");
611 }
612
613
614
615
616 @Test
617 public void test_where_clause1() throws Exception {
618 testParser("where_clause", "WHERE foo = 1", "(WHERE (= (COL foo) 1))");
619 }
620
621
622 @Test
623 public void test_where_clause2() throws Exception {
624 testParser("where_clause", "WHERE a = 1 AND b <> 2 OR c >= 3", "(WHERE (OR (AND (= (COL a) 1) (<> (COL b) 2)) (>= (COL c) 3)))");
625 }
626
627
628 @Test
629 public void test_where_clause3() throws Exception {
630 testParser("where_clause", "WHERE a = 1 AND b <> 2 OR c >= 3 AND d <= 4", "(WHERE (OR (AND (= (COL a) 1) (<> (COL b) 2)) (AND (>= (COL c) 3) (<= (COL d) 4))))");
631 }
632
633
634 @Test
635 public void test_where_clause4() throws Exception {
636 testParser("where_clause", "WHERE a = 1 AND b <> 2 OR c >= 3 AND NOT d <= 4", "(WHERE (OR (AND (= (COL a) 1) (<> (COL b) 2)) (AND (>= (COL c) 3) (NOT (<= (COL d) 4)))))");
637 }
638
639
640
641
642 @Test
643 public void test_query1() throws Exception {
644 testParser("query", "SELECT * FROM Document", "(SELECT * (FROM (TABLE Document)))");
645 }
646
647
648 @Test
649 public void test_query2() throws Exception {
650 testParser("query", "SELECT a, b, c FROM Document", "(SELECT (SEL_LIST (COL a) (COL b) (COL c)) (FROM (TABLE Document)))");
651 }
652
653
654 @Test
655 public void test_query3() throws Exception {
656 testParser("query", "SELECT a, b FROM Document ORDER BY a, b", "(SELECT (SEL_LIST (COL a) (COL b)) (FROM (TABLE Document)) (ORDER_BY (COL a) ASC (COL b) ASC))");
657 }
658
659
660
661
662 @Test
663 public void test_where_clause5() throws Exception {
664 testParser("where_clause", "WHERE IN_TREE('ID00093854763') AND ('SMITH' = ANY AUTHORS)", "(WHERE (AND (IN_TREE 'ID00093854763') (EQ_ANY 'SMITH' (COL AUTHORS))))");
665 }
666
667
668
669
670
671
672
673 @Test
674 public void query1() throws Exception {
675 testParser("query", "SELECT * FROM Document WHERE foo = 1",
676 "(SELECT * (FROM (TABLE Document)) (WHERE (= (COL foo) 1)))");
677 }
678
679
680
681
682
683
684
685
686 @Test
687 public void query2() throws Exception {
688 testParser("query", "SELECT * FROM WHITE_PAPER", "(SELECT * (FROM (TABLE WHITE_PAPER)))");
689 }
690
691
692
693
694
695
696
697 @Test
698 public void query3() throws Exception {
699 testParser("query",
700 "SELECT TITLE, AUTHORS, DATE " +
701 "FROM WHITE_PAPER " +
702 "WHERE ( IN_TREE('ID00093854763') ) AND ( 'SMITH' = ANY AUTHORS )",
703 "(SELECT (SEL_LIST (COL TITLE) (COL AUTHORS) (COL DATE)) (FROM (TABLE WHITE_PAPER)) (WHERE (AND (IN_TREE 'ID00093854763') (EQ_ANY 'SMITH' (COL AUTHORS)))))");
704 }
705
706
707
708
709
710
711
712 @Test
713 public void query4() throws Exception {
714 testParserOk("query",
715 "SELECT Y.CLAIM_NUM, X.PROPERTY_ADDRESS, Y.DAMAGE_ESTIMATES " +
716 "FROM POLICY AS X JOIN CLAIMS AS Y ON X.POLICY_NUM = Y.POLICY_NUM " +
717 "WHERE ( 100000 = ANY Y.DAMAGE_ESTIMATES ) AND ( Y.CAUSE NOT LIKE '%Katrina%' )");
718 }
719
720
721
722
723
724
725
726 @Test
727 public void query5() throws Exception {
728 testParserFail("query",
729 "SELECT Y.CLAIM_NUM, X.PROPERTY_ADDRESS, Y.DAMAGE_ESTIMATES " +
730 "FROM POLICY AS X JOIN CLAIMS AS Y ON X.POLICY_NUM = Y.POLICY_NUM " +
731 " WHERE ( 100000 <= ANY Y.DAMAGE_ESTIMATES ) AND ( Y.CAUSE NOT LIKE '%Katrina%' )");
732 }
733
734
735
736
737
738
739
740 @Test
741 public void query6() throws Exception {
742 testParserOk("query", " SELECT * FROM CAR_REVIEW WHERE ANY FEATURES IN ('NAVIGATION SYSTEM', 'SATELLITE RADIO', 'MP3' )");
743 }
744
745
746
747
748
749
750
751
752
753 @Test
754 public void query7() throws Exception {
755 testParserOk("query",
756 "SELECT OBJECT_ID, SCORE() AS X, DESTINATION, DEPARTURE_DATES " +
757 "FROM TRAVEL_BROCHURE " +
758 "WHERE ( CONTAINS('CARIBBEAN CENTRAL AMERICA CRUISE TOUR') ) AND( '2010-1-1' = ANY DEPARTURE_DATES )");
759 }
760
761 @Test
762 public void queryEsc1() throws Exception {
763 testParserOk("query",
764 "SELECT * FROM cmis:document " +
765 "WHERE cmis:name LIKE 'abc\\%'");
766 }
767
768 }