You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/11/18 16:12:14 UTC

[13/22] olingo-odata4 git commit: Test added to MockedBatchHandlerTest

Test added to MockedBatchHandlerTest

Signed-off-by: Christian Amend <ch...@apache.org>


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

Branch: refs/heads/master
Commit: bc46b5352e9cb9dae3e46478dab34287e2ea62bc
Parents: 4ff5fb9
Author: Christian Holzer <c....@sap.com>
Authored: Tue Nov 11 16:17:51 2014 +0100
Committer: Christian Amend <ch...@apache.org>
Committed: Thu Nov 13 17:11:01 2014 +0100

----------------------------------------------------------------------
 .../batch/handler/MockedBatchHandlerTest.java   | 84 +++++++++++++++-----
 1 file changed, 63 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bc46b535/lib/server-core/src/test/java/org/apache/olingo/server/core/batch/handler/MockedBatchHandlerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/batch/handler/MockedBatchHandlerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/batch/handler/MockedBatchHandlerTest.java
index 7a85ffa..b81edb8 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/batch/handler/MockedBatchHandlerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/batch/handler/MockedBatchHandlerTest.java
@@ -200,6 +200,46 @@ public class MockedBatchHandlerTest {
   }
 
   @Test
+  public void testGetRequest() throws BatchException, IOException {
+    final String content = ""
+        + "--batch_12345" + CRLF
+        + "Content-Type: application/http" + CRLF
+        + "Content-Transfer-Encoding: binary" + CRLF
+        + CRLF
+        + "GET ESAllPrim(0) HTTP/1.1" + CRLF
+        + CRLF
+        + CRLF
+        + "--batch_12345--";
+
+    final Map<String, List<String>> header = getMimeHeader();
+    final ODataResponse response = new ODataResponse();
+    final ODataRequest request = buildODataRequest(content, header);
+
+    batchHandler.process(request, response, true);
+
+    BufferedReaderIncludingLineEndings reader =
+        new BufferedReaderIncludingLineEndings(new InputStreamReader(response.getContent()));
+
+    final List<String> responseContent = reader.toList();
+    int line = 0;
+
+    assertEquals(9, responseContent.size());
+    assertTrue(responseContent.get(line++).contains("--batch_"));
+    assertEquals("Content-Type: application/http" + CRLF, responseContent.get(line++));
+    assertEquals("Content-Transfer-Encoding: binary" + CRLF, responseContent.get(line++));
+    assertEquals(CRLF, responseContent.get(line++));
+    assertEquals("HTTP/1.1 200 OK" + CRLF, responseContent.get(line++));
+    assertEquals("Content-Length: 0" + CRLF, responseContent.get(line++));
+    assertEquals(CRLF, responseContent.get(line++));
+    assertEquals(CRLF, responseContent.get(line++));
+    assertTrue(responseContent.get(line++).contains("--batch_"));
+
+    assertEquals(9, line);
+
+    reader.close();
+  }
+
+  @Test
   public void testMultipleChangeSets() throws BatchException, IOException {
     final String content = ""
         + "--batch_12345" + CRLF
@@ -442,8 +482,8 @@ public class MockedBatchHandlerTest {
 
     return contentId;
   }
-  
-  @Test(expected=BatchException.class)
+
+  @Test(expected = BatchException.class)
   public void testInvalidMethod() throws UnsupportedEncodingException, BatchException {
     final String content = ""
         + "--batch_12345" + CRLF
@@ -454,23 +494,23 @@ public class MockedBatchHandlerTest {
         + "Content-Transfer-Encoding: binary" + CRLF
         + "Content-Id: 1" + CRLF
         + CRLF
-        + "PUT ESAllPrim(1) HTTP/1.1" + CRLF 
+        + "PUT ESAllPrim(1) HTTP/1.1" + CRLF
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
         + "--changeset_12345--" + CRLF
         + CRLF
         + "--batch_12345--";
-    
+
     final Map<String, List<String>> header = getMimeHeader();
     final ODataResponse response = new ODataResponse();
     final ODataRequest request = buildODataRequest(content, header);
     request.setMethod(HttpMethod.GET);
-    
+
     batchHandler.process(request, response, true);
   }
-  
-  @Test(expected=BatchException.class)
+
+  @Test(expected = BatchException.class)
   public void testInvalidContentType() throws UnsupportedEncodingException, BatchException {
     final String content = ""
         + "--batch_12345" + CRLF
@@ -481,22 +521,22 @@ public class MockedBatchHandlerTest {
         + "Content-Transfer-Encoding: binary" + CRLF
         + "Content-Id: 1" + CRLF
         + CRLF
-        + "PUT ESAllPrim(1) HTTP/1.1" + CRLF 
+        + "PUT ESAllPrim(1) HTTP/1.1" + CRLF
         + "Content-Type: application/json;odata=verbose" + CRLF
         + CRLF
         + CRLF
         + "--changeset_12345--" + CRLF
         + CRLF
         + "--batch_12345--";
-    
+
     final Map<String, List<String>> header = new HashMap<String, List<String>>();
     header.put(HttpHeader.CONTENT_TYPE, Arrays.asList(new String[] { "application/http" }));
     final ODataResponse response = new ODataResponse();
     final ODataRequest request = buildODataRequest(content, header);
-    
+
     batchHandler.process(request, response, true);
   }
-  
+
   /*
    * Helper methods
    */
@@ -540,16 +580,6 @@ public class MockedBatchHandlerTest {
       List<ODataResponse> responses = new ArrayList<ODataResponse>();
 
       for (ODataRequest request : requests) {
-        // Mock the processor for a given requests
-        when(oDataHandler.process(request)).then(new Answer<ODataResponse>() {
-          @Override
-          public ODataResponse answer(InvocationOnMock invocation) throws Throwable {
-            Object[] arguments = invocation.getArguments();
-
-            return buildResponse((ODataRequest) arguments[0]);
-          }
-        });
-
         try {
           responses.add(operation.handleODataRequest(request, requestPart));
         } catch (BatchException e) {
@@ -567,6 +597,18 @@ public class MockedBatchHandlerTest {
         final List<ODataResponsePart> responseParts = new ArrayList<ODataResponsePart>();
 
         for (BatchRequestPart part : parts) {
+          for (final ODataRequest oDataRequest : part.getRequests()) {
+            // Mock the processor for a given requests
+            when(oDataHandler.process(oDataRequest)).then(new Answer<ODataResponse>() {
+              @Override
+              public ODataResponse answer(InvocationOnMock invocation) throws Throwable {
+                Object[] arguments = invocation.getArguments();
+
+                return buildResponse((ODataRequest) arguments[0]);
+              }
+            });
+          }
+
           responseParts.add(operation.handleBatchRequest(part));
         }