You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2013/09/24 14:42:32 UTC
[05/51] [partial] Refactored project structure
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterTest.java
deleted file mode 100644
index 1331e73..0000000
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchRequestWriterTest.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.batch;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.batch.BatchException;
-import org.apache.olingo.odata2.api.client.batch.BatchChangeSet;
-import org.apache.olingo.odata2.api.client.batch.BatchChangeSetPart;
-import org.apache.olingo.odata2.api.client.batch.BatchPart;
-import org.apache.olingo.odata2.api.client.batch.BatchQueryPart;
-import org.apache.olingo.odata2.testutil.helper.StringHelper;
-import org.junit.Test;
-
-public class BatchRequestWriterTest {
-
- private static final String POST = "POST";
- private static final String GET = "GET";
- private static final String PUT = "PUT";
- private static final String BOUNDARY = "batch_123";
-
- private void checkMimeHeaders(final String requestBody) {
- assertTrue(requestBody.contains("Content-Type: application/http"));
- assertTrue(requestBody.contains("Content-Transfer-Encoding: binary"));
- }
-
- @Test
- public void testBatchQueryPart() throws BatchException, IOException {
- List<BatchPart> batch = new ArrayList<BatchPart>();
- Map<String, String> headers = new HashMap<String, String>();
- headers.put("Accept", "application/json");
- BatchPart request = BatchQueryPart.method(GET).uri("Employees").headers(headers).build();
- batch.add(request);
-
- BatchRequestWriter writer = new BatchRequestWriter();
- InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY);
-
- String requestBody = StringHelper.inputStreamToString(batchRequest);
- assertNotNull(batchRequest);
- checkMimeHeaders(requestBody);
-
- assertTrue(requestBody.contains("--batch_"));
- assertTrue(requestBody.contains("GET Employees HTTP/1.1"));
- checkHeaders(headers, requestBody);
- }
-
- @Test
- public void testBatchChangeSet() throws IOException, BatchException {
- List<BatchPart> batch = new ArrayList<BatchPart>();
- Map<String, String> headers = new HashMap<String, String>();
- headers.put("content-type", "application/json");
- BatchChangeSetPart request = BatchChangeSetPart.method(PUT)
- .uri("Employees('2')")
- .body("{\"Возраст\":40}")
- .headers(headers)
- .contentId("111")
- .build();
- BatchChangeSet changeSet = BatchChangeSet.newBuilder().build();
- changeSet.add(request);
- batch.add(changeSet);
-
- BatchRequestWriter writer = new BatchRequestWriter();
- InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY);
-
- String requestBody = StringHelper.inputStreamToString(batchRequest, true);
- assertNotNull(batchRequest);
- checkMimeHeaders(requestBody);
- checkHeaders(headers, requestBody);
-
- assertTrue(requestBody.contains("--batch_"));
- assertTrue(requestBody.contains("--changeset_"));
- assertTrue(requestBody.contains("PUT Employees('2') HTTP/1.1"));
- assertTrue(requestBody.contains("{\"Возраст\":40}"));
- }
-
- @Test
- public void testBatchWithGetAndPost() throws BatchException, IOException {
- List<BatchPart> batch = new ArrayList<BatchPart>();
- Map<String, String> headers = new HashMap<String, String>();
- headers.put("Accept", "application/json");
- BatchPart request = BatchQueryPart.method(GET).uri("Employees").headers(headers).contentId("000").build();
- batch.add(request);
-
- Map<String, String> changeSetHeaders = new HashMap<String, String>();
- changeSetHeaders.put("content-type", "application/json");
- String body = "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEA";
- BatchChangeSetPart changeRequest = BatchChangeSetPart.method(POST)
- .uri("Employees")
- .body(body)
- .headers(changeSetHeaders)
- .contentId("111")
- .build();
- BatchChangeSet changeSet = BatchChangeSet.newBuilder().build();
- changeSet.add(changeRequest);
- batch.add(changeSet);
- BatchRequestWriter writer = new BatchRequestWriter();
- InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY);
-
- String requestBody = StringHelper.inputStreamToString(batchRequest);
- assertNotNull(batchRequest);
- checkMimeHeaders(requestBody);
-
- checkHeaders(headers, requestBody);
- checkHeaders(changeSetHeaders, requestBody);
- assertTrue(requestBody.contains("GET Employees HTTP/1.1"));
- assertTrue(requestBody.contains("POST Employees HTTP/1.1"));
- assertTrue(requestBody.contains(body));
- }
-
- @Test
- public void testChangeSetWithContentIdReferencing() throws BatchException, IOException {
- List<BatchPart> batch = new ArrayList<BatchPart>();
-
- Map<String, String> changeSetHeaders = new HashMap<String, String>();
- changeSetHeaders.put("content-type", "application/json");
- String body = "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEA";
- BatchChangeSetPart changeRequest = BatchChangeSetPart.method(POST)
- .uri("Employees('2')")
- .body(body)
- .headers(changeSetHeaders)
- .contentId("1")
- .build();
- BatchChangeSet changeSet = BatchChangeSet.newBuilder().build();
- changeSet.add(changeRequest);
-
- changeSetHeaders = new HashMap<String, String>();
- changeSetHeaders.put("content-type", "application/json;odata=verbose");
- BatchChangeSetPart changeRequest2 = BatchChangeSetPart.method(PUT)
- .uri("$/ManagerId")
- .body("{\"ManagerId\":1}")
- .headers(changeSetHeaders)
- .contentId("2")
- .build();
- changeSet.add(changeRequest2);
- batch.add(changeSet);
-
- BatchRequestWriter writer = new BatchRequestWriter();
- InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY);
-
- String requestBody = StringHelper.inputStreamToString(batchRequest);
- assertNotNull(batchRequest);
- checkMimeHeaders(requestBody);
-
- assertTrue(requestBody.contains("POST Employees('2') HTTP/1.1"));
- assertTrue(requestBody.contains("PUT $/ManagerId HTTP/1.1"));
- assertTrue(requestBody.contains(BatchHelper.HTTP_CONTENT_ID + ": 1"));
- assertTrue(requestBody.contains(BatchHelper.HTTP_CONTENT_ID + ": 2"));
- assertTrue(requestBody.contains(body));
-
- }
-
- @Test
- public void testBatchWithTwoChangeSets() throws BatchException, IOException {
- List<BatchPart> batch = new ArrayList<BatchPart>();
-
- Map<String, String> changeSetHeaders = new HashMap<String, String>();
- changeSetHeaders.put("content-type", "application/json");
- changeSetHeaders.put("content-Id", "111");
- String body = "/9j/4AAQSkZJRgABAQEBLAEsAAD/4RM0RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEA";
- BatchChangeSetPart changeRequest = BatchChangeSetPart.method(POST)
- .uri("Employees")
- .body(body)
- .headers(changeSetHeaders)
- .build();
- BatchChangeSet changeSet = BatchChangeSet.newBuilder().build();
- changeSet.add(changeRequest);
- batch.add(changeSet);
-
- Map<String, String> changeSetHeaders2 = new HashMap<String, String>();
- changeSetHeaders2.put("content-type", "application/json;odata=verbose");
- changeSetHeaders2.put("content-Id", "222");
- BatchChangeSetPart changeRequest2 = BatchChangeSetPart.method(PUT)
- .uri("Employees('2')/ManagerId")
- .body("{\"ManagerId\":1}")
- .headers(changeSetHeaders2)
- .build();
- BatchChangeSet changeSet2 = BatchChangeSet.newBuilder().build();
- changeSet2.add(changeRequest2);
- batch.add(changeSet2);
-
- BatchRequestWriter writer = new BatchRequestWriter();
- InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY);
-
- String requestBody = StringHelper.inputStreamToString(batchRequest);
- assertNotNull(batchRequest);
- checkMimeHeaders(requestBody);
-
- assertTrue(requestBody.contains("POST Employees HTTP/1.1"));
- assertTrue(requestBody.contains("PUT Employees('2')/ManagerId HTTP/1.1"));
-
- assertTrue(requestBody.contains(body));
-
- }
-
- private void checkHeaders(final Map<String, String> headers, final String requestBody) {
- for (Map.Entry<String, String> header : headers.entrySet()) {
- assertTrue(requestBody.contains(header.getKey() + ": " + header.getValue()));
- }
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testBatchQueryPartWithInvalidMethod() throws BatchException, IOException {
- BatchQueryPart.method(PUT).uri("Employees").build();
-
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testBatchChangeSetPartWithInvalidMethod() throws BatchException, IOException {
- BatchChangeSetPart.method(GET).uri("Employees('2')").build();
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
deleted file mode 100644
index 06daa2a..0000000
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseParserTest.java
+++ /dev/null
@@ -1,280 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.batch;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.batch.BatchException;
-import org.apache.olingo.odata2.api.client.batch.BatchSingleResponse;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
-import org.apache.olingo.odata2.api.commons.HttpHeaders;
-import org.junit.Test;
-
-public class BatchResponseParserTest {
-
- private static final String LF = "\r\n";
-
- @Test
- public void testSimpleBatchResponse() throws BatchException {
- String getResponse = "--batch_123" + LF
- + "Content-Type: application/http" + LF
- + "Content-Transfer-Encoding: binary" + LF
- + "Content-ID: 1" + LF
- + LF
- + "HTTP/1.1 200 OK" + LF
- + "DataServiceVersion: 2.0" + LF
- + "Content-Type: text/plain;charset=utf-8" + LF
- + "Content-length: 22" + LF
- + LF
- + "Frederic Fall MODIFIED" + LF
- + LF
- + "--batch_123--";
-
- InputStream in = new ByteArrayInputStream(getResponse.getBytes());
- BatchResponseParser parser = new BatchResponseParser("multipart/mixed;boundary=batch_123");
- List<BatchSingleResponse> responses = parser.parse(in);
- for (BatchSingleResponse response : responses) {
- assertEquals("200", response.getStatusCode());
- assertEquals("OK", response.getStatusInfo());
- assertEquals("text/plain;charset=utf-8", response.getHeaders().get(HttpHeaders.CONTENT_TYPE));
- assertEquals("22", response.getHeaders().get("Content-length"));
- assertEquals("1", response.getContentId());
- }
- }
-
- @Test
- public void testBatchResponse() throws BatchException, IOException {
- String fileName = "/batchResponse.batch";
- InputStream in = ClassLoader.class.getResourceAsStream(fileName);
- if (in == null) {
- throw new IOException("Requested file '" + fileName + "' was not found.");
- }
- BatchResponseParser parser = new BatchResponseParser("multipart/mixed;boundary=batch_123");
- List<BatchSingleResponse> responses = parser.parse(in);
- for (BatchSingleResponse response : responses) {
- if ("1".equals(response.getContentId())) {
- assertEquals("204", response.getStatusCode());
- assertEquals("No Content", response.getStatusInfo());
- } else if ("3".equals(response.getContentId())) {
- assertEquals("200", response.getStatusCode());
- assertEquals("OK", response.getStatusInfo());
- }
- }
- }
-
- @Test
- public void testResponseToChangeSet() throws BatchException {
- String putResponse = "--batch_123" + LF
- + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + LF
- + LF
- + "--changeset_12ks93js84d" + LF
- + "Content-Type: application/http" + LF
- + "Content-Transfer-Encoding: binary" + LF
- + "Content-ID: 1" + LF
- + LF
- + "HTTP/1.1 204 No Content" + LF
- + "DataServiceVersion: 2.0" + LF
- + LF
- + LF
- + "--changeset_12ks93js84d--" + LF
- + LF
- + "--batch_123--";
-
- InputStream in = new ByteArrayInputStream(putResponse.getBytes());
- BatchResponseParser parser = new BatchResponseParser("multipart/mixed;boundary=batch_123");
- List<BatchSingleResponse> responses = parser.parse(in);
- for (BatchSingleResponse response : responses) {
- assertEquals("204", response.getStatusCode());
- assertEquals("No Content", response.getStatusInfo());
- assertEquals("1", response.getContentId());
- }
- }
-
- @Test(expected = BatchException.class)
- public void testInvalidMimeHeader() throws BatchException {
- String putResponse = "--batch_123" + LF
- + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + LF
- + LF
- + "--changeset_12ks93js84d" + LF
- + "Content-Type: application/http" + LF
- + "Content-Transfer-Encoding: 7bit" + LF // Content-Transfer-Encoding must be binary
- + LF
- + "HTTP/1.1 No Content" + LF
- + "DataServiceVersion: 2.0" + LF
- + LF
- + LF
- + "--changeset_12ks93js84d--" + LF
- + LF
- + "--batch_123--";
-
- parseInvalidBatchResponseBody(putResponse);
- }
-
- @Test(expected = BatchException.class)
- public void testMissingMimeHeader() throws BatchException {
- String putResponse = "--batch_123" + LF
- + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + LF
- + LF
- + "--changeset_12ks93js84d" + LF
- + LF
- + "HTTP/1.1 No Content" + LF
- + "DataServiceVersion: 2.0" + LF
- + LF
- + LF
- + "--changeset_12ks93js84d--" + LF
- + LF
- + "--batch_123--";
-
- parseInvalidBatchResponseBody(putResponse);
- }
-
- @Test(expected = BatchException.class)
- public void testInvalidContentType() throws BatchException {
- String putResponse = "--batch_123" + LF
- + "Content-Type: " + HttpContentType.MULTIPART_MIXED + LF // Missing boundary parameter
- + LF
- + "--changeset_12ks93js84d" + LF
- + "Content-Type: application/http" + LF
- + "Content-Transfer-Encoding: binary" + LF
- + LF
- + "HTTP/1.1 No Content" + LF
- + "DataServiceVersion: 2.0" + LF
- + LF
- + LF
- + "--changeset_12ks93js84d--" + LF
- + LF
- + "--batch_123--";
-
- parseInvalidBatchResponseBody(putResponse);
- }
-
- @Test(expected = BatchException.class)
- public void testInvalidStatusLine() throws BatchException {
- String putResponse = "--batch_123" + LF
- + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + LF
- + LF
- + "--changeset_12ks93js84d" + LF
- + "Content-Type: application/http" + LF
- + "Content-Transfer-Encoding: binary" + LF
- + LF
- + "HTTP/1.1 No Content" + LF
- + "DataServiceVersion: 2.0" + LF
- + LF
- + LF
- + "--changeset_12ks93js84d--" + LF
- + LF
- + "--batch_123--";
-
- parseInvalidBatchResponseBody(putResponse);
-
- }
-
- @Test(expected = BatchException.class)
- public void testMissingCloseDelimiter() throws BatchException {
- String putResponse = "--batch_123" + LF
- + "Content-Type: " + HttpContentType.MULTIPART_MIXED + ";boundary=changeset_12ks93js84d" + LF
- + LF
- + "--changeset_12ks93js84d" + LF
- + "Content-Type: application/http" + LF
- + "Content-Transfer-Encoding: binary" + LF
- + LF
- + "HTTP/1.1 204 No Content" + LF
- + "DataServiceVersion: 2.0" + LF
- + LF
- + LF
- + "--changeset_12ks93js84d--" + LF
- + LF;
-
- parseInvalidBatchResponseBody(putResponse);
-
- }
-
- @Test(expected = BatchException.class)
- public void testInvalidEnteredContentLength() throws BatchException {
- String getResponse = "--batch_123" + LF
- + "Content-Type: application/http" + LF
- + "Content-Transfer-Encoding: binary" + LF
- + "Content-ID: 1" + LF
- + LF
- + "HTTP/1.1 200 OK" + LF
- + "DataServiceVersion: 2.0" + LF
- + "Content-Type: text/plain;charset=utf-8" + LF
- + "Content-length: 100" + LF
- + LF
- + "Frederic Fall" + LF
- + LF
- + "--batch_123--";
-
- parseInvalidBatchResponseBody(getResponse);
- }
-
- @Test(expected = BatchException.class)
- public void testInvalidBoundary() throws BatchException {
- String getResponse = "--batch_321" + LF
- + "Content-Type: application/http" + LF
- + "Content-Transfer-Encoding: binary" + LF
- + "Content-ID: 1" + LF
- + LF
- + "HTTP/1.1 200 OK" + LF
- + "DataServiceVersion: 2.0" + LF
- + "Content-Type: text/plain;charset=utf-8" + LF
- + LF
- + "Frederic Fall" + LF
- + LF
- + "--batch_123--";
-
- parseInvalidBatchResponseBody(getResponse);
- }
-
- @Test(expected = BatchException.class)
- public void testInvalidBoundary2() throws BatchException {
- String getResponse = "--batch_123" + LF
- + "Content-Type: application/http" + LF
- + "Content-Transfer-Encoding: binary" + LF
- + LF
- + "HTTP/1.1 200 OK" + LF
- + "Content-Type: text/plain;charset=utf-8" + LF
- + "Content-Length: 13" + LF
- + LF
- + "Frederic Fall" + LF
- + LF
- + "batch_123" + LF
- + "Content-Type: application/http" + LF
- + "Content-Transfer-Encoding: binary" + LF
- + LF
- + "HTTP/1.1 200 OK" + LF
- + "Content-Type: text/plain;charset=utf-8" + LF
- + LF
- + "Walter Winter" + LF
- + LF
- + "--batch_123--";
- parseInvalidBatchResponseBody(getResponse);
- }
-
- private void parseInvalidBatchResponseBody(final String putResponse) throws BatchException {
- InputStream in = new ByteArrayInputStream(putResponse.getBytes());
- BatchResponseParser parser = new BatchResponseParser("multipart/mixed;boundary=batch_123");
- parser.parse(in);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterTest.java
deleted file mode 100644
index ea7d2bb..0000000
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/batch/BatchResponseWriterTest.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.batch;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.batch.BatchException;
-import org.apache.olingo.odata2.api.batch.BatchResponsePart;
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.junit.Test;
-
-public class BatchResponseWriterTest {
-
- @Test
- public void testBatchResponse() throws BatchException, IOException {
- List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>();
- ODataResponse response = ODataResponse.entity("Walter Winter")
- .status(HttpStatusCodes.OK)
- .contentHeader("application/json")
- .build();
- List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
- responses.add(response);
- parts.add(BatchResponsePart.responses(responses).changeSet(false).build());
-
- ODataResponse changeSetResponse = ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
- responses = new ArrayList<ODataResponse>(1);
- responses.add(changeSetResponse);
- parts.add(BatchResponsePart.responses(responses).changeSet(true).build());
-
- BatchResponseWriter writer = new BatchResponseWriter();
- ODataResponse batchResponse = writer.writeResponse(parts);
-
- assertEquals(202, batchResponse.getStatus().getStatusCode());
- assertNotNull(batchResponse.getEntity());
- String body = (String) batchResponse.getEntity();
-
- assertTrue(body.contains("--batch"));
- assertTrue(body.contains("--changeset"));
- assertTrue(body.contains("HTTP/1.1 200 OK"));
- assertTrue(body.contains("Content-Type: application/http"));
- assertTrue(body.contains("Content-Transfer-Encoding: binary"));
- assertTrue(body.contains("Walter Winter"));
- assertTrue(body.contains("multipart/mixed; boundary=changeset"));
- assertTrue(body.contains("HTTP/1.1 204 No Content"));
-
- }
-
- @Test
- public void testResponse() throws BatchException, IOException {
- List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>();
- ODataResponse response =
- ODataResponse.entity("Walter Winter").status(HttpStatusCodes.OK).contentHeader("application/json").build();
- List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
- responses.add(response);
- parts.add(BatchResponsePart.responses(responses).changeSet(false).build());
- BatchResponseWriter writer = new BatchResponseWriter();
- ODataResponse batchResponse = writer.writeResponse(parts);
-
- assertEquals(202, batchResponse.getStatus().getStatusCode());
- assertNotNull(batchResponse.getEntity());
- String body = (String) batchResponse.getEntity();
-
- assertTrue(body.contains("--batch"));
- assertFalse(body.contains("--changeset"));
- assertTrue(body.contains("HTTP/1.1 200 OK" + "\r\n"));
- assertTrue(body.contains("Content-Type: application/http" + "\r\n"));
- assertTrue(body.contains("Content-Transfer-Encoding: binary" + "\r\n"));
- assertTrue(body.contains("Walter Winter"));
- assertFalse(body.contains("multipart/mixed; boundary=changeset"));
-
- }
-
- @Test
- public void testChangeSetResponse() throws BatchException, IOException {
- List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>();
- ODataResponse changeSetResponse = ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
- List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
- responses.add(changeSetResponse);
- parts.add(BatchResponsePart.responses(responses).changeSet(true).build());
-
- BatchResponseWriter writer = new BatchResponseWriter();
- ODataResponse batchResponse = writer.writeResponse(parts);
-
- assertEquals(202, batchResponse.getStatus().getStatusCode());
- assertNotNull(batchResponse.getEntity());
- String body = (String) batchResponse.getEntity();
- assertTrue(body.contains("--batch"));
- assertTrue(body.contains("--changeset"));
- assertTrue(body.indexOf("--changeset") != body.lastIndexOf("--changeset"));
- assertFalse(body.contains("HTTP/1.1 200 OK" + "\r\n"));
- assertTrue(body.contains("Content-Type: application/http" + "\r\n"));
- assertTrue(body.contains("Content-Transfer-Encoding: binary" + "\r\n"));
- assertTrue(body.contains("HTTP/1.1 204 No Content" + "\r\n"));
- assertTrue(body.contains("Content-Type: multipart/mixed; boundary=changeset"));
-
- }
-
- @Test
- public void testContentIdEchoing() throws BatchException, IOException {
- List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>();
- ODataResponse response = ODataResponse.entity("Walter Winter")
- .status(HttpStatusCodes.OK)
- .contentHeader("application/json")
- .header(BatchHelper.MIME_HEADER_CONTENT_ID, "mimeHeaderContentId123")
- .header(BatchHelper.REQUEST_HEADER_CONTENT_ID, "requestHeaderContentId123")
- .build();
- List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
- responses.add(response);
- parts.add(BatchResponsePart.responses(responses).changeSet(false).build());
- BatchResponseWriter writer = new BatchResponseWriter();
- ODataResponse batchResponse = writer.writeResponse(parts);
-
- assertEquals(202, batchResponse.getStatus().getStatusCode());
- assertNotNull(batchResponse.getEntity());
- String body = (String) batchResponse.getEntity();
-
- String mimeHeader = "Content-Type: application/http" + "\r\n"
- + "Content-Transfer-Encoding: binary" + "\r\n"
- + "Content-Id: mimeHeaderContentId123" + "\r\n";
-
- String requestHeader = "Content-Id: requestHeaderContentId123" + "\r\n"
- + "Content-Type: application/json" + "\r\n"
- + "Content-Length: 13" + "\r\n";
-
- assertTrue(body.contains(mimeHeader));
- assertTrue(body.contains(requestHeader));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/ContentTypeTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/ContentTypeTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/ContentTypeTest.java
deleted file mode 100644
index 439bb89..0000000
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/ContentTypeTest.java
+++ /dev/null
@@ -1,1010 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.commons;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.core.MediaType;
-
-import org.apache.olingo.odata2.api.commons.HttpContentType;
-import org.apache.olingo.odata2.core.commons.ContentType.ODataFormat;
-import org.apache.olingo.odata2.testutil.fit.BaseTest;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-
-// 14.1 Accept
-//
-// The Accept request-header field can be used to specify certain media types which are acceptable for the response.
-// Accept headers can be used to indicate that the request is specifically limited to a small set of desired types, as
-// in the case of a request for an in-line image.
-//
-// Accept = "Accept" ":"
-// #( media-range [ accept-params ] )
-// media-range = ( "*/*"
-// | ( type "/" "*" )
-// | ( type "/" subtype )
-// ) *( ";" parameter )
-// accept-params = ";" "q" "=" qvalue *( accept-extension )
-// accept-extension = ";" token [ "=" ( token | quoted-string ) ]
-
-/**
- *
- */
-public class ContentTypeTest extends BaseTest {
-
- @Test
- public void testMe() {
- MediaType t = new MediaType("*", "xml");
- assertNotNull(t);
- assertTrue(t.isCompatible(new MediaType("app", "xml")));
- }
-
- @Test
- public void parseable() {
- assertTrue(ContentType.isParseable("application/xml"));
- assertTrue(ContentType.isParseable("text/plain"));
- assertTrue(ContentType.isParseable("application/atom+xml; charset=UTF-8"));
-
- assertFalse(ContentType.isParseable("application/ atom+xml; charset=UTF-8"));
- assertFalse(ContentType.isParseable("application /atom+xml; charset=UTF-8"));
- //
- assertFalse(ContentType.isParseable("app/app/moreapp"));
- // assertFalse(ContentType.isParseable("application/atom+xml; charset = UTF-8"));
- assertFalse(ContentType.isParseable(null));
- assertFalse(ContentType.isParseable(""));
- assertFalse(ContentType.isParseable("hugo"));
- assertFalse(ContentType.isParseable("hugo/"));
- }
-
- @Test
- public void parseNotThrow() {
- assertNotNull(ContentType.parse("application/xml"));
- assertNotNull(ContentType.parse("text/plain"));
- assertNotNull(ContentType.parse("application/atom+xml; charset=UTF-8"));
-
- assertFalse(ContentType.isParseable("application/ atom+xml; charset=UTF-8"));
- assertFalse(ContentType.isParseable("application /atom+xml; charset=UTF-8"));
- //
- assertNull(ContentType.parse("app/app/moreapp"));
- // assertFalse(ContentType.isParseable("application/atom+xml; charset = UTF-8"));
- assertNull(ContentType.parse(null));
- assertNull(ContentType.parse("hugo"));
- assertNull(ContentType.parse("hugo"));
- assertNull(ContentType.parse("hugo/"));
- }
-
- @Test
- public void creationCustomContentType() {
- ContentType mt = ContentType.createAsCustom("custom");
-
- assertEquals("custom", mt.getType());
- assertNull(mt.getSubtype());
- assertEquals("custom", mt.toString());
- assertEquals(ODataFormat.CUSTOM, mt.getODataFormat());
- }
-
- @Test
- public void creationCustomContentTypeImageJpeg() {
- ContentType mt = ContentType.createAsCustom("image/jpeg");
-
- assertEquals("image", mt.getType());
- assertEquals("jpeg", mt.getSubtype());
- assertEquals("image/jpeg", mt.toString());
- assertEquals(ODataFormat.MIME, mt.getODataFormat());
- }
-
- @Test
- public void creationCustomContentTypes() {
- List<ContentType> contentTypes = ContentType.createAsCustom(Arrays.asList("custom", "image/jpeg"));
-
- Assert.assertEquals(2, contentTypes.size());
-
- for (ContentType contentType : contentTypes) {
- if (contentType.getType().equals("custom")) {
- assertEquals("custom", contentType.getType());
- assertNull(contentType.getSubtype());
- assertEquals("custom", contentType.toString());
- assertEquals(ODataFormat.CUSTOM, contentType.getODataFormat());
- } else if (contentType.getType().equals("image")) {
- assertEquals("image", contentType.getType());
- assertEquals("jpeg", contentType.getSubtype());
- assertEquals("image/jpeg", contentType.toString());
- assertEquals(ODataFormat.MIME, contentType.getODataFormat());
- } else {
- Assert.fail("Found unexpected content type with value " + contentType.toContentTypeString());
- }
- }
- }
-
- @Test
- public void creationContentTypeImageJpeg() {
- ContentType mt = ContentType.create("image/jpeg");
-
- assertEquals("image", mt.getType());
- assertEquals("jpeg", mt.getSubtype());
- assertEquals("image/jpeg", mt.toString());
- assertEquals(ODataFormat.MIME, mt.getODataFormat());
- }
-
- @Test
- public void creationFromHttpContentTypeAtomXmlEntry() {
- ContentType mt = ContentType.create(HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8);
-
- assertEquals("application", mt.getType());
- assertEquals("atom+xml", mt.getSubtype());
- assertEquals("application/atom+xml;charset=utf-8;type=entry", mt.toString());
- assertEquals(ODataFormat.ATOM, mt.getODataFormat());
- assertEquals(2, mt.getParameters().size());
- assertEquals("entry", mt.getParameters().get("type"));
- assertEquals("utf-8", mt.getParameters().get("charset"));
- assertEquals(ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8, mt);
- }
-
- @Test
- public void creationFromHttpContentTypeMultipartMixed() {
- ContentType mt = ContentType.create(HttpContentType.MULTIPART_MIXED);
-
- assertEquals("multipart", mt.getType());
- assertEquals("mixed", mt.getSubtype());
- assertEquals("multipart/mixed", mt.toString());
- assertEquals(ODataFormat.MIME, mt.getODataFormat());
- assertEquals(0, mt.getParameters().size());
- assertEquals(ContentType.MULTIPART_MIXED, mt);
- assertTrue(ContentType.MULTIPART_MIXED.isCompatible(mt));
- }
-
- @Test
- public void creationFromHttpContentTypeMultipartMixedWithParameters() {
- String boundary = UUID.randomUUID().toString();
- ContentType mt = ContentType.create(HttpContentType.MULTIPART_MIXED + "; boundary=" + boundary);
-
- assertEquals("multipart", mt.getType());
- assertEquals("mixed", mt.getSubtype());
- assertEquals("multipart/mixed;boundary=" + boundary, mt.toString());
- assertEquals(ODataFormat.MIME, mt.getODataFormat());
- assertEquals(1, mt.getParameters().size());
- assertEquals(boundary, mt.getParameters().get("boundary"));
- assertTrue(ContentType.MULTIPART_MIXED.isCompatible(mt));
- }
-
- @Test
- public void creationFromHttpContentTypeApplicationXml() {
- ContentType mt = ContentType.create(HttpContentType.APPLICATION_XML_UTF8);
-
- assertEquals("application", mt.getType());
- assertEquals("xml", mt.getSubtype());
- assertEquals("application/xml;charset=utf-8", mt.toString());
- assertEquals(ODataFormat.XML, mt.getODataFormat());
- assertEquals(1, mt.getParameters().size());
- assertEquals(ContentType.create(ContentType.APPLICATION_XML, "charset", "utf-8"), mt);
- }
-
- @Test
- public void creationFromHttpContentTypeApplicationJson() {
- ContentType mt = ContentType.create(HttpContentType.APPLICATION_JSON_UTF8);
-
- assertEquals("application", mt.getType());
- assertEquals("json", mt.getSubtype());
- assertEquals("application/json;charset=utf-8", mt.toString());
- assertEquals(ODataFormat.JSON, mt.getODataFormat());
- assertEquals(1, mt.getParameters().size());
- assertEquals(ContentType.create(ContentType.APPLICATION_JSON, "charset", "utf-8"), mt);
- }
-
- @Test
- public void testContentTypeCreation() {
- ContentType mt = ContentType.create("type", "subtype");
-
- assertEquals("type", mt.getType());
- assertEquals("subtype", mt.getSubtype());
- assertEquals("type/subtype", mt.toString());
- assertEquals(ODataFormat.CUSTOM, mt.getODataFormat());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testContentTypeCreationWildcardType() {
- ContentType.create("*", "subtype");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testContentTypeCreationWildcardTypeSingleFormat() {
- ContentType.create("*/subtype");
- }
-
- /**
- * See: RFC 2616:
- * The type, subtype, and parameter attribute names are case-insensitive. Parameter values might or might not be
- * case-sensitive,
- * depending on the semantics of the parameter name. Linear white space (LWS) MUST NOT be used between the type and
- * subtype,
- * nor between an attribute and its value.
- * </p>
- * @throws Throwable
- */
- @Test
- public void testContentTypeCreationInvalidWithSpaces() throws Throwable {
- failContentTypeCreation("app/ space", IllegalArgumentException.class);
- failContentTypeCreation("app /space", IllegalArgumentException.class);
- failContentTypeCreation("app / space", IllegalArgumentException.class);
- }
-
- private void
- failContentTypeCreation(final String contentType, final Class<? extends Exception> expectedExceptionClass)
- throws Exception {
- try {
- ContentType.create(contentType);
- Assert.fail("Expected exception class " + expectedExceptionClass +
- " was not thrown for creation of content type based on '" + contentType + "'.");
- } catch (Exception e) {
- assertEquals(expectedExceptionClass, e.getClass());
- }
- }
-
- @Test
- public void testContentTypeCreationWildcardSubType() {
- ContentType mt = ContentType.create("type", "*");
-
- assertEquals("type", mt.getType());
- assertEquals("*", mt.getSubtype());
- assertEquals("type/*", mt.toString());
- assertEquals(ODataFormat.CUSTOM, mt.getODataFormat());
- }
-
- @Test
- public void testContentTypeCreationWildcardSubTypeSingleFormat() {
- ContentType mt = ContentType.create("type/*");
-
- assertEquals("type", mt.getType());
- assertEquals("*", mt.getSubtype());
- assertEquals("type/*", mt.toString());
- assertEquals(ODataFormat.CUSTOM, mt.getODataFormat());
- }
-
- @Test
- public void testContentTypeCreationAtom() {
- ContentType mt = ContentType.create("application", "atom+xml");
-
- assertEquals("application", mt.getType());
- assertEquals("atom+xml", mt.getSubtype());
- assertEquals("application/atom+xml", mt.toString());
- assertEquals(ODataFormat.ATOM, mt.getODataFormat());
- }
-
- @Test
- public void testContentTypeCreationXml() {
- ContentType mt = ContentType.create("application", "xml");
-
- assertEquals("application", mt.getType());
- assertEquals("xml", mt.getSubtype());
- assertEquals("application/xml", mt.toString());
- assertEquals(ODataFormat.XML, mt.getODataFormat());
- }
-
- @Test
- public void testContentTypeCreationJson() {
- ContentType mt = ContentType.create("application", "json");
-
- assertEquals("application", mt.getType());
- assertEquals("json", mt.getSubtype());
- assertEquals("application/json", mt.toString());
- assertEquals(ODataFormat.JSON, mt.getODataFormat());
- }
-
- @Test
- public void testContentTypeCreationOneString() {
- ContentType mt = ContentType.create("type/subtype");
-
- assertEquals("type", mt.getType());
- assertEquals("subtype", mt.getSubtype());
- assertEquals("type/subtype", mt.toString());
- assertEquals(ODataFormat.CUSTOM, mt.getODataFormat());
- }
-
- @Test
- public void testContentTypeCreationAtomOneString() {
- ContentType mt = ContentType.create("application/atom+xml");
-
- assertEquals("application", mt.getType());
- assertEquals("atom+xml", mt.getSubtype());
- assertEquals("application/atom+xml", mt.toString());
- assertEquals(ODataFormat.ATOM, mt.getODataFormat());
- }
-
- @Test
- public void testContentTypeCreationXmlOneString() {
- ContentType mt = ContentType.create("application/xml");
-
- assertEquals("application", mt.getType());
- assertEquals("xml", mt.getSubtype());
- assertEquals("application/xml", mt.toString());
- assertEquals(ODataFormat.XML, mt.getODataFormat());
- }
-
- @Test
- public void testContentTypeCreationXmlWithParaOneString() {
- ContentType mt = ContentType.create("application/xml;q=0.9");
-
- assertEquals("application", mt.getType());
- assertEquals("xml", mt.getSubtype());
- assertEquals("application/xml", mt.toString());
- assertEquals(ODataFormat.XML, mt.getODataFormat());
- }
-
- @Test
- public void testContentTypeCreationJsonOneString() {
- ContentType mt = ContentType.create("application/json");
-
- assertEquals("application", mt.getType());
- assertEquals("json", mt.getSubtype());
- assertEquals("application/json", mt.toString());
- assertEquals(ODataFormat.JSON, mt.getODataFormat());
- }
-
- @Test
- public void testContentTypeCreationFromStrings() {
- List<ContentType> types =
- ContentType.create(Arrays.asList("type/subtype", "application/xml", "application/json;key=value"));
-
- assertEquals(3, types.size());
-
- ContentType first = types.get(0);
- assertEquals("type", first.getType());
- assertEquals("subtype", first.getSubtype());
- assertEquals("type/subtype", first.toString());
- assertEquals(ODataFormat.CUSTOM, first.getODataFormat());
-
- ContentType second = types.get(1);
- assertEquals("application", second.getType());
- assertEquals("xml", second.getSubtype());
- assertEquals("application/xml", second.toString());
- assertEquals(ODataFormat.XML, second.getODataFormat());
-
- ContentType third = types.get(2);
- assertEquals("application", third.getType());
- assertEquals("json", third.getSubtype());
- assertEquals("application/json;key=value", third.toString());
- assertEquals("value", third.getParameters().get("key"));
- assertEquals(ODataFormat.JSON, third.getODataFormat());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testContentTypeCreationFromStringsFail() {
- List<ContentType> types =
- ContentType.create(Arrays.asList("type/subtype", "application/xml", "application/json/FAIL;key=value"));
-
- assertEquals(3, types.size());
- }
-
- @Test
- public void testEnsureCharsetParameter() {
- ContentType mt = ContentType.create("application/json");
-
- mt = mt.receiveWithCharsetParameter("utf-8");
-
- assertEquals("application", mt.getType());
- assertEquals("json", mt.getSubtype());
- assertEquals("application/json;charset=utf-8", mt.toString());
- assertEquals("utf-8", mt.getParameters().get("charset"));
- assertEquals(ODataFormat.JSON, mt.getODataFormat());
- }
-
- @Test
- public void testEnsureCharsetParameterIso() {
- ContentType mt = ContentType.create("application/xml");
-
- mt = mt.receiveWithCharsetParameter("iso-8859-1");
-
- assertEquals("application", mt.getType());
- assertEquals("xml", mt.getSubtype());
- assertEquals("application/xml;charset=iso-8859-1", mt.toString());
- assertEquals("iso-8859-1", mt.getParameters().get("charset"));
- assertEquals(ODataFormat.XML, mt.getODataFormat());
- }
-
- @Test
- public void testEnsureCharsetParameterAlreadySet() {
- ContentType mt = ContentType.create("application/json;charset=utf-8");
-
- mt = mt.receiveWithCharsetParameter("utf-8");
-
- assertEquals("application", mt.getType());
- assertEquals("json", mt.getSubtype());
- assertEquals("application/json;charset=utf-8", mt.toString());
- assertEquals("utf-8", mt.getParameters().get("charset"));
- assertEquals(ODataFormat.JSON, mt.getODataFormat());
- }
-
- @Test
- public void testEnsureCharsetParameterAlreadySetDiffValue() {
- ContentType mt = ContentType.create("application/json;charset=utf-8");
-
- mt = mt.receiveWithCharsetParameter("iso-8859-1");
-
- assertEquals("application", mt.getType());
- assertEquals("json", mt.getSubtype());
- assertEquals("application/json;charset=utf-8", mt.toString());
- assertEquals("utf-8", mt.getParameters().get("charset"));
- assertEquals(ODataFormat.JSON, mt.getODataFormat());
- }
-
- @Test
- public void testContentTypeWithParameterCreation() {
- ContentType mt = ContentType.create("type", "subtype", addParameters("key", "value"));
-
- assertEquals("type", mt.getType());
- assertEquals("subtype", mt.getSubtype());
- assertEquals(1, mt.getParameters().size());
- assertEquals("value", mt.getParameters().get("key"));
- assertEquals("type/subtype;key=value", mt.toString());
- }
-
- @Test
- public void testContentTypeWithParametersCreation() {
- ContentType mt = ContentType.create("type", "subtype", addParameters("key1", "value1", "key2", "value2"));
- assertEquals("type", mt.getType());
- assertEquals("subtype", mt.getSubtype());
- assertEquals(2, mt.getParameters().size());
- assertEquals("value1", mt.getParameters().get("key1"));
- assertEquals("value2", mt.getParameters().get("key2"));
- assertEquals("type/subtype;key1=value1;key2=value2", mt.toString());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFormatParserInValidInputOnlyType() {
- ContentType.create("aaa");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFormatParserInValidInputOnlyTypeWithSepartor() {
- ContentType.create("aaa/");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFormatParserInValidInputOnlySubTypeWithSepartor() {
- ContentType.create("/aaa");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFormatParserInValidInputOnlySepartor() {
- ContentType.create("/");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFormatParserInValidInputEmpty() {
- ContentType.create("");
- }
-
- @Test
- public void testFormatParserValidInputTypeSubtype() {
- ContentType t = ContentType.create("aaa/bbb");
- assertEquals("aaa", t.getType());
- assertEquals("bbb", t.getSubtype());
- assertEquals(0, t.getParameters().size());
- }
-
- @Test
- public void testFormatParserValidInputTypeSybtypePara() {
- ContentType t = ContentType.create("aaa/bbb;x=y");
- assertEquals("aaa", t.getType());
- assertEquals("bbb", t.getSubtype());
- assertEquals(1, t.getParameters().size());
- }
-
- @Test
- public void testFormatParserValidInputTypeSubtypeParas() {
- ContentType t = ContentType.create("aaa/bbb;x=y;a=b");
- assertEquals("aaa", t.getType());
- assertEquals("bbb", t.getSubtype());
- assertEquals(2, t.getParameters().size());
- }
-
- @Test
- public void testFormatParserValidInputTypeSubtypeNullPara() {
- ContentType t = ContentType.create("aaa/bbb;x=y;a");
-
- assertEquals("aaa", t.getType());
- assertEquals("bbb", t.getSubtype());
- assertEquals(2, t.getParameters().size());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFormatParserInValidInputTypeNullPara() {
- ContentType.create("aaa;x=y;a");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFormatParserInvalidParameterWithSpaces() {
- ContentType.create("aaa/bbb;x= y;a");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFormatParserInvalidParameterWithLineFeed() {
- ContentType.create("aaa/bbb;x=\ny;a");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFormatParserInvalidParameterWithCarriageReturn() {
- ContentType.create("aaa/bbb;x=\ry;a");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFormatParserInvalidParameterWithTabs() {
- ContentType.create("aaa/bbb;x=\ty;a");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFormatParserInvalidParameterWithAllLws() {
- ContentType.create("aaa/bbb;x=\t \n \ry;a");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testFormatParserInvalidParameterWithAllLws2() {
- ContentType.create("aaa/bbb;x=\n \ry;a= \tbla ");
- }
-
- @Test
- public void testSimpleEqual() {
- ContentType t1 = ContentType.create("aaa/bbb");
- ContentType t2 = ContentType.create("aaa/bbb");
-
- assertEquals(t1, t2);
- }
-
- @Test
- public void testEqualWithParameters() {
- ContentType t1 = ContentType.create("aaa/bbb;x=y;a");
- ContentType t2 = ContentType.create("aaa/bbb;x=y;a");
-
- assertEquals(t1, t2);
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- }
-
- @Test
- public void testEqualWithParametersIgnoreCase() {
- ContentType t1 = ContentType.create("aaa/bbb;x=YY");
- ContentType t2 = ContentType.create("aaa/bbb;x=yy");
-
- assertEquals(t1, t2);
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- }
-
- @Test
- public void testEqualWithUnsortedParameters() {
- ContentType t1 = ContentType.create("aaa/bbb;x=y;a=b");
- ContentType t2 = ContentType.create("aaa/bbb;a=b;x=y");
-
- assertEquals(t1, t2);
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- }
-
- @Test
- public void testEqualWithUnsortedParametersIgnoreCase() {
- ContentType t1 = ContentType.create("aaa/bbb;xx=y;a=BB");
- ContentType t2 = ContentType.create("aaa/bbb;a=bb;XX=y");
-
- assertEquals(t1, t2);
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- }
-
- @Test
- public void testEqualWithWildcard() {
- ContentType t1 = ContentType.create("aaa/bbb");
- ContentType t2 = ContentType.create("*");
-
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- assertEquals(t1, t2);
- }
-
- @Test
- public void testEqualWithWildcardSubtype() {
- ContentType t1 = ContentType.create("aaa/bbb");
- ContentType t2 = ContentType.create("aaa/*");
-
- assertEquals(t1, t2);
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- }
-
- @Test
- public void testEqualWithDiffTypeWildcardSubtype() {
- ContentType t1 = ContentType.create("ccc/bbb");
- ContentType t2 = ContentType.create("aaa/*");
-
- assertFalse(t1.equals(t2));
- assertFalse(t2.equals(t1));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testIllegalSubTypeWildcardSubtype() {
- ContentType t1 = ContentType.create("*/bbb");
- assertNull(t1);
- }
-
- @Test
- public void testEqualWithWildcardAndParameters() {
- ContentType t1 = ContentType.create("aaa/bbb;x=y;a");
- ContentType t2 = ContentType.create("*");
-
- assertEquals(t1, t2);
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- }
-
- @Test
- public void testEqualWithWildcardSubtypeAndParameters() {
- ContentType t1 = ContentType.create("aaa/bbb;x=y;a");
- ContentType t2 = ContentType.create("aaa/*");
-
- assertEquals(t1, t2);
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- }
-
- @Test
- public void testEqualWithWildcardSubtypeAndParametersBoth() {
- ContentType t1 = ContentType.create("aaa/bbb;x=y");
- ContentType t2 = ContentType.create("aaa/*;x=y");
-
- assertEquals(t1, t2);
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- }
-
- @Test
- @Ignore("If ContentType contains wildcards parameters are ignored.")
- public void testUnEqualWithWildcardSubtypeAndDiffParameters() {
- ContentType t1 = ContentType.create("aaa/bbb;x=z");
- ContentType t2 = ContentType.create("aaa/*;x=y");
-
- assertFalse(t1.equals(t2));
- assertFalse(t2.equals(t1));
- }
-
- @Test
- public void testUnSimpleEqual() {
- ContentType t1 = ContentType.create("aaa/ccc");
- ContentType t2 = ContentType.create("aaa/bbb");
-
- assertFalse(t1.equals(t2));
- assertFalse(t2.equals(t1));
- }
-
- @Test
- public void testUnEqualTypesWithParameters() {
- ContentType t1 = ContentType.create("aaa/bbb;x=y;a");
- ContentType t2 = ContentType.create("ccc/bbb;x=y;a");
-
- assertFalse(t1.equals(t2));
- assertFalse(t2.equals(t1));
- }
-
- @Test
- public void testUnEqualParameters() {
- ContentType t1 = ContentType.create("aaa/bbb;x=y;a");
- ContentType t2 = ContentType.create("aaa/bbb;x=y;a=b");
-
- assertFalse(t1.equals(t2));
- assertFalse(t2.equals(t1));
- }
-
- @Test
- public void testUnEqualParametersCounts() {
- ContentType t1 = ContentType.create("aaa/bbb");
- ContentType t2 = ContentType.create("aaa/bbb;x=y;a=b");
-
- assertFalse(t1.equals(t2));
- assertFalse(t2.equals(t1));
- }
-
- @Test
- public void testUnEqualParametersCountsIgnoreQ() {
- ContentType t1 = ContentType.create("aaa/bbb;q=0.9");
- ContentType t2 = ContentType.create("aaa/bbb;x=y;a=b");
-
- assertFalse(t1.equals(t2));
- assertFalse(t2.equals(t1));
- }
-
- @Test
- public void testEqualParametersCountsIgnoreQ() {
- ContentType t1 = ContentType.create("aaa/bbb;q=0.9;x=y;a=b");
- ContentType t2 = ContentType.create("aaa/bbb;x=y;a=b");
-
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- }
-
- @Test
- public void testEqualParametersCountsWithQ() {
- ContentType t1 = ContentType.create("aaa", "bbb", addParameters("a", "b", "x", "y", "q", "0.9"));
- ContentType t2 = ContentType.create("aaa/bbb;x=y;a=b");
-
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- }
-
- @Test
- public void testUnEqualWithUnsortedParameters() {
- ContentType t1 = ContentType.create("aaa/bbb;x=z;a=b");
- ContentType t2 = ContentType.create("aaa/bbb;a=b;x=y");
-
- assertFalse(t1.equals(t2));
- assertFalse(t2.equals(t1));
- }
-
- @Test
- public void testCompareSame() {
- ContentType t1 = ContentType.create("aaa/bbb");
- ContentType t2 = ContentType.create("aaa/bbb");
-
- assertEquals(0, t1.compareWildcardCounts(t2));
- assertEquals(0, t2.compareWildcardCounts(t1));
- }
-
- @Test
- public void testCompareTwoWildcard() {
- ContentType t1 = ContentType.create("*/*");
- ContentType t2 = ContentType.create("aaa/bbb");
-
- assertEquals(3, t1.compareWildcardCounts(t2));
- assertEquals(-3, t2.compareWildcardCounts(t1));
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- }
-
- @Test
- public void testCompareSubWildcard() {
- ContentType t1 = ContentType.create("aaa/*");
- ContentType t2 = ContentType.create("aaa/bbb");
-
- assertEquals(1, t1.compareWildcardCounts(t2));
- assertEquals(-1, t2.compareWildcardCounts(t1));
- assertTrue(t1.equals(t2));
- assertTrue(t2.equals(t1));
- }
-
- @Test
- public void testCompareSubTypeWildcard() {
- ContentType t1 = ContentType.create("aaa/*");
- ContentType t2 = ContentType.create("xxx/*");
-
- assertEquals(0, t1.compareWildcardCounts(t2));
- assertEquals(0, t2.compareWildcardCounts(t1));
- assertFalse(t1.equals(t2));
- assertFalse(t2.equals(t1));
- }
-
- @Test
- public void testNonEqualCharset() {
- ContentType t1 = ContentType.create("aaa/bbb;charset=c1");
- ContentType t2 = ContentType.create("aaa/bbb;charset=c2");
-
- assertFalse(t1.equals(t2));
- }
-
- @Test
- public void testCompatible() {
- ContentType t1 = ContentType.create("aaa/bbb");
- ContentType t2 = ContentType.create("aaa/bbb");
-
- assertTrue(t1.isCompatible(t2));
- assertTrue(t2.isCompatible(t1));
- //
- assertTrue(t1.equals(t2));
- }
-
- @Test
- public void testCompatibleQ_ParametersSet() {
- ContentType t1 = ContentType.create("aaa/bbb;q=0.9;x=y;a=b");
- ContentType t2 = ContentType.create("aaa/bbb;x=y;a=b");
-
- assertTrue(t1.isCompatible(t2));
- assertTrue(t2.isCompatible(t1));
- //
- assertTrue(t1.equals(t2));
- }
-
- @Test
- public void testCompatibleDiffParameterValuesSet() {
- ContentType t1 = ContentType.create("aaa/bbb;x=z;a=c");
- ContentType t2 = ContentType.create("aaa/bbb;x=y;a=b");
-
- assertTrue(t1.isCompatible(t2));
- assertTrue(t2.isCompatible(t1));
- //
- assertFalse(t1.equals(t2));
- }
-
- @Test
- public void testCompatibleDiffParameterCountSet() {
- ContentType t1 = ContentType.create("aaa/bbb;a=b");
- ContentType t2 = ContentType.create("aaa/bbb;x=y;a=b");
-
- assertTrue(t1.isCompatible(t2));
- assertTrue(t2.isCompatible(t1));
- //
- assertFalse(t1.equals(t2));
- }
-
- @Test
- public void testMatchSimple() {
- ContentType m1 = ContentType.create("aaa/bbb;x=z;a=b");
- ContentType m2 = ContentType.create("aaa/ccc");
- ContentType m3 = ContentType.create("foo/me");
- List<ContentType> toMatchContentTypes = new ArrayList<ContentType>();
- toMatchContentTypes.add(m1);
- toMatchContentTypes.add(m2);
- toMatchContentTypes.add(m3);
-
- ContentType check = ContentType.create("foo/me");
-
- ContentType match = check.match(toMatchContentTypes);
-
- assertEquals(ContentType.create("foo/me"), match);
- assertEquals("foo/me", match.toContentTypeString());
- }
-
- @Test
- public void testMatchNoMatch() {
- ContentType m1 = ContentType.create("aaa/bbb;x=z;a=b");
- ContentType m2 = ContentType.create("aaa/ccc");
- ContentType m3 = ContentType.create("foo/me");
- List<ContentType> toMatchContentTypes = new ArrayList<ContentType>();
- toMatchContentTypes.add(m1);
- toMatchContentTypes.add(m2);
- toMatchContentTypes.add(m3);
-
- ContentType check = ContentType.create("for/me");
-
- ContentType match = check.match(toMatchContentTypes);
-
- assertTrue(match == null);
- }
-
- @Test
- public void testHasMatchSimple() {
- ContentType m1 = ContentType.create("aaa/bbb;x=z;a=b");
- ContentType m2 = ContentType.create("aaa/ccc");
- ContentType m3 = ContentType.create("foo/me");
- List<ContentType> toMatchContentTypes = new ArrayList<ContentType>();
- toMatchContentTypes.add(m1);
- toMatchContentTypes.add(m2);
- toMatchContentTypes.add(m3);
-
- ContentType check = ContentType.create("foo/me");
-
- boolean match = check.hasMatch(toMatchContentTypes);
- assertTrue(match);
- }
-
- @Test
- public void testHasMatchNoMatch() {
- ContentType m1 = ContentType.create("aaa/bbb;x=z;a=b");
- ContentType m2 = ContentType.create("aaa/ccc");
- ContentType m3 = ContentType.create("foo/me");
- List<ContentType> toMatchContentTypes = new ArrayList<ContentType>();
- toMatchContentTypes.add(m1);
- toMatchContentTypes.add(m2);
- toMatchContentTypes.add(m3);
-
- ContentType check = ContentType.create("for/me");
-
- boolean match = check.hasMatch(toMatchContentTypes);
- assertFalse(match);
- }
-
- @Test
- public void testMatchCompatibleSimple() {
- ContentType m1 = ContentType.create("aaa/bbb;x=z;a=b");
- ContentType m2 = ContentType.create("aaa/ccc");
- ContentType m3 = ContentType.create("foo/me");
- List<ContentType> toMatchContentTypes = new ArrayList<ContentType>();
- toMatchContentTypes.add(m1);
- toMatchContentTypes.add(m2);
- toMatchContentTypes.add(m3);
-
- ContentType check = ContentType.create("foo/me");
-
- ContentType match = check.matchCompatible(toMatchContentTypes);
-
- assertEquals(ContentType.create("foo/me"), match);
- assertEquals("foo/me", match.toContentTypeString());
- }
-
- @Test
- public void testMatchCompatibleNoMatch() {
- ContentType m1 = ContentType.create("aaa/bbb;x=z;a=b");
- ContentType m2 = ContentType.create("aaa/ccc");
- ContentType m3 = ContentType.create("foo/me");
- List<ContentType> toMatchContentTypes = new ArrayList<ContentType>();
- toMatchContentTypes.add(m1);
- toMatchContentTypes.add(m2);
- toMatchContentTypes.add(m3);
-
- ContentType check = ContentType.create("for/me");
-
- ContentType match = check.matchCompatible(toMatchContentTypes);
-
- assertTrue(match == null);
- }
-
- @Test
- public void testIsWildcard() {
- assertFalse(ContentType.create("aaa/bbb;x=y;a").isWildcard());
- assertFalse(ContentType.create("aaa/*;x=y;a").isWildcard());
- assertTrue(ContentType.create("*/*;x=y;a").isWildcard());
- assertTrue(ContentType.create("*/*").isWildcard());
- }
-
- @Test
- public void testHasWildcard() {
- assertFalse(ContentType.create("aaa/bbb;x=y;a").hasWildcard());
- assertTrue(ContentType.create("aaa/*;x=y;a").hasWildcard());
- assertTrue(ContentType.create("*/*;x=y;a").hasWildcard());
- assertTrue(ContentType.create("*/*").hasWildcard());
- }
-
- @Test
- public void testQParameterSort() {
- validateSort(Arrays.asList("a1/b1;q=0.2", "a2/b2;q=0.5", "a3/b3;q=0.333"), 1, 2, 0);
- validateSort(Arrays.asList("a1/b1;q=0", "a2/b2;q=0.5", "a3/b3;q=0.333"), 1, 2, 0);
- validateSort(Arrays.asList("a1/b1;q=1", "a2/b2;q=0.5", "a3/b3;q=0.333"), 0, 1, 2);
- validateSort(Arrays.asList("a1/b1;q=1", "a2/b2;q=0.5", "a3/b3;q=1.333"), 0, 1, 2);
- validateSort(Arrays.asList("a1/b1;q=0.2", "a2/b2;q=0.9", "a3/b3"), 2, 1, 0);
- }
-
- private void validateSort(final List<String> toSort, final int... expectedSequence) {
- List<String> expected = new ArrayList<String>();
- for (int i : expectedSequence) {
- expected.add(toSort.get(i));
- }
-
- ContentType.sortForQParameter(toSort);
- for (int i = 0; i < expectedSequence.length; i++) {
- assertEquals(expected.get(i), toSort.get(i));
- }
- }
-
- private Map<String, String> addParameters(final String... content) {
- Map<String, String> map = new HashMap<String, String>();
- for (int i = 0; i < content.length - 1; i += 2) {
- String key = content[i];
- String value = content[i + 1];
- map.put(key, value);
- }
- return map;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/DecoderTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/DecoderTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/DecoderTest.java
deleted file mode 100644
index a9c8299..0000000
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/DecoderTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.commons;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import org.apache.olingo.odata2.testutil.fit.BaseTest;
-import org.junit.Test;
-
-/**
- *
- */
-public class DecoderTest extends BaseTest {
-
- @Test
- public void asciiCharacters() {
- assertNull(Decoder.decode(null));
-
- String s = "azAZ019";
- assertEquals(s, Decoder.decode(s));
-
- s = "\"\\`{}|";
- assertEquals(s, Decoder.decode(s));
- }
-
- @Test
- public void asciiControl() {
- assertEquals("\u0000\b\t\n\r", Decoder.decode("%00%08%09%0a%0d"));
- }
-
- @Test
- public void asciiEncoded() {
- assertEquals("<>%&", Decoder.decode("%3c%3e%25%26"));
- assertEquals(":/?#[]@", Decoder.decode("%3a%2f%3f%23%5b%5d%40"));
- assertEquals(" !\"$'()*+,-.", Decoder.decode("%20%21%22%24%27%28%29%2A%2B%2C%2D%2E"));
- }
-
- @Test
- public void unicodeCharacters() {
- assertEquals("€", Decoder.decode("%E2%82%AC"));
- assertEquals("\uFDFC", Decoder.decode("%EF%B7%BC"));
- }
-
- @Test
- public void charactersOutsideBmp() {
- assertEquals(String.valueOf(Character.toChars(0x1F603)), Decoder.decode("%f0%9f%98%83"));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void wrongCharacter() {
- Decoder.decode("%20ä");
- }
-
- @Test(expected = NumberFormatException.class)
- public void wrongPercentNumber() {
- Decoder.decode("%-3");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void wrongPercentPercent() {
- Decoder.decode("%%a");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void unfinishedPercent() {
- Decoder.decode("%a");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void nullByte() {
- Decoder.decode("%\u0000ff");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/EncoderTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/EncoderTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/EncoderTest.java
deleted file mode 100644
index f22dea0..0000000
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/EncoderTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.commons;
-
-import static org.junit.Assert.assertEquals;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import org.apache.olingo.odata2.testutil.fit.BaseTest;
-import org.junit.Test;
-
-/**
- * Tests for percent-encoding.
- *
- */
-public class EncoderTest extends BaseTest {
-
- private final static String RFC3986_UNRESERVED = "-._~"; // + ALPHA + DIGIT
- private final static String RFC3986_GEN_DELIMS = ":/?#[]@";
- private final static String RFC3986_SUB_DELIMS = "!$&'()*+,;=";
- private final static String RFC3986_RESERVED = RFC3986_GEN_DELIMS + RFC3986_SUB_DELIMS;
-
- @Test
- public void asciiCharacters() {
- final String s = "azAZ019";
- assertEquals(s, Encoder.encode(s));
- assertEquals(s, Encoder.encode(s));
- }
-
- @Test
- public void asciiControl() {
- assertEquals("%08%09%0A%0D", Encoder.encode("\b\t\n\r"));
- }
-
- @Test
- public void unsafe() {
- assertEquals("%3C%3E%25%26", Encoder.encode("<>%&"));
- assertEquals("%22%5C%60%7B%7D%7C", Encoder.encode("\"\\`{}|"));
- }
-
- @Test
- public void rfc3986Unreserved() {
- assertEquals(RFC3986_UNRESERVED, Encoder.encode(RFC3986_UNRESERVED));
- }
-
- @Test
- public void rfc3986GenDelims() {
- assertEquals("%3A%2F%3F%23%5B%5D%40", Encoder.encode(RFC3986_GEN_DELIMS));
- }
-
- @Test
- public void rfc3986SubDelims() {
- assertEquals("%21%24%26'%28%29%2A%2B%2C%3B%3D", Encoder.encode(RFC3986_SUB_DELIMS));
- }
-
- @Test
- public void rfc3986Reserved() {
- assertEquals("%3A%2F%3F%23%5B%5D%40%21%24%26'%28%29%2A%2B%2C%3B%3D", Encoder.encode(RFC3986_RESERVED));
- }
-
- @Test
- public void unicodeCharacters() {
- assertEquals("%E2%82%AC", Encoder.encode("€"));
- assertEquals("%EF%B7%BC", Encoder.encode("\uFDFC")); // RIAL SIGN
- }
-
- @Test
- public void charactersOutsideBmp() {
- // Unicode characters outside the Basic Multilingual Plane are stored
- // in a Java String in two surrogate characters.
- final String s = String.valueOf(Character.toChars(0x1F603));
- assertEquals("%F0%9F%98%83", Encoder.encode(s));
- }
-
- @Test
- public void uriDecoding() throws URISyntaxException {
- final String decodedValue = RFC3986_UNRESERVED + RFC3986_RESERVED + "0..1..a..z..A..Z..@"
- + "\u2323\uFDFC" + String.valueOf(Character.toChars(0x1F603));
-
- final String encodedPath = Encoder.encode(decodedValue) + "/" + Encoder.encode(decodedValue);
- final String encodedQuery = Encoder.encode(decodedValue);
- final URI uri = new URI("http://host:80/" + encodedPath + "?" + encodedQuery + "=" + encodedQuery);
-
- assertEquals(uri.getPath(), "/" + decodedValue + "/" + decodedValue);
- assertEquals(uri.getQuery(), decodedValue + "=" + decodedValue);
-
- assertEquals(uri.getRawPath(), "/" + encodedPath);
- assertEquals(uri.getRawQuery(), encodedQuery + "=" + encodedQuery);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/57599da6/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/DebugInfoBodyTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/DebugInfoBodyTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/DebugInfoBodyTest.java
deleted file mode 100644
index 954a310..0000000
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/debug/DebugInfoBodyTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.debug;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.ep.util.JsonStreamWriter;
-import org.junit.Test;
-
-/**
- *
- */
-public class DebugInfoBodyTest {
-
- private static final String STRING_CONTENT = "StringContent";
- private static final String STRING_CONTENT_JSON = "\"" + STRING_CONTENT + "\"";
-
- @Test
- public void jsonStringContent() throws Exception {
- ODataResponse response = mock(ODataResponse.class);
- when(response.getEntity()).thenReturn(STRING_CONTENT);
- when(response.getContentHeader()).thenReturn(HttpContentType.APPLICATION_OCTET_STREAM);
- assertEquals(STRING_CONTENT_JSON, appendJson(response));
-
- when(response.getContentHeader()).thenReturn("image/png");
- assertEquals(STRING_CONTENT_JSON, appendJson(response));
- }
-
- @Test
- public void jsonInputStreamContent() throws Exception {
- ODataResponse response = mock(ODataResponse.class);
- ByteArrayInputStream in = new ByteArrayInputStream(STRING_CONTENT.getBytes());
- when(response.getEntity()).thenReturn(in);
- when(response.getContentHeader()).thenReturn(HttpContentType.APPLICATION_OCTET_STREAM);
- assertEquals(STRING_CONTENT_JSON, appendJson(response));
-
- in = new ByteArrayInputStream(STRING_CONTENT.getBytes());
- when(response.getEntity()).thenReturn(in);
- when(response.getContentHeader()).thenReturn("image/png");
- assertEquals("\"" + Base64.encodeBase64String(STRING_CONTENT.getBytes()) + "\"",
- appendJson(response));
- }
-
- @Test(expected = ClassCastException.class)
- public void jsonUnsupportedContent() throws Exception {
- ODataResponse response = mock(ODataResponse.class);
- when(response.getEntity()).thenReturn(new Object());
- when(response.getContentHeader()).thenReturn(HttpContentType.APPLICATION_OCTET_STREAM);
-
- appendJson(response);
- }
-
- private String appendJson(final ODataResponse response) throws IOException {
- Writer writer = new StringWriter();
- DebugInfoBody body = new DebugInfoBody(response);
- body.appendJson(new JsonStreamWriter(writer));
- return writer.toString();
- }
-}