KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > query > parser > SpeedoQLTest


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  * Authors: S.Chassande-Barrioz.
25  *
26  */

27
28 package org.objectweb.speedo.runtime.query.parser;
29
30 import junit.framework.TestCase;
31
32 import java.io.CharArrayReader JavaDoc;
33
34 import org.objectweb.util.monolog.api.Logger;
35 import org.objectweb.util.monolog.api.BasicLevel;
36 import org.objectweb.util.monolog.Monolog;
37 import org.objectweb.speedo.query.parser.SpeedoQL;
38
39 /**
40  * Speedo QL Test
41  * Test a list of valid filters.
42  */

43 public class SpeedoQLTest extends TestCase {
44     final static String JavaDoc filters[] = {
45         "toto.titi",
46         "toto.titi()",
47         "this.toto",
48         "this.titi()",
49         "(+78)",
50         "(-89458.457)",
51         "(~788)",
52         "((~abc)|| tyty)",
53         "(!rere && toto+7)",
54         "((boolean)john)",
55         "(a < b > c <= d >= e | f || g & h && i == j != k + l - m / n * o ^ p.jotp())",
56         "((byte)b && (short)s || (int)i <= (long)l == (char)c * (float)f / (double)d == (true) && (false | null))",
57         "null",
58         "((char)(byte)(short)b || (char)(java.lang.String)s)",
59         "my.toto((q<b) + 9)",
60         "(house.b())",
61         "((((g)a < b.g())))",
62         "(+4 < t)",
63         "((-4+9*8) == toto.titi.titi.ktkt(one))",
64         "((a < b.house()) || (c.name > ((d*4)/100)))",
65         "toto(tutu).titi(tata)",
66         "toto(titi)",
67         "((1 < 5 > 3) || (4 && 5 <= (934 == 4)))",
68         "(((1 < 5) > 3) || ((4 && 5) <= (934 == 4)))",
69         "(true == a)",
70         "true == a",
71         "(a+b).method()",
72         "(salary > 3000)",
73         "(salary > sal)",
74         "(dept.name == dep)",
75         "(emps.contains(emp) & emp.salary > sal)",
76         "(depts.contains(name))",
77         "((getEmpId () >= 1) && (getEmpId () <= 10))",
78         "a == \"Paul\"",
79         "a >= 1 && b <= 10",
80         "x == param",
81         "x == 4",
82         "x == param1 && y == param2",
83         "reviewers.contains(person) && person == Employee",
84         "reviewers.contains(person) && person == person"
85         //"toto(titi, tatat)",
86
};
87
88     private final static String JavaDoc LOGGER_NAME
89             = "org.objectweb.speedo.rt.query.parser.speedoql";
90
91     private static Logger logger = null;
92
93     static {
94         logger = Monolog.initialize().getLogger(LOGGER_NAME);
95     }
96
97
98     public SpeedoQLTest(String JavaDoc name) {
99         super(name);
100     }
101
102     public void testAll() {
103         logger.log(BasicLevel.DEBUG, "SpeedoQL Test - javacc grammar");
104         for (int i = 0; i < filters.length; i++) {
105             String JavaDoc filter = filters[i];
106             logger.log(BasicLevel.DEBUG, "Testing: " + filter);
107             try {
108                 filter = '(' + filter + ')';
109                 new SpeedoQL(new CharArrayReader JavaDoc(filter.toCharArray())).SpeedoQL();
110             } catch (Throwable JavaDoc e) {
111                 logger.log(BasicLevel.ERROR, "Parsing of: " + filter, e);
112                 fail("Parsing of: " + filter);
113             }
114
115         }
116     }
117 }
118
Popular Tags