cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amicha...@apache.org
Subject svn commit: r1081817 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/ext/search/client/ test/java/org/apache/cxf/jaxrs/ext/search/client/
Date Tue, 15 Mar 2011 15:26:23 GMT
Author: amichalec
Date: Tue Mar 15 15:26:22 2011
New Revision: 1081817

URL: http://svn.apache.org/viewvc?rev=1081817&view=rev
Log:
SearchConditionBuilder as factory of builders. Minor naming changes.

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/CompleteCondition.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/PartialCondition.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/Property.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilderTest.java
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilder.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/CompleteCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/CompleteCondition.java?rev=1081817&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/CompleteCondition.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/CompleteCondition.java
Tue Mar 15 15:26:22 2011
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search.client;
+
+/**
+ * Part of fluent interface of {@link SearchConditionBuilder}.
+ */
+public interface CompleteCondition {
+    /** Conjunct current expression with another */
+    PartialCondition and();
+
+    /** Disjunct current expression with another */
+    PartialCondition or();
+
+    /** Finalize condition construction and build search condition query. */
+    String query();
+}

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java?rev=1081817&r1=1081816&r2=1081817&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
Tue Mar 15 15:26:22 2011
@@ -34,10 +34,10 @@ import org.apache.cxf.jaxrs.ext.search.S
  * Examples:
  * 
  * <pre>
- * FiqlSearchConditionBuilder b = new FiqlSearchConditionBuilder();
- * b.query().is(&quot;price&quot;).equalTo(123.5).build();
+ * SearchConditionBuilder b = SearchConditionBuilder.instance("fiql");
+ * b.is(&quot;price&quot;).equalTo(123.5).query();
  * // gives &quot;price==123.5&quot;
- * b.query().is(&quot;price&quot;).greaterThan(30).and().is(&quot;price&quot;).lessThan(50).build();
+ * b.is(&quot;price&quot;).greaterThan(30).and().is(&quot;price&quot;).lessThan(50).query();
  * // gives &quot;price=gt=30.0;price=lt=50.0&quot;
  * </pre>
  * 
@@ -45,35 +45,46 @@ import org.apache.cxf.jaxrs.ext.search.S
  * like the following example:
  * 
  * <pre>
- * PartialCondition c = b.query();
- * c.is("price").lessThan(100).and().or(
- *      c.is("title").equalTo("The lord*"), 
- *      c.is("author").equalTo("R.R.Tolkien")).build();
- * // gives "price=lt=100.0;(title==The lord*,author==R.R.Tolkien)"
+ * SearchConditionBuilder b = SearchConditionBuilder.instance("fiql");
+ * b.is(&quot;price&quot;).lessThan(100).and().or(
+ *     b.is(&quot;title&quot;).equalTo(&quot;The lord*&quot;),
+ *     b.is(&quot;author&quot;).equalTo(&quot;R.R.Tolkien&quot;)).query();
+ * // gives &quot;price=lt=100.0;(title==The lord*,author==R.R.Tolkien)&quot;
  * </pre>
  */
-public class FiqlSearchConditionBuilder implements SearchConditionBuilder {
+public class FiqlSearchConditionBuilder extends SearchConditionBuilder {
 
     private Map<String, String> properties;
-    
+
     public FiqlSearchConditionBuilder() {
-        this (Collections.<String, String>emptyMap());    
+        this(Collections.<String, String> emptyMap());
     }
-    
+
     public FiqlSearchConditionBuilder(Map<String, String> properties) {
-        this.properties = properties;    
+        this.properties = properties;
     }
-    
-    public String build() {
+
+    public String query() {
         return "";
     }
 
-    public PartialCondition query() {
-        return new Builder(properties);
+    @Override
+    public Property is(String property) {
+        return new Builder(properties).is(property);
+    }
+
+    @Override
+    public CompleteCondition and(CompleteCondition c1, CompleteCondition c2, 
+                                 CompleteCondition... cn) {
+        return new Builder(properties).and(c1, c2, cn);
+    }
+
+    @Override
+    public CompleteCondition or(CompleteCondition c1, CompleteCondition c2, CompleteCondition...
cn) {
+        return new Builder(properties).or(c1, c2, cn);
     }
 
-    private static class Builder implements SearchConditionBuilder.Property,
-        SearchConditionBuilder.CompleteCondition, SearchConditionBuilder.PartialCondition
{
+    private static class Builder implements Property, CompleteCondition, PartialCondition
{
         private String result = "";
         private Builder parent;
         private DateFormat df;
@@ -91,13 +102,8 @@ public class FiqlSearchConditionBuilder 
             timeZoneSupported = parent.isTimeZoneSupported();
         }
 
-        public String build() {
+        public String query() {
             return buildPartial(null);
-            // if (parent != null) {
-            // return parent.build() + result;
-            // } else {
-            // return result;
-            // }
         }
 
         private DateFormat getDateFormat() {
@@ -107,7 +113,7 @@ public class FiqlSearchConditionBuilder 
         private boolean isTimeZoneSupported() {
             return timeZoneSupported;
         }
-        
+
         // builds from parent but not further then exclude builder
         private String buildPartial(Builder exclude) {
             if (parent != null && !parent.equals(exclude)) {

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/PartialCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/PartialCondition.java?rev=1081817&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/PartialCondition.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/PartialCondition.java
Tue Mar 15 15:26:22 2011
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search.client;
+
+/**
+ * Part of fluent interface of {@link SearchConditionBuilder}.
+ */
+public interface PartialCondition {
+    /** Get property of inspected entity type */
+    Property is(String property);
+
+    /** Conjunct multiple expressions */
+    CompleteCondition and(CompleteCondition c1, CompleteCondition c2, CompleteCondition...
cn);
+
+    /** Disjunct multiple expressions */
+    CompleteCondition or(CompleteCondition c1, CompleteCondition c2, CompleteCondition...
cn);
+}

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/Property.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/Property.java?rev=1081817&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/Property.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/Property.java
Tue Mar 15 15:26:22 2011
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search.client;
+
+import java.util.Date;
+
+import javax.xml.datatype.Duration;
+
+/**
+ * Part of fluent interface of {@link SearchConditionBuilder}.
+ */
+public interface Property {
+    /** Is textual property equal to given literal or matching given pattern? */
+    CompleteCondition equalTo(String literalOrPattern);
+
+    /** Is numeric property equal to given number? */
+    CompleteCondition equalTo(double number);
+
+    /** Is date property same as given date? */
+    CompleteCondition equalTo(Date date);
+
+    /** Is date property same as date distant from now by given period of time? */
+    CompleteCondition equalTo(Duration distanceFromNow);
+
+    /** Is textual property different than given literal or not matching given pattern? */
+    CompleteCondition notEqualTo(String literalOrPattern);
+
+    /** Is numeric property different than given number? */
+    CompleteCondition notEqualTo(double number);
+
+    /** Is date property different than given date? */
+    CompleteCondition notEqualTo(Date date);
+
+    /** Is date property different than date distant from now by given period of time? */
+    CompleteCondition notEqualTo(Duration distanceFromNow);
+
+    /** Is numeric property greater than given number? */
+    CompleteCondition greaterThan(double number);
+
+    /** Is numeric property less than given number? */
+    CompleteCondition lessThan(double number);
+
+    /** Is numeric property greater or equal to given number? */
+    CompleteCondition greaterOrEqualTo(double number);
+
+    /** Is numeric property less or equal to given number? */
+    CompleteCondition lessOrEqualTo(double number);
+
+    /** Is date property after (greater than) given date? */
+    CompleteCondition after(Date date);
+
+    /** Is date property before (less than) given date? */
+    CompleteCondition before(Date date);
+
+    /** Is date property not before (greater or equal to) given date? */
+    CompleteCondition notBefore(Date date);
+
+    /** Is date property not after (less or equal to) given date? */
+    CompleteCondition notAfter(Date date);
+
+    /** Is date property after (greater than) date distant from now by given period of time?
*/
+    CompleteCondition after(Duration distanceFromNow);
+
+    /** Is date property before (less than) date distant from now by given period of time?
*/
+    CompleteCondition before(Duration distanceFromNow);
+
+    /** Is date property not after (less or equal to) date distant from now by given period
of time? */
+    CompleteCondition notAfter(Duration distanceFromNow);
+
+    /**
+     * Is date property not before (greater or equal to) date distant from now by given period
of time?
+     */
+    CompleteCondition notBefore(Duration distanceFromNow);
+
+    /** Is textual property lexically after (greater than) given literal? */
+    CompleteCondition lexicalAfter(String literal);
+
+    /** Is textual property lexically before (less than) given literal? */
+    CompleteCondition lexicalBefore(String literal);
+
+    /** Is textual property lexically not before (greater or equal to) given literal? */
+    CompleteCondition lexicalNotBefore(String literal);
+
+    /** Is textual property lexically not after (less or equal to) given literal? */
+    CompleteCondition lexicalNotAfter(String literal);
+}

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilder.java?rev=1081817&r1=1081816&r2=1081817&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilder.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilder.java
Tue Mar 15 15:26:22 2011
@@ -18,116 +18,54 @@
  */
 package org.apache.cxf.jaxrs.ext.search.client;
 
-import java.util.Date;
-
-import javax.xml.datatype.Duration;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
- * Builds client-side search condition string using `fluent interface' style. It helps build
create part of
- * URL that will be parsed by server-side counterpart e.g. FiqlSearchConditionBuilder has
FiqlParser.
+ * Builder of client-side search condition string using `fluent interface' style. It helps
build create part
+ * of URL that will be parsed by server-side counterpart. It is factory of different implementations
e.g. for
+ * {@link FiqlSearchConditionBuilder}, that has {@link org.apache.cxf.jaxrs.ext.search.FiqlParser
FiqlParser}
+ * on server-side, one can use <tt>SearchConditionBuilder.instance("FIQL")</tt>.
+ * <p>
+ * See {@link FiqlSearchConditionBuilder} for examples of usage.
  */
-public interface SearchConditionBuilder {
-
-    /** Creates unconstrained query (no conditions) */
-    PartialCondition query();
-
-    /** Finalize condition construction and build search condition. */
-    String build();
-
-    public interface Property {
-        /** Is textual property equal to given literal or matching given pattern? */
-        CompleteCondition equalTo(String literalOrPattern);
-
-        /** Is numeric property equal to given number? */
-        CompleteCondition equalTo(double number);
-
-        /** Is date property same as given date? */
-        CompleteCondition equalTo(Date date);
-
-        /** Is date property same as date distant from now by given period of time? */
-        CompleteCondition equalTo(Duration distanceFromNow);
-
-        /** Is textual property different than given literal or not matching given pattern?
*/
-        CompleteCondition notEqualTo(String literalOrPattern);
-
-        /** Is numeric property different than given number? */
-        CompleteCondition notEqualTo(double number);
-
-        /** Is date property different than given date? */
-        CompleteCondition notEqualTo(Date date);
-
-        /** Is date property different than date distant from now by given period of time?
*/
-        CompleteCondition notEqualTo(Duration distanceFromNow);
-
-        /** Is numeric property greater than given number? */
-        CompleteCondition greaterThan(double number);
-
-        /** Is numeric property less than given number? */
-        CompleteCondition lessThan(double number);
-
-        /** Is numeric property greater or equal to given number? */
-        CompleteCondition greaterOrEqualTo(double number);
-
-        /** Is numeric property less or equal to given number? */
-        CompleteCondition lessOrEqualTo(double number);
+public abstract class SearchConditionBuilder implements PartialCondition {
 
-        /** Is date property after (greater than) given date? */
-        CompleteCondition after(Date date);
-
-        /** Is date property before (less than) given date? */
-        CompleteCondition before(Date date);
-
-        /** Is date property not before (greater or equal to) given date? */
-        CompleteCondition notBefore(Date date);
-
-        /** Is date property not after (less or equal to) given date? */
-        CompleteCondition notAfter(Date date);
-
-        /** Is date property after (greater than) date distant from now by given period of
time? */
-        CompleteCondition after(Duration distanceFromNow);
-
-        /** Is date property before (less than) date distant from now by given period of
time? */
-        CompleteCondition before(Duration distanceFromNow);
-
-        /** Is date property not after (less or equal to) date distant from now by given
period of time? */
-        CompleteCondition notAfter(Duration distanceFromNow);
-
-        /** Is date property not before (greater or equal to) date distant from now by given

-         * period of time? */
-        CompleteCondition notBefore(Duration distanceFromNow);
-
-        /** Is textual property lexically after (greater than) given literal? */
-        CompleteCondition lexicalAfter(String literal);
-
-        /** Is textual property lexically before (less than) given literal? */
-        CompleteCondition lexicalBefore(String literal);
-
-        /** Is textual property lexically not before (greater or equal to) given literal?
*/
-        CompleteCondition lexicalNotBefore(String literal);
-
-        /** Is textual property lexically not after (less or equal to) given literal? */
-        CompleteCondition lexicalNotAfter(String literal);
+    private static Map<String, SearchConditionBuilder> lang2impl;
+    private static SearchConditionBuilder defaultImpl;
+    static {
+        defaultImpl = new FiqlSearchConditionBuilder();
+        lang2impl = new HashMap<String, SearchConditionBuilder>();
+        lang2impl.put("fiql", defaultImpl);
     }
-    
-    public interface PartialCondition {
-        /** Get property of inspected entity type */
-        Property is(String property);
 
-        /** Conjunct multiple expressions */
-        CompleteCondition and(CompleteCondition c1, CompleteCondition c2, CompleteCondition...
cn);
-
-        /** Disjunct multiple expressions */
-        CompleteCondition or(CompleteCondition c1, CompleteCondition c2, CompleteCondition...
cn);
+    /**
+     * Creates instance of builder.
+     * 
+     * @return default implementation of builder.
+     */
+    public static SearchConditionBuilder instance() {
+        return instance("FIQL");
     }
-    
-    public interface CompleteCondition /*extends PartialCondition*/ {
-        /** Conjunct current expression with another */
-        PartialCondition and();
-
-        /** Disjunct current expression with another */
-        PartialCondition or();
 
-        /** Finalize condition construction and build search condition. */
-        String build();
+    /**
+     * Creates instance of builder for specific language.
+     * 
+     * @param language alias of language, case insensitive. If alias is unknown, default
FIQL implementation
+     *            is returned.
+     * @return implementation of expected or default builder.
+     */
+    public static SearchConditionBuilder instance(String language) {
+        SearchConditionBuilder impl = null;
+        if (language != null) {
+            impl = lang2impl.get(language.toLowerCase());
+        }
+        if (impl == null) {
+            impl = new FiqlSearchConditionBuilder();
+        }
+        return impl;
     }
+
+    /** Finalize condition construction and build search condition query. */
+    public abstract String query();
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java?rev=1081817&r1=1081816&r2=1081817&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
Tue Mar 15 15:26:22 2011
@@ -33,7 +33,6 @@ import javax.xml.datatype.Duration;
 import static junit.framework.Assert.assertEquals;
 
 import org.apache.cxf.jaxrs.ext.search.SearchUtils;
-import org.apache.cxf.jaxrs.ext.search.client.SearchConditionBuilder.PartialCondition;
 
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -59,25 +58,25 @@ public class FiqlSearchConditionBuilderT
     
     @Test
     public void testEmptyBuild() {
-        assertEquals("", b.build());
+        assertEquals("", b.query());
     }
 
     @Test
     public void testEqualToString() {
-        String ret = b.query().is("foo").equalTo("literalOrPattern*").build();
+        String ret = b.is("foo").equalTo("literalOrPattern*").query();
         assertEquals("foo==literalOrPattern*", ret);
     }
 
     @Test
     public void testEqualToNumber() {
-        String ret = b.query().is("foo").equalTo(123.5).build();
+        String ret = b.is("foo").equalTo(123.5).query();
         assertEquals("foo==123.5", ret);
     }
 
     @Test
     public void testEqualToDate() throws ParseException {
         Date d = df.parse("2011-03-01 12:34 +0000");
-        String ret = b.query().is("foo").equalTo(d).build();
+        String ret = b.is("foo").equalTo(d).query();
         assertEquals("foo==2011-03-01T12:34:00.000+00:00", ret);
     }
     
@@ -92,190 +91,186 @@ public class FiqlSearchConditionBuilderT
         
         FiqlSearchConditionBuilder bCustom = new FiqlSearchConditionBuilder(props);
         
-        String ret = bCustom.query().is("foo").equalTo(d).build();
+        String ret = bCustom.is("foo").equalTo(d).query();
         assertEquals("foo==2011-03-01T12:34:00", ret);
     }
 
     @Test
     public void testEqualToDuration() throws ParseException, DatatypeConfigurationException
{
         Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);

-        String ret = b.query().is("foo").equalTo(d).build();
+        String ret = b.is("foo").equalTo(d).query();
         assertEquals("foo==-P0Y0M1DT12H0M0S", ret);
     }
 
     @Test
     public void testNotEqualToString() {
-        String ret = b.query().is("foo").notEqualTo("literalOrPattern*").build();
+        String ret = b.is("foo").notEqualTo("literalOrPattern*").query();
         assertEquals("foo!=literalOrPattern*", ret);
     }
 
     @Test
     public void testNotEqualToNumber() {
-        String ret = b.query().is("foo").notEqualTo(123.5).build();
+        String ret = b.is("foo").notEqualTo(123.5).query();
         assertEquals("foo!=123.5", ret);
     }
 
     @Test
     public void testNotEqualToDate() throws ParseException {
         Date d = df.parse("2011-03-01 12:34 +0000");
-        String ret = b.query().is("foo").notEqualTo(d).build();
+        String ret = b.is("foo").notEqualTo(d).query();
         assertEquals("foo!=2011-03-01T12:34:00.000+00:00", ret);
     }
 
     @Test
     public void testNotEqualToDuration() throws ParseException, DatatypeConfigurationException
{
         Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);

-        String ret = b.query().is("foo").notEqualTo(d).build();
+        String ret = b.is("foo").notEqualTo(d).query();
         assertEquals("foo!=-P0Y0M1DT12H0M0S", ret);
     }
 
     @Test
     public void testGreaterThanString() {
-        String ret = b.query().is("foo").lexicalAfter("abc").build();
+        String ret = b.is("foo").lexicalAfter("abc").query();
         assertEquals("foo=gt=abc", ret);
     }
 
     @Test
     public void testLessThanString() {
-        String ret = b.query().is("foo").lexicalBefore("abc").build();
+        String ret = b.is("foo").lexicalBefore("abc").query();
         assertEquals("foo=lt=abc", ret);
     }
 
     @Test
     public void testLessOrEqualToString() {
-        String ret = b.query().is("foo").lexicalNotAfter("abc").build();
+        String ret = b.is("foo").lexicalNotAfter("abc").query();
         assertEquals("foo=le=abc", ret);
     }
 
     @Test
     public void testGreaterOrEqualToString() {
-        String ret = b.query().is("foo").lexicalNotBefore("abc").build();
+        String ret = b.is("foo").lexicalNotBefore("abc").query();
         assertEquals("foo=ge=abc", ret);
     }
     
     @Test
     public void testGreaterThanNumber() {
-        String ret = b.query().is("foo").greaterThan(25).build();
+        String ret = b.is("foo").greaterThan(25).query();
         assertEquals("foo=gt=25.0", ret);
     }
 
     @Test
     public void testLessThanNumber() {
-        String ret = b.query().is("foo").lessThan(25.333).build();
+        String ret = b.is("foo").lessThan(25.333).query();
         assertEquals("foo=lt=25.333", ret);
     }
 
     @Test
     public void testLessOrEqualToNumber() {
-        String ret = b.query().is("foo").lessOrEqualTo(0).build();
+        String ret = b.is("foo").lessOrEqualTo(0).query();
         assertEquals("foo=le=0.0", ret);
     }
 
     @Test
     public void testGreaterOrEqualToNumber() {
-        String ret = b.query().is("foo").greaterOrEqualTo(-5).build();
+        String ret = b.is("foo").greaterOrEqualTo(-5).query();
         assertEquals("foo=ge=-5.0", ret);
     }
 
     @Test
     public void testGreaterThanDate() throws ParseException {
         Date d = df.parse("2011-03-02 22:33 +0000");
-        String ret = b.query().is("foo").after(d).build();
+        String ret = b.is("foo").after(d).query();
         assertEquals("foo=gt=2011-03-02T22:33:00.000+00:00", ret);
     }
 
     @Test
     public void testLessThanDate() throws ParseException {
         Date d = df.parse("2011-03-02 22:33 +0000");
-        String ret = b.query().is("foo").before(d).build();
+        String ret = b.is("foo").before(d).query();
         assertEquals("foo=lt=2011-03-02T22:33:00.000+00:00", ret);
     }
 
     @Test
     public void testLessOrEqualToDate() throws ParseException {
         Date d = df.parse("2011-03-02 22:33 +0000");
-        String ret = b.query().is("foo").notAfter(d).build();
+        String ret = b.is("foo").notAfter(d).query();
         assertEquals("foo=le=2011-03-02T22:33:00.000+00:00", ret);
     }
 
     @Test
     public void testGreaterOrEqualToDate() throws ParseException {
         Date d = df.parse("2011-03-02 22:33 +0000");
-        String ret = b.query().is("foo").notBefore(d).build();
+        String ret = b.is("foo").notBefore(d).query();
         assertEquals("foo=ge=2011-03-02T22:33:00.000+00:00", ret);
     }
 
     @Test
     public void testGreaterThanDuration() throws DatatypeConfigurationException {
         Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);

-        String ret = b.query().is("foo").after(d).build();
+        String ret = b.is("foo").after(d).query();
         assertEquals("foo=gt=-P0Y0M1DT12H0M0S", ret);
     }
 
     @Test
     public void testLessThanDuration() throws DatatypeConfigurationException {
         Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);

-        String ret = b.query().is("foo").before(d).build();
+        String ret = b.is("foo").before(d).query();
         assertEquals("foo=lt=-P0Y0M1DT12H0M0S", ret);
     }
 
     @Test
     public void testLessOrEqualToDuration() throws DatatypeConfigurationException {
         Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);

-        String ret = b.query().is("foo").notAfter(d).build();
+        String ret = b.is("foo").notAfter(d).query();
         assertEquals("foo=le=-P0Y0M1DT12H0M0S", ret);
     }
 
     @Test
     public void testGreaterOrEqualToDuration() throws DatatypeConfigurationException {
         Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);

-        String ret = b.query().is("foo").notBefore(d).build();
+        String ret = b.is("foo").notBefore(d).query();
         assertEquals("foo=ge=-P0Y0M1DT12H0M0S", ret);
     }
     
     @Test
     public void testOrSimple() {
-        String ret = b.query().is("foo").greaterThan(20).or().is("foo").lessThan(10).build();
+        String ret = b.is("foo").greaterThan(20).or().is("foo").lessThan(10).query();
         assertEquals("foo=gt=20.0,foo=lt=10.0", ret);
     }    
     
     @Test
     public void testAndSimple() {
-        String ret = b.query().is("foo").greaterThan(20).and().is("bar").equalTo("plonk").build();
+        String ret = b.is("foo").greaterThan(20).and().is("bar").equalTo("plonk").query();
         assertEquals("foo=gt=20.0;bar==plonk", ret);
     }
     
     @Test
     public void testOrComplex() {
-        PartialCondition c = b.query();
-        String ret = c.or(c.is("foo").equalTo("aaa"), c.is("bar").equalTo("bbb")).build();
+        String ret = b.or(b.is("foo").equalTo("aaa"), b.is("bar").equalTo("bbb")).query();
         assertEquals("(foo==aaa,bar==bbb)", ret);
     }    
 
     @Test
     public void testAndComplex() {
-        PartialCondition c = b.query();
-        String ret = c.and(c.is("foo").equalTo("aaa"), c.is("bar").equalTo("bbb")).build();
+        String ret = b.and(b.is("foo").equalTo("aaa"), b.is("bar").equalTo("bbb")).query();
         assertEquals("(foo==aaa;bar==bbb)", ret);
     }    
 
     @Test
     public void testComplex1() {
-        PartialCondition c = b.query();
-        String ret = c.is("foo").equalTo(123.4).or().and(
-            c.is("bar").equalTo("asadf*"), 
-            c.is("baz").lessThan(20)).build();
+        String ret = b.is("foo").equalTo(123.4).or().and(
+            b.is("bar").equalTo("asadf*"), 
+            b.is("baz").lessThan(20)).query();
         assertEquals("foo==123.4,(bar==asadf*;baz=lt=20.0)", ret);
     }
 
     @Test
     public void testComplex2() {
-        PartialCondition c = b.query();
-        String ret = c.is("foo").equalTo(123.4).or().is("foo").equalTo("null").and().or(
-            c.is("bar").equalTo("asadf*"), 
-            c.is("baz").lessThan(20).and().or(
-                c.is("sub1").equalTo(0),
-                c.is("sub2").equalTo(0))).build();
+        String ret = b.is("foo").equalTo(123.4).or().is("foo").equalTo("null").and().or(
+            b.is("bar").equalTo("asadf*"), 
+            b.is("baz").lessThan(20).and().or(
+                b.is("sub1").equalTo(0),
+                b.is("sub2").equalTo(0))).query();
         
         assertEquals("foo==123.4,foo==null;(bar==asadf*,baz=lt=20.0;(sub1==0.0,sub2==0.0))",
ret);
     }

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilderTest.java?rev=1081817&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilderTest.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilderTest.java
Tue Mar 15 15:26:22 2011
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search.client;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class SearchConditionBuilderTest {
+
+    @Test
+    public void testDefault() throws Exception {
+        assertTrue(SearchConditionBuilder.instance() instanceof FiqlSearchConditionBuilder);
+    }
+
+    @Test
+    public void testFiqlImpl() throws Exception {
+        assertTrue(SearchConditionBuilder.instance("fiql") instanceof FiqlSearchConditionBuilder);
+    }
+
+    @Test
+    public void testCaseInsensitive() throws Exception {
+        assertTrue(SearchConditionBuilder.instance("fiQL") instanceof FiqlSearchConditionBuilder);
+    }
+
+    @Test
+    public void testDefaultFallback() throws Exception {
+        assertTrue(SearchConditionBuilder.instance("unknown language") instanceof FiqlSearchConditionBuilder);
+    }
+
+    @Test
+    public void testNullLang() throws Exception {
+        assertTrue(SearchConditionBuilder.instance(null) instanceof FiqlSearchConditionBuilder);
+    }
+}



Mime
View raw message