Repository: olingo-odata2 Updated Branches: refs/heads/master 456f4c641 -> ff4ab9956
[OLINGO-1105] JUnits for Custom Query Options in batch Signed-off-by: Christian Amend <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/ff4ab995 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/ff4ab995 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/ff4ab995 Branch: refs/heads/master Commit: ff4ab99569e322e0315b414e2b078d7548a7c0fb Parents: 456f4c6 Author: Archana Rai <[email protected]> Authored: Tue Apr 11 13:53:22 2017 +0530 Committer: Christian Amend <[email protected]> Committed: Wed Apr 12 11:17:15 2017 +0200 ---------------------------------------------------------------------- .../olingo/odata2/fit/basic/BasicBatchTest.java | 92 ++++++++++++++++++++ 1 file changed, 92 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/ff4ab995/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java index 0dfec68..4567501 100644 --- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java +++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/basic/BasicBatchTest.java @@ -181,6 +181,98 @@ public class BasicBatchTest extends AbstractBasicTest { assertTrue(body.contains("Content-Id: requestHeaderContentId1")); assertTrue(body.contains("HTTP/1.1 415 Unsupported Media Type")); } + + /* Tests for Custo Query options.A Custom Query String option is defined + * as any name/value pair query string parameter where the name of the + * parameter does not begin with the "$" character. Any URI exposed by + * an OData service may include one or more Custom Query Options.*/ + + @Test + public void testBatchForCustomQuery() throws Exception { + final HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + + "$batch?language=de")); + post.setHeader("Content-Type", "multipart/mixed;boundary=batch_98c1-8b13-36bb"); + HttpEntity entity = new StringEntity(REQUEST_PAYLOAD); + post.setEntity(entity); + HttpResponse response = getHttpClient().execute(post); + + assertNotNull(response); + assertEquals(202, response.getStatusLine().getStatusCode()); + assertEquals("HTTP/1.1", response.getProtocolVersion().toString()); + assertTrue(response.containsHeader("Content-Length")); + assertTrue(response.containsHeader("Content-Type")); + assertTrue(response.containsHeader("DataServiceVersion")); + assertTrue(response.getEntity().getContentType().getValue().matches(REG_EX)); + assertNotNull(response.getEntity().getContent()); + + String body = StringHelper.inputStreamToString(response.getEntity().getContent(), true); + assertTrue(body.contains("Content-Id: mimeHeaderContentId1")); + assertTrue(body.contains("Content-Id: requestHeaderContentId1")); + assertTrue(body.contains("Content-Id: mimeHeaderContentId2")); + assertTrue(body.contains("Content-Id: requestHeaderContentId2")); + } + + @Test + public void testBatchForCustomQueryFail() throws Exception { + final HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + + "$batch?$language=de")); + post.setHeader("Content-Type", "multipart/mixed;boundary=batch_98c1-8b13-36bb"); + HttpEntity entity = new StringEntity(REQUEST_PAYLOAD); + post.setEntity(entity); + HttpResponse result = getHttpClient().execute(post); + assertEquals(HttpStatusCodes.BAD_REQUEST.getStatusCode(), result.getStatusLine().getStatusCode()); + + } + + @Test + public void testBatchForCustomQuery2() throws Exception { + final HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + + "$batch?@language=de")); + post.setHeader("Content-Type", "multipart/mixed;boundary=batch_98c1-8b13-36bb"); + HttpEntity entity = new StringEntity(REQUEST_PAYLOAD); + post.setEntity(entity); + HttpResponse response = getHttpClient().execute(post); + + assertNotNull(response); + assertEquals(202, response.getStatusLine().getStatusCode()); + assertEquals("HTTP/1.1", response.getProtocolVersion().toString()); + assertTrue(response.containsHeader("Content-Length")); + assertTrue(response.containsHeader("Content-Type")); + assertTrue(response.containsHeader("DataServiceVersion")); + assertTrue(response.getEntity().getContentType().getValue().matches(REG_EX)); + assertNotNull(response.getEntity().getContent()); + + String body = StringHelper.inputStreamToString(response.getEntity().getContent(), true); + assertTrue(body.contains("Content-Id: mimeHeaderContentId1")); + assertTrue(body.contains("Content-Id: requestHeaderContentId1")); + assertTrue(body.contains("Content-Id: mimeHeaderContentId2")); + assertTrue(body.contains("Content-Id: requestHeaderContentId2")); + } + + @Test + public void testBatchForCustomQuery3() throws Exception { + final HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + + "$batch?#language=de")); + post.setHeader("Content-Type", "multipart/mixed;boundary=batch_98c1-8b13-36bb"); + HttpEntity entity = new StringEntity(REQUEST_PAYLOAD); + post.setEntity(entity); + HttpResponse response = getHttpClient().execute(post); + + assertNotNull(response); + assertEquals(202, response.getStatusLine().getStatusCode()); + assertEquals("HTTP/1.1", response.getProtocolVersion().toString()); + assertTrue(response.containsHeader("Content-Length")); + assertTrue(response.containsHeader("Content-Type")); + assertTrue(response.containsHeader("DataServiceVersion")); + assertTrue(response.getEntity().getContentType().getValue().matches(REG_EX)); + assertNotNull(response.getEntity().getContent()); + + String body = StringHelper.inputStreamToString(response.getEntity().getContent(), true); + assertTrue(body.contains("Content-Id: mimeHeaderContentId1")); + assertTrue(body.contains("Content-Id: requestHeaderContentId1")); + assertTrue(body.contains("Content-Id: mimeHeaderContentId2")); + assertTrue(body.contains("Content-Id: requestHeaderContentId2")); + } static class TestSingleProc extends ODataSingleProcessor { @Override
