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/07/25 17:12:05 UTC

git commit: [OLINGO-379] Assert that unit test issue lies within file and not implementation

Repository: olingo-odata2
Updated Branches:
  refs/heads/master f1b9134c6 -> 3c6d937de


[OLINGO-379] Assert that unit test issue lies within file and not
implementation


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

Branch: refs/heads/master
Commit: 3c6d937decf632039c14fc6e08b9e59c331edbb4
Parents: f1b9134
Author: Christian Amend <ch...@apache.org>
Authored: Fri Jul 25 17:11:00 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Fri Jul 25 17:11:00 2014 +0200

----------------------------------------------------------------------
 .../odata2/core/batch/BatchResponseParser.java  | 29 ++------------------
 .../core/batch/BatchResponseParserTest.java     | 21 ++++++++++++--
 2 files changed, 21 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3c6d937d/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseParser.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseParser.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseParser.java
index e44e2e6..239311b 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseParser.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/batch/BatchResponseParser.java
@@ -201,9 +201,9 @@ public class BatchResponseParser {
       parseNewLine(scanner);
       String body = parseBody(scanner);
       String contentLengthHeader = getHeaderValue(headers, HttpHeaders.CONTENT_LENGTH);
-      if(contentLengthHeader != null){
+      if (contentLengthHeader != null) {
         int contentLength = Integer.parseInt(contentLengthHeader);
-        if(contentLength < body.length()){
+        if (contentLength < body.length()) {
           body = body.substring(0, contentLength);
         }
       }
@@ -295,31 +295,6 @@ public class BatchResponseParser {
     return responseBody;
   }
 
-  private String parseBody(final Scanner scanner, final int contentLength) {
-    StringBuilder body = null;
-    int length = 0;
-    while (scanner.hasNext() && length < contentLength) {
-      if (!scanner.hasNext(REG_EX_ZERO_OR_MORE_WHITESPACES)) {
-        String nextLine = scanner.next();
-        length += BatchHelper.getBytes(nextLine).length;
-        if (body == null) {
-          body = new StringBuilder(nextLine);
-        } else {
-          body.append(CRLF).append(nextLine);
-        }
-      } else {
-        scanner.next();
-      }
-      currentLineNumber++;
-      if (scanner.hasNext() && scanner.hasNext(REG_EX_BLANK_LINE)) {
-        scanner.next();
-        currentLineNumber++;
-      }
-    }
-    String responseBody = body != null ? body.toString() : null;
-    return responseBody;
-  }
-
   private String getBoundary(final String contentType) throws BatchException {
     Scanner contentTypeScanner = new Scanner(contentType);
     contentTypeScanner.useDelimiter(";\\s?");

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/3c6d937d/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
index 87d8cac..23e4cf3 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
@@ -19,6 +19,7 @@
 package org.apache.olingo.odata2.core.batch;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -285,9 +286,11 @@ public class BatchResponseParserTest {
 
   @Test
   public void parseWithAdditionalLineEndingAtTheEnd() throws Exception {
-    InputStream stream = getFileAsStream("BatchResponseWithAdditionalLineEnding.batch");
+    String fileString = readFile("BatchResponseWithAdditionalLineEnding.batch");
+    assertTrue(fileString.contains("\r\n--batch_123--"));
+    InputStream stream =new ByteArrayInputStream(fileString.getBytes());
     BatchSingleResponse response =
-        EntityProvider.parseBatchResponse(stream, "multipart/mixed;boundary=batch_123").get(0);
+        EntityProvider.parseBatchResponse(stream , "multipart/mixed;boundary=batch_123").get(0);
     assertEquals("This is the body we need to parse. The trailing line ending is part of the body." + CRLF, response
         .getBody());
 
@@ -330,6 +333,20 @@ public class BatchResponseParserTest {
     assertEquals(body, response.getBody());
   }
 
+  protected String readFile(final String filename) throws IOException {
+    InputStream in = getFileAsStream(filename);
+
+    byte[] tmp = new byte[8192];
+    int count = in.read(tmp);
+    StringBuilder b = new StringBuilder();
+    while (count >= 0) {
+      b.append(new String(tmp, 0, count));
+      count = in.read(tmp);
+    }
+
+    return b.toString();
+  }
+  
   private InputStream getFileAsStream(final String filename) throws IOException {
     InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
     if (in == null) {