From bb4b554116382e61519c6f7e98010aaff31eb441 Mon Sep 17 00:00:00 2001 From: Christian Holzer Date: Wed, 5 Nov 2014 16:18:40 +0100 Subject: [PATCH] Tests added Signed-off-by: Christian Amend --- .../batch/handler/BatchChangeSetSorter.java | 7 ++- .../batch/handler/MockedBatchHandlerTest.java | 56 ++++++++++++++++++- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/batch/handler/BatchChangeSetSorter.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/batch/handler/BatchChangeSetSorter.java index 408159eb3..5e1c2762e 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/batch/handler/BatchChangeSetSorter.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/batch/handler/BatchChangeSetSorter.java @@ -99,10 +99,11 @@ public class BatchChangeSetSorter { } private List getRequestsWithoutReferences() { - final List requestsWithoutReference = requestReferenceMapping.get(null); + List requests = requestReferenceMapping.get(null); requestReferenceMapping.remove(null); - - return requestsWithoutReference; + + requests = (requests == null) ? new ArrayList() : requests; + return requests; } private void addRequestsToKnownContentIds(List requestsWithoutReference) { 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 d772fbc6a..e1864e226 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 @@ -442,7 +442,61 @@ public class MockedBatchHandlerTest { return contentId; } - + + @Test(expected=BatchException.class) + public void testInvalidMethod() throws UnsupportedEncodingException, BatchException { + final String content = "" + + "--batch_12345" + CRLF + + "Content-Type: multipart/mixed; boundary=changeset_12345" + CRLF + + CRLF + + "--changeset_12345" + CRLF + + "Content-Type: application/http" + CRLF + + "Content-Transfer-Encoding: binary" + CRLF + + "Content-Id: 1" + CRLF + + 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> 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) + public void testInvalidContentType() throws UnsupportedEncodingException, BatchException { + final String content = "" + + "--batch_12345" + CRLF + + "Content-Type: multipart/mixed; boundary=changeset_12345" + CRLF + + CRLF + + "--changeset_12345" + CRLF + + "Content-Type: application/http" + CRLF + + "Content-Transfer-Encoding: binary" + CRLF + + "Content-Id: 1" + CRLF + + 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> header = new HashMap>(); + 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 */