cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1095176 - 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, 19 Apr 2011 19:44:50 GMT
Author: sergeyb
Date: Tue Apr 19 19:44:49 2011
New Revision: 1095176

URL: http://svn.apache.org/viewvc?rev=1095176&view=rev
Log:
[JAX-RS] Some updates to SearchConditionBuilder

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/Property.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
    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
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java?rev=1095176&r1=1095175&r2=1095176&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 Apr 19 19:44:49 2011
@@ -29,7 +29,7 @@ import org.apache.cxf.jaxrs.ext.search.F
 import org.apache.cxf.jaxrs.ext.search.SearchUtils;
 
 /**
- * Builds client-side search condition that passed to backend can be consumed by {@link FiqlParser}.
+ * Builds a FIQL search condition.
  * <p>
  * Examples:
  * 
@@ -121,125 +121,130 @@ public class FiqlSearchConditionBuilder 
         }
 
         public CompleteCondition after(Date date) {
-            result += FiqlParser.GT + toString(date);
-            return this;
+            return condition(FiqlParser.GT, toString(date));
         }
 
         public CompleteCondition before(Date date) {
-            result += FiqlParser.LT + toString(date);
-            return this;
+            return condition(FiqlParser.LT, toString(date));
         }
 
         public CompleteCondition equalTo(String literalOrPattern) {
-            result += FiqlParser.EQ + literalOrPattern;
-            return this;
+            return condition(FiqlParser.EQ, literalOrPattern);
         }
 
         public CompleteCondition equalTo(double number) {
-            result += FiqlParser.EQ + number;
-            return this;
+            return condition(FiqlParser.EQ, number);
+        }
+        
+        public CompleteCondition equalTo(long number) {
+            return condition(FiqlParser.EQ, number);
         }
 
         public CompleteCondition equalTo(Date date) {
-            result += FiqlParser.EQ + toString(date);
-            return this;
+            return condition(FiqlParser.EQ, toString(date));
         }
 
         public CompleteCondition greaterOrEqualTo(double number) {
-            result += FiqlParser.GE + number;
-            return this;
+            return condition(FiqlParser.GE, number);
+        }
+        
+        public CompleteCondition greaterOrEqualTo(long number) {
+            return condition(FiqlParser.GE, number);
         }
 
         public CompleteCondition greaterThan(double number) {
-            result += FiqlParser.GT + number;
-            return this;
+            return condition(FiqlParser.GT, number);
+        }
+        
+        public CompleteCondition greaterThan(long number) {
+            return condition(FiqlParser.GT, number);
         }
 
         public CompleteCondition lessOrEqualTo(double number) {
-            result += FiqlParser.LE + number;
-            return this;
+            return condition(FiqlParser.LE, number);
+        }
+        
+        public CompleteCondition lessOrEqualTo(long number) {
+            return condition(FiqlParser.LE, number);
         }
 
         public CompleteCondition lessThan(double number) {
-            result += FiqlParser.LT + number;
-            return this;
+            return condition(FiqlParser.LT, number);
+        }
+        
+        public CompleteCondition lessThan(long number) {
+            return condition(FiqlParser.LT, number);
         }
 
         public CompleteCondition lexicalAfter(String literal) {
-            result += FiqlParser.GT + literal;
-            return this;
+            return condition(FiqlParser.GT, literal);
         }
 
         public CompleteCondition lexicalBefore(String literal) {
-            result += FiqlParser.LT + literal;
-            return this;
+            return condition(FiqlParser.LT, literal);
         }
 
         public CompleteCondition lexicalNotAfter(String literal) {
-            result += FiqlParser.LE + literal;
-            return this;
+            return condition(FiqlParser.LE, literal);
         }
 
         public CompleteCondition lexicalNotBefore(String literal) {
-            result += FiqlParser.GE + literal;
-            return this;
+            return condition(FiqlParser.GE, literal);
         }
 
         public CompleteCondition notAfter(Date date) {
-            result += FiqlParser.LE + toString(date);
-            return this;
+            return condition(FiqlParser.LE, toString(date));
         }
 
         public CompleteCondition notBefore(Date date) {
-            result += FiqlParser.GE + toString(date);
-            return this;
+            return condition(FiqlParser.GE, toString(date));
         }
 
         public CompleteCondition notEqualTo(String literalOrPattern) {
-            result += FiqlParser.NEQ + literalOrPattern;
-            return this;
+            return condition(FiqlParser.NEQ, literalOrPattern);
         }
 
         public CompleteCondition notEqualTo(double number) {
-            result += FiqlParser.NEQ + number;
-            return this;
+            return condition(FiqlParser.NEQ, number);
+        }
+        
+        public CompleteCondition notEqualTo(long number) {
+            return condition(FiqlParser.NEQ, number);
         }
 
         public CompleteCondition notEqualTo(Date date) {
-            result += FiqlParser.NEQ + toString(date);
-            return this;
+            return condition(FiqlParser.NEQ, toString(date));
         }
 
         public CompleteCondition after(Duration distanceFromNow) {
-            result += FiqlParser.GT + distanceFromNow;
-            return this;
+            return condition(FiqlParser.GT, distanceFromNow);
         }
 
         public CompleteCondition before(Duration distanceFromNow) {
-            result += FiqlParser.LT + distanceFromNow;
-            return this;
+            return condition(FiqlParser.LT, distanceFromNow);
         }
 
         public CompleteCondition equalTo(Duration distanceFromNow) {
-            result += FiqlParser.EQ + distanceFromNow;
-            return this;
+            return condition(FiqlParser.EQ, distanceFromNow);
         }
 
         public CompleteCondition notAfter(Duration distanceFromNow) {
-            result += FiqlParser.LE + distanceFromNow;
-            return this;
+            return condition(FiqlParser.LE, distanceFromNow);
         }
 
         public CompleteCondition notBefore(Duration distanceFromNow) {
-            result += FiqlParser.GE + distanceFromNow;
-            return this;
+            return condition(FiqlParser.GE, distanceFromNow);
         }
 
         public CompleteCondition notEqualTo(Duration distanceFromNow) {
-            result += FiqlParser.NEQ + distanceFromNow;
-            return this;
+            return condition(FiqlParser.NEQ, distanceFromNow);
         }
 
+        protected CompleteCondition condition(String operator, Object value) {
+            result += operator + value;
+            return this;
+        }
+        
         public PartialCondition and() {
             result += FiqlParser.AND;
             return this;

Modified: 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=1095176&r1=1095175&r2=1095176&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/Property.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/Property.java
Tue Apr 19 19:44:49 2011
@@ -29,9 +29,12 @@ 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? */
+    /** Is numeric property equal to given double number? */
     CompleteCondition equalTo(double number);
 
+    /** Is numeric property equal to given long number? */
+    CompleteCondition equalTo(long number);
+    
     /** Is date property same as given date? */
     CompleteCondition equalTo(Date date);
 
@@ -41,8 +44,11 @@ public interface Property {
     /** Is textual property different than given literal or not matching given pattern? */
     CompleteCondition notEqualTo(String literalOrPattern);
 
-    /** Is numeric property different than given number? */
+    /** Is numeric property different than given double number? */
     CompleteCondition notEqualTo(double number);
+    
+    /** Is numeric property different than given long number? */
+    CompleteCondition notEqualTo(long number);
 
     /** Is date property different than given date? */
     CompleteCondition notEqualTo(Date date);
@@ -52,15 +58,27 @@ public interface Property {
 
     /** Is numeric property greater than given number? */
     CompleteCondition greaterThan(double number);
+    
+    /** Is numeric property greater than given number? */
+    CompleteCondition greaterThan(long number);
 
     /** Is numeric property less than given number? */
     CompleteCondition lessThan(double number);
+    
+    /** Is numeric property less than given number? */
+    CompleteCondition lessThan(long number);
 
     /** Is numeric property greater or equal to given number? */
     CompleteCondition greaterOrEqualTo(double number);
+    
+    /** Is numeric property greater or equal to given number? */
+    CompleteCondition greaterOrEqualTo(long number);
 
     /** Is numeric property less or equal to given number? */
     CompleteCondition lessOrEqualTo(double number);
+    
+    /** Is numeric property less or equal to given number? */
+    CompleteCondition lessOrEqualTo(long number);
 
     /** Is date property after (greater than) given date? */
     CompleteCondition after(Date date);

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=1095176&r1=1095175&r2=1095176&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 Apr 19 19:44:49 2011
@@ -18,7 +18,7 @@
  */
 package org.apache.cxf.jaxrs.ext.search.client;
 
-import java.util.HashMap;
+import java.util.Collections;
 import java.util.Map;
 
 /**
@@ -31,21 +31,23 @@ import java.util.Map;
  */
 public abstract class SearchConditionBuilder implements PartialCondition {
 
-    private static Map<String, SearchConditionBuilder> lang2impl;
-    private static SearchConditionBuilder defaultImpl;
-    static {
-        defaultImpl = new FiqlSearchConditionBuilder();
-        lang2impl = new HashMap<String, SearchConditionBuilder>();
-        lang2impl.put("fiql", defaultImpl);
-    }
-
+    public static final String DEFAULT_LANGUAGE = "FIQL";
     /**
      * Creates instance of builder.
      * 
      * @return default implementation of builder.
      */
     public static SearchConditionBuilder instance() {
-        return instance("FIQL");
+        return instance(DEFAULT_LANGUAGE);
+    }
+    
+    /**
+     * Creates instance of builder with provided properties
+     * @param properties
+     * @return default implementation of builder.
+     */
+    public static SearchConditionBuilder instance(Map<String, String> properties) {
+        return instance(DEFAULT_LANGUAGE, properties);
     }
 
     /**
@@ -56,14 +58,14 @@ public abstract class SearchConditionBui
      * @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 instance(language, Collections.<String, String>emptyMap());
+    }
+    
+    public static SearchConditionBuilder instance(String language, Map<String, String>
properties) {
+        if (!DEFAULT_LANGUAGE.equalsIgnoreCase(language)) {
+            throw new IllegalArgumentException("Unsupported query language: " + language);
         }
-        return impl;
+        return new FiqlSearchConditionBuilder(properties);
     }
 
     /** Finalize condition construction and build search condition 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=1095176&r1=1095175&r2=1095176&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 Apr 19 19:44:49 2011
@@ -153,10 +153,16 @@ public class FiqlSearchConditionBuilderT
     }
     
     @Test
-    public void testGreaterThanNumber() {
-        String ret = b.is("foo").greaterThan(25).query();
+    public void testGreaterThanNumberDouble() {
+        String ret = b.is("foo").greaterThan(25.0).query();
         assertEquals("foo=gt=25.0", ret);
     }
+    
+    @Test
+    public void testGreaterThanLong() {
+        String ret = b.is("foo").greaterThan(25).query();
+        assertEquals("foo=gt=25", ret);
+    }
 
     @Test
     public void testLessThanNumber() {
@@ -165,16 +171,28 @@ public class FiqlSearchConditionBuilderT
     }
 
     @Test
-    public void testLessOrEqualToNumber() {
-        String ret = b.is("foo").lessOrEqualTo(0).query();
+    public void testLessOrEqualToNumberDouble() {
+        String ret = b.is("foo").lessOrEqualTo(0.0).query();
         assertEquals("foo=le=0.0", ret);
     }
+    
+    @Test
+    public void testLessOrEqualToNumberLong() {
+        String ret = b.is("foo").lessOrEqualTo(0).query();
+        assertEquals("foo=le=0", ret);
+    }
 
     @Test
-    public void testGreaterOrEqualToNumber() {
-        String ret = b.is("foo").greaterOrEqualTo(-5).query();
+    public void testGreaterOrEqualToNumberDouble() {
+        String ret = b.is("foo").greaterOrEqualTo(-5.0).query();
         assertEquals("foo=ge=-5.0", ret);
     }
+    
+    @Test
+    public void testGreaterOrEqualToNumberLong() {
+        String ret = b.is("foo").greaterOrEqualTo(-5).query();
+        assertEquals("foo=ge=-5", ret);
+    }
 
     @Test
     public void testGreaterThanDate() throws ParseException {
@@ -235,13 +253,13 @@ public class FiqlSearchConditionBuilderT
     @Test
     public void testOrSimple() {
         String ret = b.is("foo").greaterThan(20).or().is("foo").lessThan(10).query();
-        assertEquals("foo=gt=20.0,foo=lt=10.0", ret);
+        assertEquals("foo=gt=20,foo=lt=10", ret);
     }    
     
     @Test
     public void testAndSimple() {
         String ret = b.is("foo").greaterThan(20).and().is("bar").equalTo("plonk").query();
-        assertEquals("foo=gt=20.0;bar==plonk", ret);
+        assertEquals("foo=gt=20;bar==plonk", ret);
     }
     
     @Test
@@ -261,7 +279,7 @@ public class FiqlSearchConditionBuilderT
         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);
+        assertEquals("foo==123.4,(bar==asadf*;baz=lt=20)", ret);
     }
 
     @Test
@@ -272,6 +290,6 @@ public class FiqlSearchConditionBuilderT
                 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);
+        assertEquals("foo==123.4,foo==null;(bar==asadf*,baz=lt=20;(sub1==0,sub2==0))", ret);
     }
 }

Modified: 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=1095176&r1=1095175&r2=1095176&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilderTest.java
Tue Apr 19 19:44:49 2011
@@ -31,21 +31,16 @@ public class SearchConditionBuilderTest 
 
     @Test
     public void testFiqlImpl() throws Exception {
-        assertTrue(SearchConditionBuilder.instance("fiql") instanceof FiqlSearchConditionBuilder);
+        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);
+        assertTrue(SearchConditionBuilder.instance("fiql") instanceof FiqlSearchConditionBuilder);
     }
 
-    @Test
-    public void testNullLang() throws Exception {
-        assertTrue(SearchConditionBuilder.instance(null) instanceof FiqlSearchConditionBuilder);
+    @Test(expected = IllegalArgumentException.class)
+    public void testUnknownQueryLanguage() throws Exception {
+        SearchConditionBuilder.instance("unknown language");
     }
 }



Mime
View raw message