01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.config;
17:
18: import java.util.Arrays;
19:
20: import junit.framework.TestCase;
21:
22: public class SunQueryFilterTest extends TestCase {
23: private SunConversion sunConversion = new SunConversion();
24:
25: public void testTrivial() {
26: String ejbQl = sunConversion.convertToEjbQl("item", null, null);
27: assertEquals("SELECT OBJECT(o) FROM item AS o", ejbQl);
28: ejbQl = sunConversion.convertToEjbQl("item", null, "true");
29: assertEquals("SELECT OBJECT(o) FROM item AS o", ejbQl);
30: }
31:
32: public void testParameterReplacement() {
33: String ejbQl = sunConversion.convertToEjbQl("item", Arrays
34: .asList("NAME"), "java.lang.String name",
35: "NAME == name");
36: assertEquals(
37: "SELECT OBJECT(o) FROM item AS o WHERE o.NAME = ?1",
38: ejbQl);
39: }
40:
41: public void testSymbolReplacement() {
42: String ejbQl = sunConversion.convertToEjbQl("item", Arrays
43: .asList("PRICE"), "float start, float end",
44: "start <= PRICE && PRICE >= end");
45: assertEquals(
46: "SELECT OBJECT(o) FROM item AS o WHERE ?1 <= o.PRICE and o.PRICE >= ?2",
47: ejbQl);
48: }
49:
50: public void testAllSymbolReplacement() {
51: String ejbQl = sunConversion.convertToEjbQl("item", null,
52: "&& || ! == !=");
53: assertEquals(
54: "SELECT OBJECT(o) FROM item AS o WHERE and or not = <>",
55: ejbQl);
56: }
57:
58: public void testNoWhiteSpace() {
59: String ejbQl = sunConversion.convertToEjbQl("item", Arrays
60: .asList("PRICE"), "float start, float end",
61: "start<=PRICE&&PRICE>=end");
62: assertEquals(
63: "SELECT OBJECT(o) FROM item AS o WHERE ?1 <= o.PRICE and o.PRICE >= ?2",
64: ejbQl);
65: }
66: }
|