Skip to content
Permalink
Browse files
[CXF-5430]: Added initial support for OData 2.0 query language. Added…
… more test cases and more effective primitive type handling

git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1567615 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Andriy Redko committed Feb 12, 2014
1 parent c68ae4f commit 7686ddb3ce2663c2f6923b41ce3948371e17103d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
@@ -36,6 +36,10 @@
<cxf.lucene.version>4.0.0-BETA</cxf.lucene.version>
</properties>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -28,6 +28,7 @@
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<?> getTypeClass() {
return cls;
}

public Class<?> getWrappedTypeClass() {
return cls.isPrimitive() ? ClassUtils.primitiveToWrapper(cls) : cls;
}

public Type getGenericType() {
return genericType;
}
@@ -160,7 +160,7 @@ public Object visitBinary(BinaryExpression binaryExpression, BinaryOperator oper

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,
@@ -34,6 +34,9 @@ public static class Person {
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 void setAge(int age) {
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 void testFilterByAgeGreatThanValue() throws SearchParseException {
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)));
}
}

0 comments on commit 7686ddb

Please sign in to comment.