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/01/14 09:19:22 UTC

olingo-odata4 git commit: [OLINGO-482] Added test case

Repository: olingo-odata4
Updated Branches:
  refs/heads/master 3fd384366 -> ab39763f3


[OLINGO-482] Added test case


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

Branch: refs/heads/master
Commit: ab39763f3e811faf87d6a09e972dd6df0e4723a6
Parents: 3fd3843
Author: Michael Bolz <mi...@sap.com>
Authored: Wed Jan 14 09:14:36 2015 +0100
Committer: Michael Bolz <mi...@sap.com>
Committed: Wed Jan 14 09:14:36 2015 +0100

----------------------------------------------------------------------
 .../olingo/server/core/ODataHandlerTest.java    | 50 +++++++++++++++++---
 1 file changed, 44 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/ab39763f/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
index 72d2956..b62371e 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
@@ -27,9 +27,13 @@ import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
 
 import java.util.Collections;
+import java.util.List;
 import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.olingo.commons.api.ODataException;
@@ -45,6 +49,7 @@ import org.apache.olingo.server.api.OData;
 import org.apache.olingo.server.api.ODataApplicationException;
 import org.apache.olingo.server.api.ODataRequest;
 import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.ODataServerError;
 import org.apache.olingo.server.api.ServiceMetadata;
 import org.apache.olingo.server.api.edm.provider.EdmProvider;
 import org.apache.olingo.server.api.edm.provider.EntitySet;
@@ -63,6 +68,7 @@ import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor;
 import org.apache.olingo.server.api.processor.CountPrimitiveCollectionProcessor;
 import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
 import org.apache.olingo.server.api.processor.EntityProcessor;
+import org.apache.olingo.server.api.processor.ErrorProcessor;
 import org.apache.olingo.server.api.processor.MediaEntityProcessor;
 import org.apache.olingo.server.api.processor.MetadataProcessor;
 import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor;
@@ -618,8 +624,32 @@ public class ODataHandlerTest {
     dispatchMethodNotAllowed(HttpMethod.DELETE, uri, processor);
   }
 
+  @Test
+  public void unsupportedRequestContentType() throws Exception {
+    EntityProcessor processor = mock(EntityProcessor.class);
+    ErrorProcessor errorProcessor = mock(ErrorProcessor.class);
+    dispatch(HttpMethod.POST, "ESAllPrim", "", HttpHeader.CONTENT_TYPE, "some/unsupported", errorProcessor);
+    verifyZeroInteractions(processor);
+    verify(errorProcessor).processError(any(ODataRequest.class), any(ODataResponse.class), any(ODataServerError.class),
+            any(ContentType.class));
+  }
+
   private ODataResponse dispatch(final HttpMethod method, final String path, final String query,
       final String headerName, final String headerValue, final Processor processor) {
+    Map<String, List<String>> headers = null;
+    if(headerName != null) {
+      headers = Collections.singletonMap(headerName, Collections.singletonList(headerValue));
+    }
+    List<Processor> processors = null;
+    if(processor != null) {
+      processors = Collections.singletonList(processor);
+    }
+    return dispatch(method, path, query, headers, processors);
+  }
+
+
+  private ODataResponse dispatch(final HttpMethod method, final String path, final String query,
+      final Map<String, List<String>> headers, final List<Processor> processors) {
     ODataRequest request = new ODataRequest();
     request.setMethod(method);
     request.setRawBaseUri(BASE_URI);
@@ -629,11 +659,17 @@ public class ODataHandlerTest {
     request.setRawODataPath(path);
     request.setRawQueryPath(query);
 
-    if (headerName != null) {
-      request.addHeader(headerName, Collections.singletonList(headerValue));
+    if (headers != null) {
+      Set<Map.Entry<String, List<String>>> headerSet = headers.entrySet();
+      for (Map.Entry<String, List<String>> headerItem : headerSet) {
+        request.addHeader(headerItem.getKey(), headerItem.getValue());
+      }
+    }
+
+    if(request.getHeaders(HttpHeader.CONTENT_TYPE) == null) {
+      request.addHeader(HttpHeader.CONTENT_TYPE, Collections.singletonList(
+              ODataFormat.JSON.getContentType(ODataServiceVersion.V40).toContentTypeString()));
     }
-    request.addHeader(HttpHeader.CONTENT_TYPE, Collections.singletonList(
-        ODataFormat.JSON.getContentType(ODataServiceVersion.V40).toContentTypeString()));
 
     final OData odata = OData.newInstance();
     final ServiceMetadata metadata = odata.createServiceMetadata(
@@ -641,8 +677,10 @@ public class ODataHandlerTest {
 
     ODataHandler handler = new ODataHandler(odata, metadata);
 
-    if (processor != null) {
-      handler.register(processor);
+    if (processors != null && !processors.isEmpty()) {
+      for (Processor p : processors) {
+        handler.register(p);
+      }
     }
 
     final ODataResponse response = handler.process(request);