1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact tma@netspace.net.au.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2003-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: StringTest.java,v 1.5 2004/02/03 21:52:11 tanderson Exp $
44 */
45 package org.exolab.jmscts.test.selector;
46
47 import java.util.HashMap;
48
49 import junit.framework.Test;
50
51 import org.exolab.jmscts.core.TestCreator;
52
53
54 /***
55 * This class tests selectors containing string literals and objects
56 *
57 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
58 * @version $Revision: 1.5 $
59 * @see AbstractSelectorTestCase
60 * @jmscts.message TextMessage
61 */
62 public class StringTest extends AbstractSelectorTestCase {
63
64 /***
65 * Message properties
66 */
67 private static final HashMap PROPERTIES = new HashMap();
68
69
70 /***
71 * Create an instance of this class for a specific test case
72 *
73 * @param name the name of test case
74 */
75 public StringTest(String name) {
76 super(name);
77 }
78
79 /***
80 * Sets up the test suite
81 *
82 * @return an instance of this class that may be run by
83 * {@link org.exolab.jmscts.core.JMSTestRunner}
84 */
85 public static Test suite() {
86 return TestCreator.createSendReceiveTest(StringTest.class);
87 }
88
89 /***
90 * Verifies that the selector <code>'abc' = 'abc'</code> selects
91 * all messages
92 *
93 * @jmscts.requirement selector.literal.string
94 * @jmscts.requirement selector.comparison.string
95 * @jmscts.requirement selector.expression
96 * @throws Exception for any error
97 */
98 public void testEquals() throws Exception {
99 checkSelector("'abc' = 'abc'", true);
100 }
101
102 /***
103 * Verifies that the selector <code>Country = 'France'</code> selects
104 * all messages, when the string property 'Country' is set, with
105 * value 'France'
106 *
107 * @jmscts.requirement selector.literal.string
108 * @jmscts.requirement selector.comparison.string
109 * @jmscts.requirement selector.expression
110 * @throws Exception for any error
111 */
112 public void testEqualsProperty() throws Exception {
113 checkSelector("Country = 'France'", true, PROPERTIES);
114 }
115
116 /***
117 * Verifies that string literals are case sensitive, using the selector
118 * <code>'abc' = 'ABC'</code>. This shouldn't select any messages.
119 *
120 * @jmscts.requirement selector.literal.string
121 * @jmscts.requirement selector.comparison.string
122 * @jmscts.requirement selector.expression
123 * @throws Exception for any error
124 */
125 public void testCaseComparison1() throws Exception {
126 checkSelector("'abc' = 'ABC'", false);
127 }
128
129 /***
130 * Verifies that string literals are case sensitive, using the selector
131 * <code>'abc' <> 'ABC'</code>. This should select all messages.
132 *
133 * @jmscts.requirement selector.literal.string
134 * @jmscts.requirement selector.comparison.string
135 * @jmscts.requirement selector.expression
136 * @throws Exception for any error
137 */
138 public void testCaseComparison2() throws Exception {
139 checkSelector("'abc' <> 'ABC'", true);
140 }
141
142 /***
143 * Verifies that string literals are case sensitive when compared
144 * with string properties, using the selector
145 * <code>Country = 'france'</code>, and the string property 'Country',
146 * with value 'France'. This should select no messages.
147 *
148 * @jmscts.requirement selector.literal.string
149 * @jmscts.requirement selector.comparison.string
150 * @jmscts.requirement selector.expression
151 * @throws Exception for any error
152 */
153 public void testCaseComparison3() throws Exception {
154 checkSelector("Country = 'france'", false, PROPERTIES);
155 }
156
157 /***
158 * Verifies that string literals can contain embedded quotes, using
159 * the selector <code>'it''s' = 'it''s'</code>. This should select
160 * all messages
161 *
162 * @jmscts.requirement selector.literal.string
163 * @jmscts.requirement selector.comparison.string
164 * @jmscts.requirement selector.expression
165 * @throws Exception for any error
166 */
167 public void testCheckSingleQuotes1() throws Exception {
168 checkSelector("'it''s' = 'it''s'", true);
169 }
170
171 /***
172 * Verifies that the quotes are preserved in string literals with embedded
173 * quotes, using the selector <code>'it''s' = 'its'</code>.
174 * This should select no messages
175 *
176 * @jmscts.requirement selector.literal.string
177 * @jmscts.requirement selector.comparison.string
178 * @jmscts.requirement selector.expression
179 * @throws Exception for any error
180 */
181 public void testCheckSingleQuotes2() throws Exception {
182 checkSelector("'it''s' = 'its'", false);
183 }
184
185 /***
186 * Verifies that the selector <code>'abc' < 'abc'</code> throws
187 * InvalidSelectorException
188 *
189 * @jmscts.requirement selector.comparison.string
190 * @jmscts.requirement selector.validation
191 * @throws Exception for any error
192 */
193 public void testLessThan1() throws Exception {
194 checkInvalidSelector("'abc' < 'abc'");
195 }
196
197 /***
198 * Verifies that the selector <code>dummy < 'abc'</code> throws
199 * InvalidSelectorException
200 *
201 * @jmscts.requirement selector.comparison.string
202 * @jmscts.requirement selector.validation
203 * @throws Exception for any error
204 */
205 public void testLessThan2() throws Exception {
206 checkInvalidSelector("dummy < 'abc'");
207 }
208
209 /***
210 * Verifies that the selector <code>'abc' < dummy</code> throws
211 * InvalidSelectorException
212 *
213 * @jmscts.requirement selector.comparison.string
214 * @jmscts.requirement selector.validation
215 * @throws Exception for any error
216 */
217 public void testLessThan3() throws Exception {
218 checkInvalidSelector("'abc' < dummy");
219 }
220
221 /***
222 * Verifies that the selector <code>'abc' > 'abc'</code> throws
223 * InvalidSelectorException
224 *
225 * @jmscts.requirement selector.comparison.string
226 * @jmscts.requirement selector.validation
227 * @throws Exception for any error
228 */
229 public void testGreaterThan1() throws Exception {
230 checkInvalidSelector("'abc' > 'abc'");
231 }
232
233 /***
234 * Verifies that the selector <code>dummy > 'abc'</code> throws
235 * InvalidSelectorException
236 *
237 * @jmscts.requirement selector.comparison.string
238 * @jmscts.requirement selector.validation
239 * @throws Exception for any error
240 */
241 public void testGreaterThan2() throws Exception {
242 checkInvalidSelector("dummy > 'abc'");
243 }
244
245 /***
246 * Verifies that the selector <code>'abc' > dummy</code> throws
247 * InvalidSelectorException
248 *
249 * @jmscts.requirement selector.comparison.string
250 * @jmscts.requirement selector.validation
251 * @throws Exception for any error
252 */
253 public void testGreaterThan3() throws Exception {
254 checkInvalidSelector("'abc' < dummy");
255 }
256
257 /***
258 * Verifies that the selector <code>'abc' <= 'abc'</code> throws
259 * InvalidSelectorException
260 *
261 * @jmscts.requirement selector.comparison.string
262 * @jmscts.requirement selector.validation
263 * @throws Exception for any error
264 */
265 public void testLessEquals1() throws Exception {
266 checkInvalidSelector("'abc' <= 'abc'");
267 }
268
269 /***
270 * Verifies that the selector <code>dummy <= 'abc'</code> throws
271 * InvalidSelectorException
272 *
273 * @jmscts.requirement selector.comparison.string
274 * @jmscts.requirement selector.validation
275 * @throws Exception for any error
276 */
277 public void testLessEquals2() throws Exception {
278 checkInvalidSelector("dummy <= 'abc'");
279 }
280
281 /***
282 * Verifies that the selector <code>'abc' <= dummy</code> throws
283 * InvalidSelectorException
284 *
285 * @jmscts.requirement selector.comparison.string
286 * @jmscts.requirement selector.validation
287 * @throws Exception for any error
288 */
289 public void testLessEquals3() throws Exception {
290 checkInvalidSelector("'abc' <= dummy");
291 }
292
293 /***
294 * Verifies that the selector <code>'abc' >= 'abc'</code> throws
295 * InvalidSelectorException
296 *
297 * @jmscts.requirement selector.comparison.string
298 * @jmscts.requirement selector.validation
299 * @throws Exception for any error
300 */
301 public void testGreaterEquals1() throws Exception {
302 checkInvalidSelector("'abc' >= 'abc'");
303 }
304
305 /***
306 * Verifies that the selector <code>dummy >= 'abc'</code> throws
307 * InvalidSelectorException
308 *
309 * @jmscts.requirement selector.comparison.string
310 * @jmscts.requirement selector.validation
311 * @throws Exception for any error
312 */
313 public void testGreaterEquals2() throws Exception {
314 checkInvalidSelector("dummy >= 'abc'");
315 }
316
317 /***
318 * Verifies that the selector <code>'abc' >= dummy</code> throws
319 * InvalidSelectorException
320 *
321 * @jmscts.requirement selector.comparison.string
322 * @jmscts.requirement selector.validation
323 * @throws Exception for any error
324 */
325 public void testGreaterEquals3() throws Exception {
326 checkInvalidSelector("'abc' >= dummy");
327 }
328
329 /***
330 * Verifies that the selector <code>'abc'</code> throws
331 * InvalidSelectorException
332 *
333 * @jmscts.requirement selector.validation
334 * @throws Exception for any error
335 */
336 public void testInvalid1() throws Exception {
337 checkInvalidSelector("'abc'");
338 }
339
340 /***
341 * Verifies that the selector <code>'abc' = 'abc</code> throws
342 * InvalidSelectorException
343 *
344 * @jmscts.requirement selector.validation
345 * @throws Exception for any error
346 */
347 public void testInvalid2() throws Exception {
348 checkInvalidSelector("'abc' = 'abc");
349 }
350
351 /***
352 * Verifies that the selector <code>'abc' = abc'</code> throws
353 * InvalidSelectorException
354 *
355 * @jmscts.requirement selector.validation
356 * @throws Exception for any error
357 */
358 public void testInvalid3() throws Exception {
359 checkInvalidSelector("'abc' = abc'");
360 }
361
362 /***
363 * Verifies that the selector <code>'abc = 'abc'</code> throws
364 * InvalidSelectorException
365 *
366 * @jmscts.requirement selector.validation
367 * @throws Exception for any error
368 */
369 public void testInvalid4() throws Exception {
370 checkInvalidSelector("'abc = 'abc'");
371 }
372
373 /***
374 * Verifies that the selector <code>'abc'''' = 'abc'</code> throws
375 * InvalidSelectorException
376 *
377 * @jmscts.requirement selector.validation
378 * @throws Exception for any error
379 */
380 public void testInvalid5() throws Exception {
381 checkInvalidSelector("'abc'''' = 'abc'");
382 }
383
384 /***
385 * Verifies that the selector <code>"abc" = "abc"</code> throws
386 * InvalidSelectorException
387 *
388 * @jmscts.requirement selector.validation
389 * @throws Exception for any error
390 */
391 public void testInvalid6() throws Exception {
392 checkInvalidSelector("\"abc\" = \"abc\"");
393 }
394
395 static {
396 PROPERTIES.put("Country", "France");
397 }
398
399 }
This page was automatically generated by Maven