Repository: olingo-odata4
Updated Branches:
  refs/heads/master 66ea810b0 -> ce076387c


[OLINGO-1132]Type information is lost when primitive properties with null value 
is updated


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/ce076387
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/ce076387
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/ce076387

Branch: refs/heads/master
Commit: ce076387c38b14a35b9824cc26a3e0e806c7e6ae
Parents: 66ea810
Author: ramya vasanth <ramya.vasa...@sap.com>
Authored: Thu Jun 8 17:40:55 2017 +0530
Committer: ramya vasanth <ramya.vasa...@sap.com>
Committed: Thu Jun 8 17:40:55 2017 +0530

----------------------------------------------------------------------
 .../fit/tecsvc/client/AsyncSupportITCase.java   |   2 +-
 .../olingo/fit/tecsvc/client/BasicITCase.java   |   8 +-
 .../client/core/domain/ClientValuableImpl.java  |   2 +-
 .../apache/olingo/client/core/EntityTest.java   |  20 ++++
 .../apache/olingo/client/core/ESTwoKeyNav.json  | 105 +++++++++++++++++++
 5 files changed, 131 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ce076387/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java
index 68098e6..2263e9b 100644
--- 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java
+++ 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java
@@ -211,7 +211,7 @@ public final class AsyncSupportITCase extends 
AbstractParamTecSvcITCase {
     assertShortOrInt(42, property1.getPrimitiveValue().toValue());
     final ClientProperty property2 = 
createdEntity.getProperty("PropertyDecimal");
     assertNotNull(property2);
-    assertNull(property2.getPrimitiveValue());
+    assertNull(property2.getPrimitiveValue().toValue());
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ce076387/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
index 3d33ee9..c07a6cf 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
@@ -412,7 +412,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
         property2.getPrimitiveValue().toValue());
     final ClientProperty property3 = entity.getProperty(PROPERTY_INT64);
     assertNotNull(property3);
-    assertNull(property3.getPrimitiveValue());
+    assertNull(property3.getPrimitiveValue().toValue());
     final ClientProperty property4 = entity.getProperty("PropertyDuration");
     assertNotNull(property4);
     assertEquals(isJson() ? "PT6S" : BigDecimal.valueOf(6), 
property4.getPrimitiveValue().toValue());
@@ -439,7 +439,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
     assertShortOrInt(42, property1.getPrimitiveValue().toValue());
     final ClientProperty property2 = entity.getProperty(PROPERTY_DECIMAL);
     assertNotNull(property2);
-    assertNull(property2.getPrimitiveValue());
+    assertNull(property2.getPrimitiveValue().toValue());
   }
 
   @Test
@@ -504,7 +504,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
     assertNotNull(complex);
     final ClientProperty property = complex.get(PROPERTY_INT16);
     assertNotNull(property);
-    assertNull(property.getPrimitiveValue());
+    assertNull(property.getPrimitiveValue().toValue());
   }
 
   @Test
@@ -534,7 +534,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
     assertShortOrInt(42, property1.getPrimitiveValue().toValue());
     final ClientProperty property2 = 
createdEntity.getProperty(PROPERTY_DECIMAL);
     assertNotNull(property2);
-    assertNull(property2.getPrimitiveValue());
+    assertNull(property2.getPrimitiveValue().toValue());
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ce076387/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ClientValuableImpl.java
----------------------------------------------------------------------
diff --git 
a/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ClientValuableImpl.java
 
b/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ClientValuableImpl.java
index 4b94be6..d2f1a3a 100644
--- 
a/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ClientValuableImpl.java
+++ 
b/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/ClientValuableImpl.java
@@ -45,7 +45,7 @@ public class ClientValuableImpl implements ClientValuable {
 
   @Override
   public boolean hasPrimitiveValue() {
-    return !hasNullValue() && value.isPrimitive();
+    return value != null && value.isPrimitive();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ce076387/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java
----------------------------------------------------------------------
diff --git 
a/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java 
b/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java
index 0d075a9..b3f1b5e 100644
--- 
a/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java
+++ 
b/lib/client-core/src/test/java/org/apache/olingo/client/core/EntityTest.java
@@ -21,6 +21,7 @@ package org.apache.olingo.client.core;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.InputStream;
@@ -40,6 +41,8 @@ import org.apache.olingo.client.api.domain.ClientProperty;
 import org.apache.olingo.client.api.domain.ClientValuable;
 import org.apache.olingo.client.api.domain.ClientValue;
 import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.Property;
+import org.apache.olingo.commons.api.data.ValueType;
 import org.apache.olingo.commons.api.edm.Edm;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
 import org.apache.olingo.commons.api.format.ContentType;
@@ -381,4 +384,21 @@ public class EntityTest extends AbstractTest {
   public void derivedFromFullJSON() throws Exception {
     derived(client, ContentType.JSON_FULL_METADATA);
   }
+  
+  @Test
+  public void testNullValuesForPrimitiveTypes() throws Exception {
+    final InputStream input = 
getClass().getResourceAsStream("ESTwoKeyNav.json");
+    final ClientEntity entity = client.getBinder().getODataEntity(
+        client.getDeserializer(ContentType.APPLICATION_JSON).toEntity(input));
+    assertNotNull(entity);
+
+    Entity entity1 = client.getBinder().getEntity(entity);
+    assertNotNull(entity1);
+    Property property = 
entity1.getProperty("PropertyComp").asComplex().getValue().
+        get(1).asComplex().getValue().get(2);
+    assertEquals(property.getType(), "Edm.Boolean");
+    assertNull(property.getValue());
+    assertTrue(property.isPrimitive());
+    assertEquals(property.getValueType(), ValueType.PRIMITIVE);
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ce076387/lib/client-core/src/test/resources/org/apache/olingo/client/core/ESTwoKeyNav.json
----------------------------------------------------------------------
diff --git 
a/lib/client-core/src/test/resources/org/apache/olingo/client/core/ESTwoKeyNav.json
 
b/lib/client-core/src/test/resources/org/apache/olingo/client/core/ESTwoKeyNav.json
new file mode 100644
index 0000000..cc38bf9
--- /dev/null
+++ 
b/lib/client-core/src/test/resources/org/apache/olingo/client/core/ESTwoKeyNav.json
@@ -0,0 +1,105 @@
+{
+  "@odata.context": "$metadata#ESTwoKeyNav/$entity",
+  "@odata.metadataEtag": "W/\"10fc9ac1-4eec-4bfa-b678-45f606e48601\"",
+  "@odata.type": "#olingo.odata.test1.ETTwoKeyNav",
+  "@odata.id": "ESTwoKeyNav(PropertyInt16=1,PropertyString='1')",
+  "propertyin...@odata.type": "#Int16",
+  "PropertyInt16": 1,
+  "PropertyString": "1",
+  "PropertyComp": {
+    "@odata.type": "#olingo.odata.test1.CTPrimComp",
+    "propertyin...@odata.type": "#Int16",
+    "PropertyInt16": 11,
+    "PropertyComp": {
+      "@odata.type": "#olingo.odata.test1.CTAllPrim",
+      "PropertyString": "StringValue",
+      "propertybin...@odata.type": "#Binary",
+      "PropertyBinary": "ASNFZ4mrze8=",
+      "propertybool...@odata.type": "#Boolean",
+      "PropertyBoolean": null,
+      "propertyb...@odata.type": "#Byte",
+      "PropertyByte": 255,
+      "propertyd...@odata.type": "#Date",
+      "PropertyDate": "2012-12-03",
+      "propertydatetimeoff...@odata.type": "#DateTimeOffset",
+      "PropertyDateTimeOffset": null,
+      "propertydeci...@odata.type": "#Decimal",
+      "PropertyDecimal": null,
+      "propertysin...@odata.type": "#Single",
+      "PropertySingle": 179000,
+      "PropertyDouble": -1790000,
+      "propertydurat...@odata.type": "#Duration",
+      "PropertyDuration": "PT6S",
+      "propertyg...@odata.type": "#Guid",
+      "PropertyGuid": "01234567-89ab-cdef-0123-456789abcdef",
+      "propertyin...@odata.type": "#Int16",
+      "PropertyInt16": 32767,
+      "propertyin...@odata.type": "#Int32",
+      "PropertyInt32": 2147483647,
+      "propertyin...@odata.type": "#Int64",
+      "PropertyInt64": 92233775807,
+      "propertysb...@odata.type": "#SByte",
+      "PropertySByte": 127,
+      "propertytimeof...@odata.type": "#TimeOfDay",
+      "PropertyTimeOfDay": "21:05:59"
+    }
+  },
+  "PropertyCompNav": {
+    "@odata.type": "#olingo.odata.test1.CTBasePrimCompNav",
+    "propertyin...@odata.type": "#Int16",
+    "PropertyInt16": 1,
+    "PropertyComp": {
+      "@odata.type": "#olingo.odata.test1.CTAllPrim",
+      "PropertyString": "First Resource - positive values",
+      "propertybin...@odata.type": "#Binary",
+      "PropertyBinary": "ASNFZ4mrze8=",
+      "PropertyBoolean": true,
+      "propertyb...@odata.type": "#Byte",
+      "PropertyByte": 255,
+      "propertyd...@odata.type": "#Date",
+      "PropertyDate": "2012-12-03",
+      "propertydatetimeoff...@odata.type": "#DateTimeOffset",
+      "PropertyDateTimeOffset": "2012-12-03T07:16:23Z",
+      "propertydeci...@odata.type": "#Decimal",
+      "PropertyDecimal": 34,
+      "propertysin...@odata.type": "#Single",
+      "PropertySingle": 170000000,
+      "PropertyDouble": -179000000,
+      "propertydurat...@odata.type": "#Duration",
+      "PropertyDuration": "PT6S",
+      "propertyg...@odata.type": "#Guid",
+      "PropertyGuid": "01234567-89ab-cdef-0123-456789abcdef",
+      "propertyin...@odata.type": "#Int16",
+      "PropertyInt16": 32767,
+      "propertyin...@odata.type": "#Int32",
+      "PropertyInt32": 2147483647,
+      "propertyin...@odata.type": "#Int64",
+      "PropertyInt64": 92233725807,
+      "propertysb...@odata.type": "#SByte",
+      "PropertySByte": 127,
+      "propertytimeof...@odata.type": "#TimeOfDay",
+      "PropertyTimeOfDay": "21:05:59"
+    }
+  },
+  "collpropertyc...@odata.type": "#Collection(olingo.odata.test1.CTPrimComp)",
+  "CollPropertyComp": [],
+  "collpropertycomp...@odata.type": 
"#Collection(olingo.odata.test1.CTNavFiveProp)",
+  "CollPropertyCompNav": [
+    {
+      "@odata.type": "#olingo.odata.test1.CTNavFiveProp",
+      "propertyin...@odata.type": "#Int16",
+      "PropertyInt16": 1
+    }
+  ],
+  "collpropertystr...@odata.type": "#Collection(String)",
+  "CollPropertyString": [
+    "1",
+    "2"
+  ],
+  "PropertyCompTwoPrim": {
+    "@odata.type": "#olingo.odata.test1.CTTwoPrim",
+    "propertyin...@odata.type": "#Int16",
+    "PropertyInt16": 11,
+    "PropertyString": "11"
+  }
+}
\ No newline at end of file

Reply via email to