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 2015/10/05 08:02:06 UTC

[09/11] olingo-odata4 git commit: [OLINGO-789] server support for action parameters of all types

[OLINGO-789] server support for action parameters of all types

Signed-off-by: Michael Bolz <mi...@sap.com>


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

Branch: refs/heads/olingo786
Commit: d6db341db734266536d5177dcb749eae0683c2c7
Parents: b9403cd
Author: Klaus Straubinger <kl...@sap.com>
Authored: Thu Oct 1 10:20:44 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Oct 1 12:11:33 2015 +0200

----------------------------------------------------------------------
 .../client/AbstractParamTecSvcITCase.java       |  18 +
 .../fit/tecsvc/client/AbstractTecSvcITCase.java |  28 +-
 .../fit/tecsvc/client/ActionImportITCase.java   |  11 +-
 .../fit/tecsvc/client/AsyncSupportITCase.java   |  24 +-
 .../fit/tecsvc/client/DeepInsertITCase.java     | 886 +++++++++--------
 .../fit/tecsvc/client/DeepInsertXmlITCase.java  | 950 -------------------
 .../ExpandWithSystemQueryOptionsITCase.java     |  12 +-
 .../commons/api/edm/EdmNavigationProperty.java  |   2 +-
 .../olingo/commons/api/edm/EdmParameter.java    |   2 +-
 .../olingo/commons/api/edm/EdmProperty.java     |   4 +-
 .../olingo/commons/api/edm/EdmReturnType.java   |   2 +-
 .../apache/olingo/server/core/ODataImpl.java    |   7 +-
 .../json/ODataJsonDeserializer.java             | 389 +++-----
 .../deserializer/xml/ODataXmlDeserializer.java  |  52 +-
 .../core/serializer/xml/ODataXmlSerializer.java |  46 +-
 .../olingo/server/tecsvc/data/ActionData.java   | 101 +-
 .../olingo/server/tecsvc/data/DataProvider.java |  23 +-
 .../tecsvc/data/ActionDataProviderTest.java     |  14 +-
 .../AbstractODataDeserializerTest.java          |  44 +
 .../json/AbstractODataDeserializerTest.java     |  46 -
 .../json/ODataDeserializerDeepInsertTest.java   | 125 +--
 .../ODataDeserializerEntityCollectionTest.java  | 205 ++--
 ...ataJsonDeserializerActionParametersTest.java | 350 +++----
 .../json/ODataJsonDeserializerEntityTest.java   | 678 ++++---------
 ...DataXMLDeserializerActionParametersTest.java | 350 +++----
 .../xml/ODataXmlDeserializerTest.java           | 211 ++--
 .../core/uri/antlr/TestUriParserImpl.java       |  11 +-
 27 files changed, 1549 insertions(+), 3042 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
index 2d45d79..d6e35a3 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
@@ -18,6 +18,11 @@
  */
 package org.apache.olingo.fit.tecsvc.client;
 
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
 import java.util.Arrays;
 import java.util.List;
 
@@ -45,4 +50,17 @@ public abstract class AbstractParamTecSvcITCase extends AbstractTecSvcITCase {
   protected ContentType getContentType() {
     return contentType;
   }
+
+  protected void assertContentType(final String content) {
+    assertThat(content, startsWith(contentType.toContentTypeString()));
+  }
+
+  protected boolean isJson() {
+    return ContentType.JSON.isCompatible(contentType);
+  }
+
+  protected void assertShortOrInt(final int value, final Object n) {
+    assertTrue(n instanceof Number);
+    assertEquals(value, ((Number) n).intValue());
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractTecSvcITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractTecSvcITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractTecSvcITCase.java
index 1333644..c74f345 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractTecSvcITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractTecSvcITCase.java
@@ -18,11 +18,6 @@
  */
 package org.apache.olingo.fit.tecsvc.client;
 
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
 import java.util.Collection;
 
 import org.apache.olingo.client.api.EdmEnabledODataClient;
@@ -61,22 +56,7 @@ public abstract class AbstractTecSvcITCase extends AbstractBaseTestITCase {
     }
   }
 
-  protected void assertShortOrInt(final int value, final Object n) {
-    assertTrue(n instanceof Number);
-    assertEquals(value, ((Number) n).intValue());
-  }
-
-  protected void assertContentType(final String content) {
-    assertThat(content, containsString(getContentType().toContentTypeString()));
-  }
-
-  protected ContentType getContentType() {
-    return ContentType.APPLICATION_JSON;
-  }
-
-  protected boolean isJson() {
-    return ContentType.JSON.isCompatible(getContentType());
-  }
+  protected abstract ContentType getContentType();
 
   @Override
   protected ODataClient getClient() {
@@ -85,12 +65,8 @@ public abstract class AbstractTecSvcITCase extends AbstractBaseTestITCase {
     return odata;
   }
 
-  protected EdmEnabledODataClient getClient(final String serviceRoot) {
-    return ODataClientFactory.getEdmEnabledClient(serviceRoot, getContentType());
-  }
-
   protected EdmEnabledODataClient getEdmEnabledClient() {
-    return getClient(SERVICE_URI);
+    return ODataClientFactory.getEdmEnabledClient(SERVICE_URI, getContentType());
   }
 
   protected ClientObjectFactory getFactory() {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
index b7671cb..c21671b 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
@@ -21,6 +21,7 @@ package org.apache.olingo.fit.tecsvc.client;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
 
 import java.math.BigDecimal;
 import java.net.URI;
@@ -42,13 +43,12 @@ import org.apache.olingo.client.api.domain.ClientInvokeResult;
 import org.apache.olingo.client.api.domain.ClientProperty;
 import org.apache.olingo.client.api.domain.ClientValue;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.commons.api.http.HttpHeader;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.apache.olingo.fit.tecsvc.TecSvcConst;
 import org.junit.Test;
 
-public class ActionImportITCase extends AbstractTecSvcITCase {
+public class ActionImportITCase extends AbstractParamTecSvcITCase {
 
   @Test
   public void noReturnTypeAction() throws Exception {
@@ -293,6 +293,8 @@ public class ActionImportITCase extends AbstractTecSvcITCase {
 
   private <T extends ClientInvokeResult> ODataInvokeResponse<T> callAction(final String name,
       final Class<T> resultRef, final Map<String, ClientValue> parameters, final boolean returnMinimal) {
+    assumeTrue("The client would send wrongly formatted parameters in XML.",
+        parameters == null || parameters.isEmpty() || isJson());  // TODO: XML case
     final URI actionURI = getClient().newURIBuilder(TecSvcConst.BASE_URI).appendActionCallSegment(name).build();
     ODataInvokeRequest<T> request = getClient().getInvokeRequestFactory()
         .getActionInvokeRequest(actionURI, resultRef, parameters);
@@ -309,9 +311,4 @@ public class ActionImportITCase extends AbstractTecSvcITCase {
     }
     return response;
   }
-
-  @Override
-  protected ContentType getContentType() {
-    return ContentType.APPLICATION_JSON;
-  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/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 f447bbc..f6893d1 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
@@ -48,13 +48,12 @@ import org.apache.olingo.client.api.domain.ClientProperty;
 import org.apache.olingo.commons.api.data.Entity;
 import org.apache.olingo.commons.api.data.EntityCollection;
 import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.commons.api.format.PreferenceName;
 import org.apache.olingo.commons.api.http.HttpHeader;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.junit.Test;
 
-public final class AsyncSupportITCase extends AbstractTecSvcITCase {
+public final class AsyncSupportITCase extends AbstractParamTecSvcITCase {
 
   private static final String ES_ALL_PRIM = "ESAllPrim";
   private static final String NAV_PROPERTY_ET_TWO_PRIM_ONE = "NavPropertyETTwoPrimOne";
@@ -70,7 +69,7 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
 
     final ODataRetrieveResponse<ClientEntity> response = client.getRetrieveRequestFactory()
         .getEntityRequest(uri).execute();
-    assertEquals(32767, response.getBody().getProperty("PropertyInt16").getPrimitiveValue().toValue());
+    assertShortOrInt(32767, response.getBody().getProperty("PropertyInt16").getPrimitiveValue().toValue());
     assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
 
     // first async request
@@ -98,9 +97,8 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
     assertNotNull(first.getODataResponse());
     ODataResponse firstResponse = first.getODataResponse();
     assertEquals(HttpStatusCode.OK.getStatusCode(), firstResponse.getStatusCode());
-    ResWrap<Entity> entity = client.getDeserializer(ContentType.APPLICATION_JSON)
-        .toEntity(firstResponse.getRawResponse());
-    assertEquals(32767, entity.getPayload().getProperty("PropertyInt16").asPrimitive());
+    ResWrap<Entity> entity = client.getDeserializer(getContentType()).toEntity(firstResponse.getRawResponse());
+    assertShortOrInt(32767, entity.getPayload().getProperty("PropertyInt16").asPrimitive());
     assertEquals("First Resource - positive values", entity.getPayload().getProperty("PropertyString").asPrimitive());
   }
 
@@ -144,12 +142,12 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
     assertEquals(HttpStatusCode.OK.getStatusCode(), firstResponse.getStatusCode());
     assertEquals(2, firstResponse.getHeaderNames().size());
     assertEquals("4.0", firstResponse.getHeader(HttpHeader.ODATA_VERSION).iterator().next());
-    ResWrap<EntityCollection> firWrap = client.getDeserializer(ContentType.APPLICATION_JSON)
+    ResWrap<EntityCollection> firWrap = client.getDeserializer(getContentType())
         .toEntitySet(firstResponse.getRawResponse());
     EntityCollection firstResponseEntitySet = firWrap.getPayload();
     assertEquals(3, firstResponseEntitySet.getEntities().size());
     Entity firstResponseEntity = firstResponseEntitySet.getEntities().get(0);
-    assertEquals(32767, firstResponseEntity.getProperty("PropertyInt16").asPrimitive());
+    assertShortOrInt(32767, firstResponseEntity.getProperty("PropertyInt16").asPrimitive());
     assertEquals("First Resource - positive values", firstResponseEntity.getProperty("PropertyString").asPrimitive());
   }
 
@@ -190,7 +188,7 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
     assertNotNull(createdEntity);
     final ClientProperty property1 = createdEntity.getProperty("PropertyInt64");
     assertNotNull(property1);
-    assertEquals(42, property1.getPrimitiveValue().toValue());
+    assertShortOrInt(42, property1.getPrimitiveValue().toValue());
     final ClientProperty property2 = createdEntity.getProperty("PropertyDecimal");
     assertNotNull(property2);
     assertNull(property2.getPrimitiveValue());
@@ -220,7 +218,7 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
     assertEquals("4.0", firstResponse.getHeader(HttpHeader.ODATA_VERSION).iterator().next());
 
     final ClientEntity entity = firstResponse.getBody();
-    assertEquals(32767, entity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
+    assertShortOrInt(32767, entity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
     assertEquals("First Resource - positive values",
         entity.getProperty("PropertyString").getPrimitiveValue().toValue());
   }
@@ -266,11 +264,11 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
     return client.getRetrieveRequestFactory().getEntityRequest(uri);
   }
 
-  private void checkEntityAvailableWith(ClientEntitySet entitySet, String property, Object value) {
+  private void checkEntityAvailableWith(ClientEntitySet entitySet, String property, int value) {
     for (ClientEntity entity : entitySet.getEntities()) {
-      ClientProperty ep = entity.getProperty("PropertyInt16");
+      ClientProperty ep = entity.getProperty(property);
       if (ep != null) {
-        assertEquals(value, ep.getPrimitiveValue().toValue());
+        assertShortOrInt(value, ep.getPrimitiveValue().toValue());
         return;
       }
     }