This is an automated email from the ASF dual-hosted git repository.

mibo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git

commit 5cf7e1c0c67b01d03e53f8e46f77b8a4c26ada8d
Author: jzhao <[email protected]>
AuthorDate: Wed Nov 27 15:38:27 2019 +0800

    [OLINGO-1114] Fix NULL PrimitiveValue change the type when convert (#21)
    
    ClientEntity to a HttpEntity
---
 .../org/apache/olingo/client/core/JSONTest.java    | 70 ++++++++++++++++++++++
 .../org/apache/olingo/client/core/olingo1114.json  | 17 ++++++
 2 files changed, 87 insertions(+)

diff --git 
a/lib/client-core/src/test/java/org/apache/olingo/client/core/JSONTest.java 
b/lib/client-core/src/test/java/org/apache/olingo/client/core/JSONTest.java
index 29a5222..d6af25a 100644
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/JSONTest.java
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/JSONTest.java
@@ -32,6 +32,8 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.util.EntityUtils;
 import org.apache.olingo.client.api.data.ResWrap;
 import org.apache.olingo.client.api.domain.ClientAnnotation;
 import org.apache.olingo.client.api.domain.ClientCollectionValue;
@@ -45,6 +47,7 @@ import org.apache.olingo.client.api.domain.ClientProperty;
 import org.apache.olingo.client.api.domain.ClientValue;
 import org.apache.olingo.client.core.domain.ClientAnnotationImpl;
 import org.apache.olingo.client.core.serialization.JsonDeserializer;
+import org.apache.olingo.client.core.uri.URIUtils;
 import org.apache.olingo.client.core.serialization.JsonSerializer;
 import org.apache.olingo.commons.api.Constants;
 import org.apache.olingo.commons.api.data.ComplexValue;
@@ -907,6 +910,73 @@ public class JSONTest extends AbstractTest {
       i++;
     }
   }
+
+  @Test
+  public void testOLINGO1114() throws Exception {
+    ClientEntity entityIncNullValue = client.getObjectFactory()
+            .newEntity(new FullQualifiedName("Microsoft.Dynamics.CRM", 
"account"));
+    List<ClientProperty> properties = entityIncNullValue.getProperties();
+
+    // Property "name"
+    ClientPrimitiveValue.Builder valueBuilder = 
client.getObjectFactory().newPrimitiveValueBuilder();
+    valueBuilder.setType(EdmPrimitiveTypeKind.String);
+    valueBuilder.setValue("testString");
+    ClientProperty name = 
client.getObjectFactory().newPrimitiveProperty("name", valueBuilder.build());
+    properties.add(name);
+
+    // Property "testDecimal"
+    valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
+    valueBuilder.setType(EdmPrimitiveTypeKind.Decimal);
+    valueBuilder.setValue(null);
+    ClientProperty revenue = 
client.getObjectFactory().newPrimitiveProperty("testDecimal", 
valueBuilder.build());
+    properties.add(revenue);
+
+    // Property "testByte"
+    valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
+    valueBuilder.setType(EdmPrimitiveTypeKind.Byte);
+    valueBuilder.setValue(null);
+    ClientProperty testByte = 
client.getObjectFactory().newPrimitiveProperty("testByte", 
valueBuilder.build());
+    properties.add(testByte);
+
+    // Property "testDouble"
+    valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
+    valueBuilder.setType(EdmPrimitiveTypeKind.Double);
+    valueBuilder.setValue(null);
+    ClientProperty testDouble = 
client.getObjectFactory().newPrimitiveProperty("testDouble", 
valueBuilder.build());
+    properties.add(testDouble);
+
+    // Property "testInt64"
+    valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
+    valueBuilder.setType(EdmPrimitiveTypeKind.Int64);
+    valueBuilder.setValue(null);
+    ClientProperty testInt64 = 
client.getObjectFactory().newPrimitiveProperty("testInt64", 
valueBuilder.build());
+    properties.add(testInt64);
+
+    // Property "testInt32"
+    valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
+    valueBuilder.setType(EdmPrimitiveTypeKind.Int32);
+    valueBuilder.setValue(null);
+    ClientProperty testInt32 = 
client.getObjectFactory().newPrimitiveProperty("testInt32", 
valueBuilder.build());
+    properties.add(testInt32);
+
+    // Property "testInt16"
+    valueBuilder = client.getObjectFactory().newPrimitiveValueBuilder();
+    valueBuilder.setType(EdmPrimitiveTypeKind.Int16);
+    valueBuilder.setValue(null);
+    ClientProperty testInt16 = 
client.getObjectFactory().newPrimitiveProperty("testInt16", 
valueBuilder.build());
+    properties.add(testInt16);
+
+    InputStream inputStream = 
client.getWriter().writeEntity(entityIncNullValue, ContentType.JSON);
+    HttpEntity httpEntity = URIUtils.buildInputStreamEntity(client, 
inputStream);
+
+    final String actual = EntityUtils.toString(httpEntity);
+    final JsonNode expected =
+            
OBJECT_MAPPER.readTree(IOUtils.toString(getClass().getResourceAsStream("olingo1114.json")).
+                    replace(Constants.JSON_NAVIGATION_LINK, 
Constants.JSON_BIND_LINK_SUFFIX));
+    final ObjectNode actualNode = (ObjectNode) OBJECT_MAPPER.readTree(new 
ByteArrayInputStream(actual.getBytes()));
+    assertEquals(expected, actualNode);
+  }
+
   
   @Test
   public void issueOLINGO1152() throws Exception {
diff --git 
a/lib/client-core/src/test/resources/org/apache/olingo/client/core/olingo1114.json
 
b/lib/client-core/src/test/resources/org/apache/olingo/client/core/olingo1114.json
new file mode 100644
index 0000000..fbf5e0d
--- /dev/null
+++ 
b/lib/client-core/src/test/resources/org/apache/olingo/client/core/olingo1114.json
@@ -0,0 +1,17 @@
+{
+  "@odata.type":"#Microsoft.Dynamics.CRM.account",
+  "[email protected]":"String",
+  "name":"testString",
+  "[email protected]":"Decimal",
+  "testDecimal":null,
+  "[email protected]":"Byte",
+  "testByte":null,
+  "[email protected]":"Double",
+  "testDouble":null,
+  "[email protected]":"Int64",
+  "testInt64":null,
+  "[email protected]":"Int32",
+  "testInt32":null,
+  "[email protected]":"Int16",
+  "testInt16":null
+}
\ No newline at end of file

Reply via email to