Repository: olingo-odata4
Updated Branches:
  refs/heads/master b5ff47837 -> 717d69b97


[]


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

Branch: refs/heads/master
Commit: 717d69b979b418b32a8fe2ae286f399def04efca
Parents: b5ff478
Author: ramya vasanth <[email protected]>
Authored: Thu Sep 14 16:08:38 2017 +0530
Committer: ramya vasanth <[email protected]>
Committed: Thu Sep 14 16:08:38 2017 +0530

----------------------------------------------------------------------
 .../olingo/server/core/uri/UriHelperImpl.java   |  9 ++++--
 .../olingo/server/core/uri/UriHelperTest.java   | 31 ++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/717d69b9/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java
index ee4636b..2c19ade 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriHelperImpl.java
@@ -94,13 +94,14 @@ public class UriHelperImpl implements UriHelper {
         result.append(Encoder.encode(value));
       } catch (final EdmPrimitiveTypeException e) {
         throw new SerializerException("Wrong key value!", e,
-            SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, 
edmProperty.getName(), propertyValue.toString());
+            SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, 
edmProperty.getName(), 
+            propertyValue != null ? propertyValue.toString(): null);
       }
     }
     return result.toString();
   }
   
-  private Object findPropertyRefValue(Entity entity, EdmKeyPropertyRef 
refType) {
+  private Object findPropertyRefValue(Entity entity, EdmKeyPropertyRef 
refType) throws SerializerException {
     final int INDEX_ERROR_CODE = -1;
     final String propertyPath = refType.getName();
     String tmpPropertyName;
@@ -122,6 +123,10 @@ public class UriHelperImpl implements UriHelper {
         tmpPropertyName = propertyPath.substring(lastIndex, index);
         prop = findProperty(tmpPropertyName, prop.asComplex().getValue());
      }
+    if (prop == null) {
+      throw new SerializerException("Key Value Cannot be null for property: " 
+ propertyPath, 
+          SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, propertyPath);
+    }
     return prop.getValue();
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/717d69b9/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriHelperTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriHelperTest.java
 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriHelperTest.java
index e5ed731..8e19835 100644
--- 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriHelperTest.java
+++ 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriHelperTest.java
@@ -18,9 +18,13 @@
  */
 package org.apache.olingo.server.core.uri;
 
+import static org.junit.Assert.assertEquals;
+
 import java.util.Collections;
+import java.util.List;
 
 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.EdmEntityContainer;
@@ -32,7 +36,9 @@ import org.apache.olingo.server.api.uri.UriHelper;
 import org.apache.olingo.server.tecsvc.data.DataProvider;
 import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
 import org.junit.Assert;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 public class UriHelperTest {
 
@@ -78,4 +84,29 @@ public class UriHelperTest {
     entity.getProperty("PropertyInt16").setValue(ValueType.PRIMITIVE, "wrong");
     helper.buildCanonicalURL(entitySet, entity);
   }
+  
+  @Rule
+  public ExpectedException expectedEx = ExpectedException.none(); 
+  
+  @Test(expected = SerializerException.class)
+  public void canonicalURLWithoutKeys() throws Exception {
+    final EdmEntitySet entitySet = container.getEntitySet("ESAllPrim");
+    Entity entity = data.readAll(entitySet).getEntities().get(0);
+    List<Property> properties = entity.getProperties();
+    properties.remove(0);
+    helper.buildCanonicalURL(entitySet, entity);
+    expectedEx.expect(SerializerException.class);
+    expectedEx.expectMessage("Key Value Cannot be null for property: 
PropertyInt16");
+  }
+  
+  @Test(expected = SerializerException.class)
+  public void canonicalURLWithKeyHavingNullValue() throws Exception {
+    final EdmEntitySet entitySet = container.getEntitySet("ESAllPrim");
+    Entity entity = data.readAll(entitySet).getEntities().get(0);
+    Property property = entity.getProperties().get(0);
+    property.setValue(property.getValueType(), null);
+    helper.buildCanonicalURL(entitySet, entity);
+    expectedEx.expect(SerializerException.class);
+    expectedEx.expectMessage("Wrong key value!");
+  }
 }

Reply via email to