Java Code Examples for org.apache.olingo.commons.api.http.HttpHeader#CONTENT_ID
The following examples show how to use
org.apache.olingo.commons.api.http.HttpHeader#CONTENT_ID .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void contentTypeBoundaryCaseInsensitive() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; bOunDaRy=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> batchRequestParts = parse(batch); Assert.assertNotNull(batchRequestParts); Assert.assertEquals(1, batchRequestParts.size()); Assert.assertTrue(batchRequestParts.get(0).isChangeSet()); Assert.assertEquals(1, batchRequestParts.get(0).getRequests().size()); }
Example 2
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void contentTypeCaseInsensitive() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + HttpHeader.CONTENT_LENGTH + ": 200" + CRLF + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; parse(batch); }
Example 3
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void batchBoundaryEqualsChangeSetBoundary() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + ";boundary=" + BOUNDARY + CRLF + CRLF + "--" + BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.PUT + " " + PROPERTY_URI + HTTP_VERSION + CRLF + ACCEPT_HEADER + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + CRLF + "{\"value\":\"MODIFIED\"}" + CRLF + CRLF + "--" + BOUNDARY + "--" + CRLF + "--" + BOUNDARY + "--"; parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_BLANK_LINE); }
Example 4
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void invalidMethodForChangeset() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.GET + " " + PROPERTY_URI + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + "--" + BOUNDARY + "--"; parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CHANGESET_METHOD); }
Example 5
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void invalidChangeSetBoundary() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + ";boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY.substring(0, CHANGESET_BOUNDARY.length() - 1) + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.POST + " ESAllPrim" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> parts = parse(batch); Assert.assertEquals(1, parts.size()); final BatchRequestPart part = parts.get(0); Assert.assertTrue(part.isChangeSet()); Assert.assertEquals(0, part.getRequests().size()); }
Example 6
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void nestedChangeset() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + ";boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + ";boundary=changeset_f980-1cb6-94dd2" + CRLF + CRLF + "--changeset_f980-1cb6-94dd2" + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.POST + " ESAllPrim" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + HttpHeader.CONTENT_ID + ": 2" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.UNEXPECTED_CONTENT_TYPE); }
Example 7
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void missingContentType() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + ";boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF // + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_HTTP + CRLF + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.POST + " ESAllPrim" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + "--" + BOUNDARY + "--"; parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_CONTENT_TYPE); }
Example 8
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void negativeContentLengthRequest() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + HttpHeader.CONTENT_LENGTH + ": -2" + CRLF + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_LENGTH); }
Example 9
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void nonStrictParserMoreCRLF() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + ";boundary=" + CHANGESET_BOUNDARY + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + CRLF // Only one CRLF allowed + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + ACCEPT_HEADER + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + "--" + BOUNDARY + "--"; parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_STATUS_LINE, false); }
Example 10
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@Test public void nonNumericContentLength() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + HttpHeader.CONTENT_LENGTH + ": 10abc" + CRLF + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.INVALID_CONTENT_LENGTH); }
Example 11
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void contentLengthGreatherThanBodyLength() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + HttpHeader.CONTENT_LENGTH + ": 100000" + CRLF + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> batchRequestParts = parse(batch); Assert.assertNotNull(batchRequestParts); Assert.assertEquals(1, batchRequestParts.size()); final BatchRequestPart part = batchRequestParts.get(0); Assert.assertTrue(part.isChangeSet()); Assert.assertEquals(1, part.getRequests().size()); final ODataRequest request = part.getRequests().get(0); Assert.assertEquals("{\"PropertyString\":\"new\"}", IOUtils.toString(request.getBody())); }
Example 12
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void noContentId() throws Exception { final String batch = "--" + BOUNDARY + CRLF + MIME_HEADERS + CRLF + HttpMethod.GET + " ESMedia" + HTTP_VERSION + CRLF + ACCEPT_HEADER + CRLF + CRLF + "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.POST + " ESMedia" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": image/png" + CRLF + "Content-Transfer-Encoding: base64" + CRLF + CRLF + "iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAIAAADtbgqsAAAABmJLR0QA/wD/AP+gvaeTAAAAH0lE" + "QVQokWNgGHmA8S4FmpkosXngNDP+PzdANg+cZgBqiQK5mkdWWgAAAABJRU5ErkJggg==" + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.PUT + " $1/PropertyInt16" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + CRLF + "{\"value\":5}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; parse(batch); }
Example 13
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void contentLengthSmallerThanBodyLength() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.PATCH + " ESAllPrim(32767)" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + HttpHeader.CONTENT_LENGTH + ": 10" + CRLF + CRLF + "{\"PropertyString\":\"new\"}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> batchRequestParts = parse(batch); Assert.assertNotNull(batchRequestParts); Assert.assertEquals(1, batchRequestParts.size()); final BatchRequestPart part = batchRequestParts.get(0); Assert.assertTrue(part.isChangeSet()); Assert.assertEquals(1, part.getRequests().size()); final ODataRequest request = part.getRequests().get(0); Assert.assertEquals("{\"Property", IOUtils.toString(request.getBody())); }
Example 14
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void getRequestMissingCRLF() throws Exception { final String batch = "--" + BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.GET + " " + PROPERTY_URI + HTTP_VERSION + CRLF // + CRLF // Belongs to the GET request + CRLF // Belongs to the boundary + "--" + BOUNDARY + "--"; parseInvalidBatchBody(batch, BatchDeserializerException.MessageKeys.MISSING_BLANK_LINE); }
Example 15
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void postWithoutBody() throws Exception { final String batch = "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": changeRequest1" + CRLF + CRLF + HttpMethod.POST + " ESAllPrim" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_LENGTH + ": 100" + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_OCTET_STREAM + CRLF + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> batchRequestParts = parse(batch); Assert.assertEquals(1, batchRequestParts.size()); Assert.assertTrue(batchRequestParts.get(0).isChangeSet()); Assert.assertEquals(1, batchRequestParts.get(0).getRequests().size()); final ODataRequest request = batchRequestParts.get(0).getRequests().get(0); Assert.assertEquals(HttpMethod.POST, request.getMethod()); Assert.assertEquals("100", request.getHeader(HttpHeader.CONTENT_LENGTH)); Assert.assertEquals(APPLICATION_OCTET_STREAM, request.getHeader(HttpHeader.CONTENT_TYPE)); Assert.assertNotNull(request.getBody()); Assert.assertEquals(-1, request.getBody().read()); }
Example 16
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 5 votes |
@Test public void imageInContent() throws Exception { final String content = IOUtils.toString(readFile("/batchWithContent.batch")); final String batch = "--" + BOUNDARY + CRLF + GET_REQUEST + "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.POST + " ESMedia" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_LENGTH + ": 100000" + CRLF + HttpHeader.CONTENT_TYPE + ": image/jpeg" + CRLF + "Content-Transfer-Encoding: base64" + CRLF + CRLF + content + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> BatchRequestParts = parse(batch); for (final BatchRequestPart part : BatchRequestParts) { Assert.assertEquals(1, part.getRequests().size()); final ODataRequest request = part.getRequests().get(0); if (!part.isChangeSet()) { Assert.assertEquals(HttpMethod.GET, request.getMethod()); Assert.assertEquals(SERVICE_ROOT + "/" + PROPERTY_URI, request.getRawRequestUri()); Assert.assertEquals(SERVICE_ROOT, request.getRawBaseUri()); Assert.assertEquals("/" + PROPERTY_URI, request.getRawODataPath()); } else { Assert.assertEquals(HttpMethod.POST, request.getMethod()); Assert.assertEquals("100000", request.getHeader(HttpHeader.CONTENT_LENGTH)); Assert.assertEquals("1", request.getHeader(HttpHeader.CONTENT_ID)); Assert.assertEquals("image/jpeg", request.getHeader(HttpHeader.CONTENT_TYPE)); Assert.assertEquals(content, IOUtils.toString(request.getBody())); } } }
Example 17
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Test public void epilog() throws Exception { String batch = "--" + BOUNDARY + CRLF + GET_REQUEST + "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.POST + " ESMedia" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": image/png" + CRLF + "Content-Transfer-Encoding: base64" + CRLF + CRLF + "iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAIAAADtbgqsAAAABmJLR0QA/wD/AP+gvaeTAAAAH0lE" + "QVQokWNgGHmA8S4FmpkosXngNDP+PzdANg+cZgBqiQK5mkdWWgAAAABJRU5ErkJggg==" + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 2" + CRLF + CRLF + HttpMethod.PUT + " $1/PropertyInt16" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + CRLF + "{\"value\":5}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "This is an epilog and must be ignored" + CRLF + CRLF + CRLF + "----1242" + CRLF + "--" + BOUNDARY + "--" + CRLF + "This is an epilog and must be ignored" + CRLF + CRLF + CRLF + "----1242"; final List<BatchRequestPart> batchRequestParts = parse(batch); Assert.assertNotNull(batchRequestParts); Assert.assertEquals(2, batchRequestParts.size()); BatchRequestPart getRequestPart = batchRequestParts.get(0); Assert.assertEquals(1, getRequestPart.getRequests().size()); ODataRequest getRequest = getRequestPart.getRequests().get(0); Assert.assertEquals(HttpMethod.GET, getRequest.getMethod()); BatchRequestPart changeSetPart = batchRequestParts.get(1); Assert.assertEquals(2, changeSetPart.getRequests().size()); Assert.assertEquals("iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAIAAADtbgqsAAAABmJLR0QA/wD/AP+gvaeTAAAAH0lE" + "QVQokWNgGHmA8S4FmpkosXngNDP+PzdANg+cZgBqiQK5mkdWWgAAAABJRU5ErkJggg==" + CRLF, IOUtils.toString(changeSetPart.getRequests().get(0).getBody())); Assert.assertEquals("{\"value\":5}", IOUtils.toString(changeSetPart.getRequests().get(1).getBody())); }
Example 18
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Test public void basic() throws Exception { final String batch = "--" + BOUNDARY + CRLF + MIME_HEADERS + CRLF + HttpMethod.GET + " " + PROPERTY_URI + "?$format=json" + HTTP_VERSION + CRLF + HttpHeader.ACCEPT_LANGUAGE + ":en-US,en;q=0.7,en-GB;q=0.9" + CRLF + CRLF + CRLF + "--" + BOUNDARY +CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": changeRequest1" + CRLF + CRLF + HttpMethod.PUT + " " + PROPERTY_URI + HTTP_VERSION + CRLF + HttpHeader.CONTENT_LENGTH + ": 100000" + CRLF + ACCEPT_HEADER + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + CRLF + "{\"value\":\"€ MODIFIED\"}" + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + CRLF + MIME_HEADERS + CRLF + HttpMethod.GET + " " + PROPERTY_URI + "?$format=json" + HTTP_VERSION + CRLF + CRLF + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> batchRequestParts = parse(batch); Assert.assertNotNull(batchRequestParts); Assert.assertFalse(batchRequestParts.isEmpty()); for (final BatchRequestPart object : batchRequestParts) { Assert.assertEquals(1, object.getRequests().size()); final ODataRequest request = object.getRequests().get(0); Assert.assertEquals(SERVICE_ROOT, request.getRawBaseUri()); Assert.assertEquals("/" + PROPERTY_URI, request.getRawODataPath()); if (!object.isChangeSet()) { Assert.assertEquals(HttpMethod.GET, request.getMethod()); if (request.getHeaders(HttpHeader.ACCEPT_LANGUAGE) != null) { Assert.assertEquals(3, request.getHeaders(HttpHeader.ACCEPT_LANGUAGE).size()); } Assert.assertEquals(SERVICE_ROOT + "/" + PROPERTY_URI + "?$format=json", request.getRawRequestUri()); Assert.assertEquals("$format=json", request.getRawQueryPath()); } else { Assert.assertEquals(HttpMethod.PUT, request.getMethod()); Assert.assertEquals("100000", request.getHeader(HttpHeader.CONTENT_LENGTH)); Assert.assertEquals(APPLICATION_JSON, request.getHeader(HttpHeader.CONTENT_TYPE)); final List<String> acceptHeader = request.getHeaders(HttpHeader.ACCEPT); Assert.assertEquals(4, request.getHeaders(HttpHeader.ACCEPT).size()); Assert.assertEquals("application/atom+xml;q=0.8", acceptHeader.get(2)); Assert.assertEquals("*/*;q=0.1", acceptHeader.get(3)); Assert.assertEquals(SERVICE_ROOT + "/" + PROPERTY_URI, request.getRawRequestUri()); Assert.assertEquals("", request.getRawQueryPath()); // No query parameter Assert.assertEquals("{\"value\":\"€ MODIFIED\"}" + CRLF, IOUtils.toString(request.getBody())); } } }
Example 19
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Test public void contentId() throws Exception { final String batch = "--" + BOUNDARY + CRLF + MIME_HEADERS + CRLF + HttpMethod.GET + " ESAllPrim" + HTTP_VERSION + CRLF + ACCEPT_HEADER + HttpHeader.CONTENT_ID + ": BBB" + CRLF + CRLF + CRLF + "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.POST + " ESMedia" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": image/png" + CRLF + "Content-Transfer-Encoding: base64" + CRLF + CRLF + "iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAIAAADtbgqsAAAABmJLR0QA/wD/AP+gvaeTAAAAH0lE" + "QVQokWNgGHmA8S4FmpkosXngNDP+PzdANg+cZgBqiQK5mkdWWgAAAABJRU5ErkJggg==" + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + CRLF + HttpMethod.PUT + " $1/PropertyInt16" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + HttpHeader.CONTENT_ID + ": 2" + CRLF + CRLF + "{\"value\":5}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> batchRequestParts = parse(batch); Assert.assertNotNull(batchRequestParts); for (BatchRequestPart multipart : batchRequestParts) { if (!multipart.isChangeSet()) { Assert.assertEquals(1, multipart.getRequests().size()); Assert.assertEquals("BBB", multipart.getRequests().get(0).getHeader(HttpHeader.CONTENT_ID)); } else { for (ODataRequest request : multipart.getRequests()) { if (HttpMethod.POST.equals(request.getMethod())) { Assert.assertEquals("1", request.getHeader(HttpHeader.CONTENT_ID)); } else if (HttpMethod.PUT.equals(request.getMethod())) { Assert.assertEquals("2", request.getHeader(HttpHeader.CONTENT_ID)); Assert.assertEquals("/$1/PropertyInt16", request.getRawODataPath()); Assert.assertEquals(SERVICE_ROOT + "/$1/PropertyInt16", request.getRawRequestUri()); } } } } }
Example 20
Source File: BatchRequestParserTest.java From olingo-odata4 with Apache License 2.0 | 4 votes |
@Test public void preamble() throws Exception { final String batch = "This is a preamble and must be ignored" + CRLF + CRLF + CRLF + "----1242" + CRLF + "--" + BOUNDARY + CRLF + MIME_HEADERS + CRLF + HttpMethod.GET + " ESAllPrim" + HTTP_VERSION + CRLF + ACCEPT_HEADER + CRLF + CRLF + "--" + BOUNDARY + CRLF + HttpHeader.CONTENT_TYPE + ": " + MULTIPART_MIXED + "; boundary=" + CHANGESET_BOUNDARY + CRLF + CRLF + "This is a preamble and must be ignored" + CRLF + CRLF + CRLF + "----1242" + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 1" + CRLF + CRLF + HttpMethod.POST + " ESMedia" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": image/png" + CRLF + "Content-Transfer-Encoding: base64" + CRLF + CRLF + "iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAIAAADtbgqsAAAABmJLR0QA/wD/AP+gvaeTAAAAH0lE" + "QVQokWNgGHmA8S4FmpkosXngNDP+PzdANg+cZgBqiQK5mkdWWgAAAABJRU5ErkJggg==" + CRLF + CRLF + "--" + CHANGESET_BOUNDARY + CRLF + MIME_HEADERS + HttpHeader.CONTENT_ID + ": 2" + CRLF + CRLF + HttpMethod.PUT + " $1/PropertyInt16" + HTTP_VERSION + CRLF + HttpHeader.CONTENT_TYPE + ": " + APPLICATION_JSON + CRLF + CRLF + "{\"value\":5}" + CRLF + "--" + CHANGESET_BOUNDARY + "--" + CRLF + CRLF + "--" + BOUNDARY + "--"; final List<BatchRequestPart> batchRequestParts = parse(batch); Assert.assertNotNull(batchRequestParts); Assert.assertEquals(2, batchRequestParts.size()); final BatchRequestPart getRequestPart = batchRequestParts.get(0); Assert.assertEquals(1, getRequestPart.getRequests().size()); final ODataRequest getRequest = getRequestPart.getRequests().get(0); Assert.assertEquals(HttpMethod.GET, getRequest.getMethod()); final BatchRequestPart changeSetPart = batchRequestParts.get(1); Assert.assertEquals(2, changeSetPart.getRequests().size()); Assert.assertEquals("iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAIAAADtbgqsAAAABmJLR0QA/wD/AP+gvaeTAAAAH0lE" + "QVQokWNgGHmA8S4FmpkosXngNDP+PzdANg+cZgBqiQK5mkdWWgAAAABJRU5ErkJggg==" + CRLF, IOUtils.toString(changeSetPart.getRequests().get(0).getBody())); Assert.assertEquals("{\"value\":5}", IOUtils.toString(changeSetPart.getRequests().get(1).getBody())); }