You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/01/16 16:13:37 UTC
git commit: [OLINGO-122] Allow NULL data parameter and return NULL
Updated Branches:
refs/heads/master 6c8c2db5f -> 6bfbe8fb8
[OLINGO-122] Allow NULL data parameter and return NULL
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/6bfbe8fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/6bfbe8fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/6bfbe8fb
Branch: refs/heads/master
Commit: 6bfbe8fb82127a6eda20e1e77157fed4c2651f6a
Parents: 6c8c2db
Author: Michael Bolz <mi...@apache.org>
Authored: Thu Jan 16 16:13:12 2014 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Thu Jan 16 16:13:12 2014 +0100
----------------------------------------------------------------------
.../core/datasource/AnnotationValueAccess.java | 14 ++++++++-----
.../datasource/AnnotationValueAccessTest.java | 22 ++++++++++++++++++++
2 files changed, 31 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/6bfbe8fb/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccess.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccess.java
index b685ec8..cc36d2a 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccess.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccess.java
@@ -54,10 +54,12 @@ public class AnnotationValueAccess implements ValueAccess {
*/
@Override
public <T, V> void setPropertyValue(final T data, final EdmProperty property, final V value) throws ODataException {
- if (annotationHelper.isEdmAnnotated(data)) {
- annotationHelper.setValueForProperty(data, property.getName(), value);
- } else {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ if (data != null) {
+ if (annotationHelper.isEdmAnnotated(data)) {
+ annotationHelper.setValueForProperty(data, property.getName(), value);
+ } else {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
}
}
@@ -69,7 +71,9 @@ public class AnnotationValueAccess implements ValueAccess {
*/
@Override
public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
- if (annotationHelper.isEdmAnnotated(data)) {
+ if(data == null) {
+ return null;
+ } else if (annotationHelper.isEdmAnnotated(data)) {
Class<?> fieldType = annotationHelper.getFieldTypeForProperty(data, property.getName());
if (fieldType == null) {
throw new ODataException("No field type found for property " + property);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/6bfbe8fb/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccessTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccessTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccessTest.java
index 5e9147f..df7b3a4 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccessTest.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccessTest.java
@@ -43,6 +43,17 @@ public class AnnotationValueAccessTest {
Assert.assertEquals(String.class, type);
}
+ @Test
+ public void getPropertyTypeNullData() throws ODataException {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ EdmProperty property = mockProperty("Name");
+
+ Class<?> type = ava.getPropertyType(null, property);
+
+ Assert.assertNull(type);
+ }
+
+
@Test(expected=ODataNotImplementedException.class)
public void getPropertyTypeNotAnnotated() throws ODataException {
AnnotationValueAccess ava = new AnnotationValueAccess();
@@ -138,6 +149,17 @@ public class AnnotationValueAccessTest {
}
@Test
+ public void setPropertyDataNull() throws ODataException {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = null;
+ EdmProperty property = mockProperty("Name");
+
+ ava.setPropertyValue(data, property, null);
+
+ // no exception is thrown, all fine
+ }
+
+ @Test
public void getMappingValue() throws Exception {
AnnotationValueAccess ava = new AnnotationValueAccess();
SimpleEntity data = new SimpleEntity();