01: /*
02: * TestQueryExpressionSplit.java
03: *
04: * Created on October 18, 2006, 1:57 PM
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09: /*
10: * Licensed to the Apache Software Foundation (ASF) under one
11: * or more contributor license agreements. See the NOTICE file
12: * distributed with this work for additional information
13: * regarding copyright ownership. The ASF licenses this file
14: * to you under the Apache License, Version 2.0 (the
15: * "License"); you may not use this file except in compliance
16: * with the License. You may obtain a copy of the License at
17: *
18: * http://www.apache.org/licenses/LICENSE-2.0
19: *
20: * Unless required by applicable law or agreed to in writing,
21: * software distributed under the License is distributed on an
22: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23: * KIND, either express or implied. See the License for the
24: * specific language governing permissions and limitations
25: * under the License.
26: */
27: package org.apache.openjpa.persistence.query;
28:
29: import java.util.Arrays;
30: import java.util.List;
31:
32: import org.apache.openjpa.kernel.Filters;
33:
34: public class TestQueryExpressionSplit extends BaseQueryTest {
35:
36: /**
37: * Creates a new instance of TestQueryExpressionSplit
38: */
39:
40: public TestQueryExpressionSplit(String test) {
41: super (test);
42: }
43:
44: public void testSimple() {
45: assertEquals(new String[] { "foo() bar(boo)" }, Filters
46: .splitExpressions("foo() bar(boo)", ',', 3));
47: assertEquals(new String[] { "foo() bar(boo)", "biz()",
48: "baz(boo)" }, Filters.splitExpressions(
49: "foo() bar(boo), biz(), baz(boo)", ',', 3));
50: }
51:
52: public void testCommaInString() {
53: assertEquals(new String[] { "foo \"bar(),biz)\"" }, Filters
54: .splitExpressions("foo \"bar(),biz)\"", ',', 3));
55: assertEquals(new String[] { "foo 'bar(),\"biz)'", "boo" },
56: Filters.splitExpressions("foo 'bar(),\"biz)', boo",
57: ',', 3));
58: }
59:
60: public void testCommaInFunction() {
61: assertEquals(new String[] { "(foo(bar, biz))",
62: "boo(biz, baz('xxx,yyy'))" }, Filters.splitExpressions(
63: "(foo(bar, biz)), " + "boo(biz, baz('xxx,yyy'))", ',',
64: 3));
65: }
66:
67: public void testEscapedString() {
68: assertEquals(new String[] { "foo \"bar\\\", biz(\"",
69: "\"baz\\\", boo\"" }, Filters.splitExpressions(
70: "foo \"bar\\\", biz(\", " + "\"baz\\\", boo\"", ',', 3));
71: }
72:
73: private void assertEquals(String[] ans, List test) {
74: List l = Arrays.asList(ans);
75: assertEquals(l + " != " + test, l, test);
76: }
77: }
|