cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1567615 - in /cxf/trunk/rt/rs/extensions/search: ./ src/main/java/org/apache/cxf/jaxrs/ext/search/ src/main/java/org/apache/cxf/jaxrs/ext/search/odata/ src/test/java/org/apache/cxf/jaxrs/ext/search/odata/
Date Wed, 12 Feb 2014 13:25:52 GMT
Author: reta
Date: Wed Feb 12 13:25:52 2014
New Revision: 1567615

URL: http://svn.apache.org/r1567615
Log:
[CXF-5430]: Added initial support for OData 2.0 query language. Added more test cases and
more effective primitive type handling

Modified:
    cxf/trunk/rt/rs/extensions/search/pom.xml
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/Beanspector.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParser.java
    cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParserTest.java

Modified: cxf/trunk/rt/rs/extensions/search/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/pom.xml?rev=1567615&r1=1567614&r2=1567615&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/pom.xml (original)
+++ cxf/trunk/rt/rs/extensions/search/pom.xml Wed Feb 12 13:25:52 2014
@@ -37,6 +37,10 @@
     </properties>
     <dependencies>
         <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+        </dependency>    
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/Beanspector.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/Beanspector.java?rev=1567615&r1=1567614&r2=1567615&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/Beanspector.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/Beanspector.java
Wed Feb 12 13:25:52 2014
@@ -28,6 +28,7 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.lang.ClassUtils;
 import org.apache.cxf.jaxrs.ext.search.collections.CollectionCheckInfo;
 
 /**
@@ -207,6 +208,10 @@ public class Beanspector<T> {
             return cls;
         }
         
+        public Class<?> getWrappedTypeClass() {
+            return cls.isPrimitive() ? ClassUtils.primitiveToWrapper(cls) : cls;
+        }
+        
         public Type getGenericType() {
             return genericType;
         }

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParser.java?rev=1567615&r1=1567614&r2=1567615&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParser.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParser.java
Wed Feb 12 13:25:52 2014
@@ -160,7 +160,7 @@ public class ODataParser<T> extends Abst
             
             Object typedValue = null;
             // If property type and value type are compatible, just use them
-            if (property.typeInfo.getTypeClass().isAssignableFrom(value.typeClass)) {
+            if (property.typeInfo.getWrappedTypeClass().isAssignableFrom(value.typeClass))
{
                 typedValue = value.value;
             } else { // Property type and value type are not compatible and convert / cast
are required
                 typedValue = parseType(property.propertyName, null, null, property.propertyName,


Modified: cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParserTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParserTest.java?rev=1567615&r1=1567614&r2=1567615&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParserTest.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParserTest.java
Wed Feb 12 13:25:52 2014
@@ -34,6 +34,9 @@ public class ODataParserTest extends Ass
         private String firstName;
         private String lastName;
         private int age;
+        private float height;
+        private double hourlyRate;
+        private Long ssn;
 
         public Person() {
         }
@@ -67,10 +70,49 @@ public class ODataParserTest extends Ass
             this.age = age;
         }
         
+        public float getHeight() {
+            return height;
+        }
+        
+        public void setHeight(float height) {
+            this.height = height;
+        }
+        
+        public double getHourlyRate() {
+            return hourlyRate;
+        }
+        
+        public void setHourlyRate(double hourlyRate) {
+            this.hourlyRate = hourlyRate;
+        }
+        
+        public Long getSsn() {
+            return ssn;
+        }
+        
+        public void setSsn(Long ssn) {
+            this.ssn = ssn;
+        }
+        
         Person withAge(int newAge) {
             setAge(newAge);
             return this;
         }
+
+        Person withHeight(float newHeight) {
+            setHeight(newHeight);
+            return this;
+        }
+        
+        Person withHourlyRate(double newHourlyRate) {
+            setHourlyRate(newHourlyRate);
+            return this;
+        }
+        
+        Person withSsn(Long newSsn) {
+            setSsn(newSsn);
+            return this;
+        }
     }
 
     @Before
@@ -131,4 +173,25 @@ public class ODataParserTest extends Ass
         assertTrue(filter.isMet(new Person("Tom", "Bombadil").withAge(18)));
         assertFalse(filter.isMet(new Person("Tom", "Bombadil").withAge(16)));
     }
+    
+    @Test
+    public void testFilterByHeightGreatOrEqualValue() throws SearchParseException {
+        SearchCondition< Person > filter = parser.parse("Height ge 179.5f or Height
le 159.5d");
+        assertTrue(filter.isMet(new Person("Tom", "Bombadil").withHeight(185.6f)));
+        assertFalse(filter.isMet(new Person("Tom", "Bombadil").withHeight(166.7f)));
+    }
+    
+    @Test
+    public void testFilterByHourlyRateGreatThanValue() throws SearchParseException {
+        SearchCondition< Person > filter = parser.parse("HourlyRate ge 30.50d or HourlyRate
lt 20.50f");
+        assertTrue(filter.isMet(new Person("Tom", "Bombadil").withHourlyRate(45.6)));
+        assertFalse(filter.isMet(new Person("Tom", "Bombadil").withHourlyRate(26.7)));
+    }
+    
+    @Test
+    public void testFilterBySsnNotEqualsToValue() throws SearchParseException {
+        SearchCondition< Person > filter = parser.parse("Ssn ne 748232221");
+        assertTrue(filter.isMet(new Person("Tom", "Bombadil").withSsn(553232222L)));
+        assertFalse(filter.isMet(new Person("Tom", "Bombadil").withHourlyRate(748232221L)));
+    }
 }



Mime
View raw message