KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jtests > jms > conform > selector > SelectorSyntaxTest


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2002 INRIA
4  * Contact: joram-team@objectweb.org
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.1 of the License, or 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
19  * USA
20  *
21  * Initial developer(s): Jeff Mesnil (jmesnil@inrialpes.fr)
22  * Contributor(s): ______________________________________.
23  */

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 /**
35  * Test the syntax of of message selector of JMS
36  *
37  * @author Jeff Mesnil (jmesnil@inrialpes.fr)
38  * @version $Id: SelectorSyntaxTest.java,v 1.8 2002/06/27 08:34:21 jmesnil Exp $
39  */

40 public class SelectorSyntaxTest extends PTPTestCase {
41
42     /**
43      * Test that identifiers that start with a valid Java identifier start character are valid.
44      * A valid identifier means that the method <code>Character.isJavaIdentifierStart</code> returns
45      * <code>true</code> for this identifier first character.
46      *
47      * @see <a HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Character.html#isJavaIdentifierStart(char)">Character.isJavaIdentifierStart(char)</a>
48      */

49     public void testValidIdentifiersStart() {
50         String JavaDoc 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     /**
67      * Test that identifiers that start with an invalid Java identifier start character are invalid.
68      *
69      * @see #testValidIdentifiersStart()
70      */

71     public void testInvalidIdentifiersStart() {
72         String JavaDoc 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     /**
96      * Test that message selector can be an empty string.
97      */

98     public void testEmptyStringAsSelector() {
99         try {
100             receiver = receiverSession.createReceiver(receiverQueue, "");
101         } catch (JMSException e) {
102             fail(e);
103         }
104     }
105
106     /**
107      * Test that identifiers can't be <code>NULL</code>.
108      */

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     /**
120      * Test that identifiers can't be <code>TRUE</code>.
121      */

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     /**
131      * Test that identifiers can't be <code>FALSE</code>.
132      */

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     /**
142      * Test that identifiers can't be <code>NOT</code>.
143      */

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     /**
153      * Test that identifiers can't be <code>AND</code>.
154      */

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     /**
164      * Test that identifiers can't be <code>OR</code>.
165      */

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     /**
176      * Test that identifiers can't be <code>BETWEEN</code>.
177      */

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     /**
188      * Test that identifiers can't be <code>LIKE</code>.
189      */

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     /**
200      * Test that identifiers can't be <code>IN</code>.
201      */

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     /**
212      * Test that identifiers can't be <code>IS</code>.
213      */

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     /**
224      * Test that identifiers can't be <code>ESCAPE</code>.
225      */

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     /**
235      * Test syntax of "<em>identifier</em> IS [NOT] NULL"
236      */

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     /**
247      * Test syntax of "<em>identifier</em> [NOT] LIKE <em>pattern-value</em> [ESCAPE <em>escape-character</em>]"
248      */

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     /**
261      * Test syntax of "<em>identifier</em> [NOT] IN (<em>string-literal1</em>, <em>string-literal2</em>,...)"
262      */

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     /**
273      * Test syntax of "<em>arithmetic-expr1</em> [NOT] BETWEEN <em>arithmetic-expr2</em> and <em>arithmetic-expr3</em>"
274      */

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     /**
285      * Test diffent syntax for approximate numeric literal (+6.2, -95.7, 7.)
286      */

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     /**
298      * Test diffent syntax for exact numeric literal (+62, -957, 57)
299      */

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     /**
311      * Test diffent syntax for zero as an exact or an approximate numeric literal (0, 0.0, 0.)
312      */

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     /**
324      * Test diffent syntax for string literal ('literal' and 'literal''s')
325      */

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     /**
336      * Method to use this class in a Test suite
337      */

338     public static Test suite() {
339         return new TestSuite(SelectorSyntaxTest.class);
340     }
341     
342     public SelectorSyntaxTest(String JavaDoc name) {
343         super(name);
344     }
345 }
346
Popular Tags