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/10 19:04:10 UTC
[1/2] git commit: Refactoring for OLINGO-15 (JSON-Part)
Updated Branches:
refs/heads/master 44d62897a -> 060f9c656
Refactoring for OLINGO-15 (JSON-Part)
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/ce78a0b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/ce78a0b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/ce78a0b8
Branch: refs/heads/master
Commit: ce78a0b8fa0ba39c3d1785ef00bf185f23e07543
Parents: 44d6289
Author: Michael Bolz <mi...@apache.org>
Authored: Mon Sep 9 14:12:11 2013 +0200
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Sep 10 18:54:36 2013 +0200
----------------------------------------------------------------------
.../odata2/api/commons/HttpContentType.java | 1 +
.../olingo/odata2/core/ContentNegotiator.java | 13 +-
.../odata2/core/ODataExceptionWrapper.java | 3 +
.../olingo/odata2/core/ODataRequestHandler.java | 13 +-
.../odata2/core/ep/BasicEntityProvider.java | 7 +-
.../odata2/core/ep/JsonEntityProvider.java | 12 +-
.../processor/ODataSingleProcessorService.java | 8 +
.../core/ODataRequestHandlerValidationTest.java | 8 +
.../producer/JsonEntryEntityProducerTest.java | 25 ++-
.../core/ep/producer/JsonErrorProducerTest.java | 3 +-
.../ep/producer/JsonFeedEntityProducerTest.java | 8 +-
.../ep/producer/JsonFunctionImportTest.java | 12 +-
.../ep/producer/JsonLinkEntityProducerTest.java | 2 -
.../producer/JsonLinksEntityProducerTest.java | 10 +-
.../ep/producer/JsonPropertyProducerTest.java | 6 +-
.../JsonServiceDocumentProducerTest.java | 6 +-
.../odata2/fit/ref/ContentNegotiationTest.java | 5 +-
.../BasicContentNegotiationTest.java | 175 +++++++++++++++++++
18 files changed, 260 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-api/src/main/java/org/apache/olingo/odata2/api/commons/HttpContentType.java
----------------------------------------------------------------------
diff --git a/odata-api/src/main/java/org/apache/olingo/odata2/api/commons/HttpContentType.java b/odata-api/src/main/java/org/apache/olingo/odata2/api/commons/HttpContentType.java
index fbf788c..d274afb 100644
--- a/odata-api/src/main/java/org/apache/olingo/odata2/api/commons/HttpContentType.java
+++ b/odata-api/src/main/java/org/apache/olingo/odata2/api/commons/HttpContentType.java
@@ -38,6 +38,7 @@ public interface HttpContentType {
public static final String APPLICATION_ATOM_SVC_UTF8 = APPLICATION_ATOM_SVC + ";charset=utf-8";
public static final String APPLICATION_JSON = "application/json";
+ public static final String APPLICATION_JSON_VERBOSE = APPLICATION_JSON + ";odata=verbose";
public static final String APPLICATION_JSON_UTF8 = APPLICATION_JSON + ";charset=utf-8";
public static final String APPLICATION_JSON_UTF8_VERBOSE = APPLICATION_JSON_UTF8 + ";odata=verbose";
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/main/java/org/apache/olingo/odata2/core/ContentNegotiator.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/ContentNegotiator.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/ContentNegotiator.java
index 1e5cea2..9fe638c 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/ContentNegotiator.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/ContentNegotiator.java
@@ -68,7 +68,7 @@ public class ContentNegotiator {
private ContentType doContentNegotiationForFormat(final UriInfoImpl uriInfo, final List<ContentType> supportedContentTypes) throws ODataException {
validateFormatQuery(uriInfo);
ContentType formatContentType = mapFormat(uriInfo);
- formatContentType = formatContentType.receiveWithCharsetParameter(DEFAULT_CHARSET);
+ formatContentType = ensureCharset(formatContentType);
for (final ContentType contentType : supportedContentTypes) {
if (contentType.equals(formatContentType)) {
@@ -138,7 +138,7 @@ public class ContentNegotiator {
}
} else {
for (ContentType contentType : acceptedContentTypes) {
- contentType = contentType.receiveWithCharsetParameter(DEFAULT_CHARSET);
+ contentType = ensureCharset(contentType);
final ContentType match = contentType.match(supportedContentTypes);
if (match != null) {
return match;
@@ -149,4 +149,13 @@ public class ContentNegotiator {
throw new ODataNotAcceptableException(ODataNotAcceptableException.NOT_SUPPORTED_ACCEPT_HEADER.addContent(acceptedContentTypes.toString()));
}
+ private ContentType ensureCharset(ContentType contentType) {
+ if(ContentType.APPLICATION_ATOM_XML.isCompatible(contentType)
+ || ContentType.APPLICATION_ATOM_SVC.isCompatible(contentType)
+ || ContentType.APPLICATION_XML.isCompatible(contentType)) {
+ return contentType.receiveWithCharsetParameter(DEFAULT_CHARSET);
+ }
+ return contentType;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataExceptionWrapper.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataExceptionWrapper.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataExceptionWrapper.java
index ada0e30..38abe1d 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataExceptionWrapper.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataExceptionWrapper.java
@@ -111,6 +111,9 @@ public class ODataExceptionWrapper {
} else {
oDataResponse = EntityProvider.writeErrorDocument(errorContext);
}
+ if(!oDataResponse.containsHeader(org.apache.olingo.odata2.api.commons.HttpHeaders.CONTENT_TYPE)) {
+ oDataResponse = ODataResponse.fromResponse(oDataResponse).contentHeader(contentType).build();
+ }
return oDataResponse;
} catch (Exception e) {
ODataResponse response = ODataResponse.entity("Exception during error handling occured!")
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
index e938a1f..7a375d9 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
@@ -25,6 +25,7 @@ import java.util.Map;
import org.apache.olingo.odata2.api.ODataService;
import org.apache.olingo.odata2.api.ODataServiceFactory;
import org.apache.olingo.odata2.api.ODataServiceVersion;
+import org.apache.olingo.odata2.api.commons.HttpHeaders;
import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
import org.apache.olingo.odata2.api.commons.ODataHttpHeaders;
import org.apache.olingo.odata2.api.commons.ODataHttpMethod;
@@ -112,15 +113,21 @@ public class ODataRequestHandler {
odataResponse = dispatcher.dispatch(method, uriInfo, request.getBody(), request.getContentType(), acceptContentType);
context.stopRuntimeMeasurement(timingHandle2);
- final UriType uriType = uriInfo.getUriType();
- final String location = (method == ODataHttpMethod.POST && (uriType == UriType.URI1 || uriType == UriType.URI6B)) ? odataResponse.getIdLiteral() : null;
- final HttpStatusCodes s = odataResponse.getStatus() == null ? method == ODataHttpMethod.POST ? uriType == UriType.URI9 ? HttpStatusCodes.OK : uriType == UriType.URI7B ? HttpStatusCodes.NO_CONTENT : HttpStatusCodes.CREATED : method == ODataHttpMethod.PUT || method == ODataHttpMethod.PATCH || method == ODataHttpMethod.MERGE || method == ODataHttpMethod.DELETE ? HttpStatusCodes.NO_CONTENT : HttpStatusCodes.OK : odataResponse.getStatus();
ODataResponseBuilder extendedResponse = ODataResponse.fromResponse(odataResponse);
if (!odataResponse.containsHeader(ODataHttpHeaders.DATASERVICEVERSION)) {
extendedResponse = extendedResponse.header(ODataHttpHeaders.DATASERVICEVERSION, serverDataServiceVersion);
}
+ if(!odataResponse.containsHeader("Content-Type")) {
+ extendedResponse.header(HttpHeaders.CONTENT_TYPE, acceptContentType);
+ }
+
+ final UriType uriType = uriInfo.getUriType();
+ final String location = (method == ODataHttpMethod.POST && (uriType == UriType.URI1 || uriType == UriType.URI6B)) ? odataResponse.getIdLiteral() : null;
+ final HttpStatusCodes s = odataResponse.getStatus() == null ? method == ODataHttpMethod.POST ? uriType == UriType.URI9 ? HttpStatusCodes.OK : uriType == UriType.URI7B ? HttpStatusCodes.NO_CONTENT : HttpStatusCodes.CREATED : method == ODataHttpMethod.PUT || method == ODataHttpMethod.PATCH || method == ODataHttpMethod.MERGE || method == ODataHttpMethod.DELETE ? HttpStatusCodes.NO_CONTENT : HttpStatusCodes.OK : odataResponse.getStatus();
extendedResponse = extendedResponse.idLiteral(location).status(s);
+
+
odataResponse = extendedResponse.build();
} catch (final Exception e) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
index 931c5a6..eb964f0 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/BasicEntityProvider.java
@@ -63,7 +63,7 @@ import org.apache.olingo.odata2.core.ep.util.CircleStreamBuffer;
public class BasicEntityProvider {
/** Default used charset for writer and response content header */
- private static final String DEFAULT_CHARSET = "UTF-8";
+ private static final String DEFAULT_CHARSET = "utf-8";
/**
* Reads binary data from an input stream.
@@ -179,7 +179,7 @@ public class BasicEntityProvider {
}
/**
- * Write text value as content type <code>text/plain</code>.
+ * Write text value as content type <code>text/plain</code> with charset parameter set to {@value #DEFAULT_CHARSET}.
* @param value the string that is written to {@link ODataResponse}
* @return resulting {@link ODataResponse} with written text content
* @throws EntityProviderException
@@ -195,7 +195,8 @@ public class BasicEntityProvider {
}
builder.entity(stream);
}
- builder.contentHeader(ContentType.TEXT_PLAIN_CS_UTF_8.toContentTypeString());
+
+ builder.contentHeader(ContentType.TEXT_PLAIN.receiveWithCharsetParameter(DEFAULT_CHARSET).toContentTypeString());
return builder.build();
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/JsonEntityProvider.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/JsonEntityProvider.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/JsonEntityProvider.java
index 40cfd7a..7abdf5d 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/JsonEntityProvider.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/JsonEntityProvider.java
@@ -27,7 +27,6 @@ import java.util.Locale;
import java.util.Map;
import org.apache.olingo.odata2.api.ODataServiceVersion;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
import org.apache.olingo.odata2.api.commons.InlineCount;
import org.apache.olingo.odata2.api.commons.ODataHttpHeaders;
@@ -92,7 +91,6 @@ public class JsonEntityProvider implements ContentTypeBasedEntityProvider {
return ODataResponse.status(status)
.entity(buffer.getInputStream())
- .contentHeader(HttpContentType.APPLICATION_JSON)
.header(ODataHttpHeaders.DATASERVICEVERSION, ODataServiceVersion.V10)
.build();
} catch (Exception e) {
@@ -119,7 +117,6 @@ public class JsonEntityProvider implements ContentTypeBasedEntityProvider {
buffer.closeWrite();
return ODataResponse.entity(buffer.getInputStream())
- .contentHeader(HttpContentType.APPLICATION_JSON)
.header(ODataHttpHeaders.DATASERVICEVERSION, ODataServiceVersion.V10)
.build();
} catch (Exception e) {
@@ -141,7 +138,6 @@ public class JsonEntityProvider implements ContentTypeBasedEntityProvider {
buffer.closeWrite();
return ODataResponse.entity(buffer.getInputStream())
- .contentHeader(HttpContentType.APPLICATION_JSON)
.eTag(producer.getETag())
.idLiteral(producer.getLocation())
.build();
@@ -170,7 +166,6 @@ public class JsonEntityProvider implements ContentTypeBasedEntityProvider {
buffer.closeWrite();
return ODataResponse.entity(buffer.getInputStream())
- .contentHeader(HttpContentType.APPLICATION_JSON)
.header(ODataHttpHeaders.DATASERVICEVERSION, ODataServiceVersion.V10)
.build();
} catch (EntityProviderException e) {
@@ -193,7 +188,7 @@ public class JsonEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
buffer.closeWrite();
- return ODataResponse.entity(buffer.getInputStream()).contentHeader(HttpContentType.APPLICATION_JSON).build();
+ return ODataResponse.entity(buffer.getInputStream()).build();
} catch (EntityProviderException e) {
buffer.close();
throw e;
@@ -215,7 +210,6 @@ public class JsonEntityProvider implements ContentTypeBasedEntityProvider {
buffer.closeWrite();
return ODataResponse.entity(buffer.getInputStream())
- .contentHeader(HttpContentType.APPLICATION_JSON)
.header(ODataHttpHeaders.DATASERVICEVERSION, ODataServiceVersion.V10)
.build();
} catch (EntityProviderException e) {
@@ -238,7 +232,7 @@ public class JsonEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
buffer.closeWrite();
- ODataResponseBuilder response = ODataResponse.entity(buffer.getInputStream()).contentHeader(HttpContentType.APPLICATION_JSON);
+ ODataResponseBuilder response = ODataResponse.entity(buffer.getInputStream());
if (properties.getInlineCountType() != InlineCount.ALLPAGES) {
response = response.header(ODataHttpHeaders.DATASERVICEVERSION, ODataServiceVersion.V10);
}
@@ -261,7 +255,7 @@ public class JsonEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
buffer.closeWrite();
- return ODataResponse.entity(buffer.getInputStream()).contentHeader(HttpContentType.APPLICATION_JSON).build();
+ return ODataResponse.entity(buffer.getInputStream()).build();
} catch (EntityProviderException e) {
buffer.close();
throw e;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/main/java/org/apache/olingo/odata2/core/processor/ODataSingleProcessorService.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/processor/ODataSingleProcessorService.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/processor/ODataSingleProcessorService.java
index f5298c1..0aec7b5 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/processor/ODataSingleProcessorService.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/processor/ODataSingleProcessorService.java
@@ -213,6 +213,8 @@ public class ODataSingleProcessorService implements ODataService {
result.add(HttpContentType.APPLICATION_ATOM_XML_UTF8);
result.add(HttpContentType.APPLICATION_JSON_UTF8);
result.add(HttpContentType.APPLICATION_JSON_UTF8_VERBOSE);
+ result.add(HttpContentType.APPLICATION_JSON);
+ result.add(HttpContentType.APPLICATION_JSON_VERBOSE);
result.add(HttpContentType.APPLICATION_XML_UTF8);
} else if (processorFeature == FunctionImportProcessor.class
|| processorFeature == EntityLinkProcessor.class
@@ -222,6 +224,8 @@ public class ODataSingleProcessorService implements ODataService {
result.add(HttpContentType.APPLICATION_XML_UTF8);
result.add(HttpContentType.APPLICATION_JSON_UTF8);
result.add(HttpContentType.APPLICATION_JSON_UTF8_VERBOSE);
+ result.add(HttpContentType.APPLICATION_JSON);
+ result.add(HttpContentType.APPLICATION_JSON_VERBOSE);
} else if (processorFeature == EntityMediaProcessor.class
|| processorFeature == EntitySimplePropertyValueProcessor.class
|| processorFeature == FunctionImportValueProcessor.class) {
@@ -231,6 +235,8 @@ public class ODataSingleProcessorService implements ODataService {
result.add(HttpContentType.APPLICATION_ATOM_XML_UTF8);
result.add(HttpContentType.APPLICATION_JSON_UTF8);
result.add(HttpContentType.APPLICATION_JSON_UTF8_VERBOSE);
+ result.add(HttpContentType.APPLICATION_JSON);
+ result.add(HttpContentType.APPLICATION_JSON_VERBOSE);
result.add(HttpContentType.APPLICATION_XML_UTF8);
} else if (processorFeature == MetadataProcessor.class) {
result.add(HttpContentType.APPLICATION_XML_UTF8);
@@ -238,6 +244,8 @@ public class ODataSingleProcessorService implements ODataService {
result.add(HttpContentType.APPLICATION_ATOM_SVC_UTF8);
result.add(HttpContentType.APPLICATION_JSON_UTF8);
result.add(HttpContentType.APPLICATION_JSON_UTF8_VERBOSE);
+ result.add(HttpContentType.APPLICATION_JSON);
+ result.add(HttpContentType.APPLICATION_JSON_VERBOSE);
result.add(HttpContentType.APPLICATION_XML_UTF8);
} else {
throw new ODataNotImplementedException();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/test/java/org/apache/olingo/odata2/core/ODataRequestHandlerValidationTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ODataRequestHandlerValidationTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ODataRequestHandlerValidationTest.java
index 279bdd3..f8629cd 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ODataRequestHandlerValidationTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ODataRequestHandlerValidationTest.java
@@ -261,11 +261,15 @@ public class ODataRequestHandlerValidationTest extends BaseTest {
when(service.getSupportedContentTypes(EntityProcessor.class)).thenReturn(Arrays.asList(
HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8,
HttpContentType.APPLICATION_ATOM_XML_UTF8,
+ HttpContentType.APPLICATION_JSON,
+ HttpContentType.APPLICATION_JSON_VERBOSE,
HttpContentType.APPLICATION_JSON_UTF8,
HttpContentType.APPLICATION_JSON_UTF8_VERBOSE,
HttpContentType.APPLICATION_XML_UTF8));
final List<String> jsonAndXml = Arrays.asList(
+ HttpContentType.APPLICATION_JSON,
+ HttpContentType.APPLICATION_JSON_VERBOSE,
HttpContentType.APPLICATION_JSON_UTF8,
HttpContentType.APPLICATION_JSON_UTF8_VERBOSE,
HttpContentType.APPLICATION_XML_UTF8);
@@ -283,6 +287,8 @@ public class ODataRequestHandlerValidationTest extends BaseTest {
when(service.getSupportedContentTypes(EntitySetProcessor.class)).thenReturn(Arrays.asList(
HttpContentType.APPLICATION_ATOM_XML_FEED_UTF8,
HttpContentType.APPLICATION_ATOM_XML_UTF8,
+ HttpContentType.APPLICATION_JSON,
+ HttpContentType.APPLICATION_JSON_VERBOSE,
HttpContentType.APPLICATION_JSON_UTF8,
HttpContentType.APPLICATION_JSON_UTF8_VERBOSE,
HttpContentType.APPLICATION_XML_UTF8));
@@ -292,6 +298,8 @@ public class ODataRequestHandlerValidationTest extends BaseTest {
when(service.getSupportedContentTypes(ServiceDocumentProcessor.class)).thenReturn(Arrays.asList(
HttpContentType.APPLICATION_ATOM_SVC_UTF8,
+ HttpContentType.APPLICATION_JSON,
+ HttpContentType.APPLICATION_JSON_VERBOSE,
HttpContentType.APPLICATION_JSON_UTF8,
HttpContentType.APPLICATION_JSON_UTF8_VERBOSE,
HttpContentType.APPLICATION_XML_UTF8));
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
index 7dc1fcb..a39dcd2 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
@@ -33,7 +33,6 @@ import java.util.List;
import java.util.Map;
import org.apache.olingo.odata2.api.ODataCallback;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmProperty;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
@@ -74,7 +73,7 @@ public class JsonEntryEntityProducerTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeEntry(entitySet, teamData, DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -114,7 +113,7 @@ public class JsonEntryEntityProducerTest extends BaseTest {
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node).build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -136,7 +135,7 @@ public class JsonEntryEntityProducerTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeEntry(entitySet, photoData, DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -167,7 +166,7 @@ public class JsonEntryEntityProducerTest extends BaseTest {
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node).build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -212,7 +211,7 @@ public class JsonEntryEntityProducerTest extends BaseTest {
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1).callbacks(callbacks).build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
Map<String, Object> roomEntry = new Gson().fromJson(new InputStreamReader((InputStream) response.getEntity()), Map.class);
//remove d wrapper
@@ -253,7 +252,7 @@ public class JsonEntryEntityProducerTest extends BaseTest {
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1).callbacks(callbacks).build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
Map<String, Object> roomEntry = new Gson().fromJson(new InputStreamReader((InputStream) response.getEntity()), Map.class);
//remove d wrapper
@@ -295,7 +294,7 @@ public class JsonEntryEntityProducerTest extends BaseTest {
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1).callbacks(callbacks).build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -325,7 +324,7 @@ public class JsonEntryEntityProducerTest extends BaseTest {
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1).build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -390,7 +389,7 @@ public class JsonEntryEntityProducerTest extends BaseTest {
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1).callbacks(callbacks).build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -434,7 +433,7 @@ public class JsonEntryEntityProducerTest extends BaseTest {
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1).callbacks(callbacks).build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
Map<String, Object> buildingEntry = new Gson().fromJson(new InputStreamReader((InputStream) response.getEntity()), Map.class);
//remove d wrapper
@@ -477,7 +476,7 @@ public class JsonEntryEntityProducerTest extends BaseTest {
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1).callbacks(callbacks).build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
Map<String, Object> buildingEntry = new Gson().fromJson(new InputStreamReader((InputStream) response.getEntity()), Map.class);
//remove d wrapper
@@ -506,7 +505,7 @@ public class JsonEntryEntityProducerTest extends BaseTest {
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).expandSelectTree(node1).build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonErrorProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonErrorProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonErrorProducerTest.java
index e4b72d6..e641762 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonErrorProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonErrorProducerTest.java
@@ -19,6 +19,7 @@
package org.apache.olingo.odata2.core.ep.producer;
import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
import java.io.InputStream;
import java.util.Locale;
@@ -64,7 +65,7 @@ public class JsonErrorProducerTest {
ctx.setMessage(message);
ODataResponse response = new ProviderFacadeImpl().writeErrorDocument(ctx);
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
assertEquals(ODataServiceVersion.V10, response.getHeader(ODataHttpHeaders.DATASERVICEVERSION));
final String jsonErrorMessage = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertEquals("{\"error\":{\"code\":" + (errorCode == null ? "null" : "\"" + errorCode + "\"") + ","
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedEntityProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedEntityProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedEntityProducerTest.java
index f4f6be7..13a8f64 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedEntityProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFeedEntityProducerTest.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.InputStream;
import java.net.URI;
@@ -28,7 +29,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.commons.InlineCount;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
@@ -63,7 +63,7 @@ public class JsonFeedEntityProducerTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeFeed(entitySet, teamsData, DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -87,7 +87,7 @@ public class JsonFeedEntityProducerTest extends BaseTest {
.build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -108,7 +108,7 @@ public class JsonFeedEntityProducerTest extends BaseTest {
EntityProviderWriteProperties.serviceRoot(URI.create(BASE_URI)).nextLink("Rooms?$skiptoken=2").build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFunctionImportTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFunctionImportTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFunctionImportTest.java
index 575928e..3777ffa 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFunctionImportTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFunctionImportTest.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.InputStream;
import java.net.URI;
@@ -29,7 +30,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
import org.apache.olingo.odata2.api.processor.ODataResponse;
@@ -51,7 +51,7 @@ public class JsonFunctionImportTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeFunctionImport(functionImport, 42, null);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -71,7 +71,7 @@ public class JsonFunctionImportTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeFunctionImport(functionImport, locationData, null);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -89,7 +89,7 @@ public class JsonFunctionImportTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeFunctionImport(functionImport, Arrays.asList("1", "2", "3"), null);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -109,7 +109,7 @@ public class JsonFunctionImportTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeFunctionImport(functionImport, locations, null);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -133,7 +133,7 @@ public class JsonFunctionImportTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeFunctionImport(functionImport, employeeData, properties);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonLinkEntityProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonLinkEntityProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonLinkEntityProducerTest.java
index 715c225..ac7b71f 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonLinkEntityProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonLinkEntityProducerTest.java
@@ -26,7 +26,6 @@ import java.net.URI;
import java.util.HashMap;
import java.util.Map;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
import org.apache.olingo.odata2.api.processor.ODataResponse;
@@ -53,7 +52,6 @@ public class JsonLinkEntityProducerTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeLink(entitySet, employeeData, DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonLinksEntityProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonLinksEntityProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonLinksEntityProducerTest.java
index 65af870..36832ad 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonLinksEntityProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonLinksEntityProducerTest.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.InputStream;
import java.net.URI;
@@ -27,7 +28,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.commons.InlineCount;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
@@ -57,7 +57,7 @@ public class JsonLinksEntityProducerTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeLinks(entitySet, employeesData, DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -81,7 +81,7 @@ public class JsonLinksEntityProducerTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeLinks(entitySet, employeesData, DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -99,7 +99,7 @@ public class JsonLinksEntityProducerTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeLinks(entitySet, data, DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
@@ -122,7 +122,7 @@ public class JsonLinksEntityProducerTest extends BaseTest {
.inlineCountType(InlineCount.ALLPAGES).inlineCount(42).build());
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(json);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonPropertyProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonPropertyProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonPropertyProducerTest.java
index 80b6a3d..0a00f91 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonPropertyProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonPropertyProducerTest.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.InputStream;
import java.util.Arrays;
@@ -29,7 +30,6 @@ import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.olingo.odata2.api.ODataServiceVersion;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.commons.ODataHttpHeaders;
import org.apache.olingo.odata2.api.edm.EdmProperty;
import org.apache.olingo.odata2.api.processor.ODataResponse;
@@ -51,7 +51,7 @@ public class JsonPropertyProducerTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeProperty(property, "\"Игорь\tНиколаевич\tЛарионов\"");
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
assertEquals(ODataServiceVersion.V10, response.getHeader(ODataHttpHeaders.DATASERVICEVERSION));
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
@@ -69,7 +69,7 @@ public class JsonPropertyProducerTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeProperty(property, propertyValue);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
assertEquals(ODataServiceVersion.V10, response.getHeader(ODataHttpHeaders.DATASERVICEVERSION));
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonServiceDocumentProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonServiceDocumentProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonServiceDocumentProducerTest.java
index aea7b57..eaf4e8c 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonServiceDocumentProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonServiceDocumentProducerTest.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -28,7 +29,6 @@ import java.net.URI;
import java.util.Arrays;
import org.apache.olingo.odata2.api.ODataServiceVersion;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.commons.ODataHttpHeaders;
import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.api.edm.EdmEntitySetInfo;
@@ -52,7 +52,7 @@ public class JsonServiceDocumentProducerTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeServiceDocument(edm, "http://host:80/service/");
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
assertEquals(ODataServiceVersion.V10, response.getHeader(ODataHttpHeaders.DATASERVICEVERSION));
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
@@ -73,7 +73,7 @@ public class JsonServiceDocumentProducerTest extends BaseTest {
final ODataResponse response = new JsonEntityProvider().writeServiceDocument(edm, "http://host:80/service/");
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_JSON, response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
assertEquals(ODataServiceVersion.V10, response.getHeader(ODataHttpHeaders.DATASERVICEVERSION));
final String json = StringHelper.inputStreamToString((InputStream) response.getEntity());
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/ContentNegotiationTest.java
----------------------------------------------------------------------
diff --git a/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/ContentNegotiationTest.java b/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/ContentNegotiationTest.java
index 969f345..e590e1b 100644
--- a/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/ContentNegotiationTest.java
+++ b/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/ContentNegotiationTest.java
@@ -22,10 +22,9 @@ import static org.junit.Assert.assertTrue;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
-import org.junit.Test;
-
import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.junit.Test;
/**
*
@@ -47,7 +46,7 @@ public class ContentNegotiationTest extends AbstractRefTest {
@Test
public void formatJson() throws Exception {
final HttpResponse response = callUri("?$format=json");
- checkMediaType(response, HttpContentType.APPLICATION_JSON_UTF8);
+ checkMediaType(response, HttpContentType.APPLICATION_JSON);
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ce78a0b8/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/BasicContentNegotiationTest.java
----------------------------------------------------------------------
diff --git a/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/BasicContentNegotiationTest.java b/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/BasicContentNegotiationTest.java
new file mode 100644
index 0000000..529693c
--- /dev/null
+++ b/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/contentnegotiation/BasicContentNegotiationTest.java
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * 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.fit.ref.contentnegotiation;
+
+import static org.apache.olingo.odata2.api.commons.HttpContentType.APPLICATION_ATOM_XML;
+import static org.apache.olingo.odata2.api.commons.HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8;
+import static org.apache.olingo.odata2.api.commons.HttpContentType.APPLICATION_JSON;
+import static org.apache.olingo.odata2.api.commons.HttpContentType.APPLICATION_JSON_UTF8;
+import static org.apache.olingo.odata2.api.commons.HttpContentType.APPLICATION_XML;
+import static org.apache.olingo.odata2.api.commons.HttpContentType.APPLICATION_XML_UTF8;
+import static org.apache.olingo.odata2.api.commons.HttpContentType.TEXT_PLAIN;
+import static org.apache.olingo.odata2.api.commons.HttpContentType.TEXT_PLAIN_UTF8;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.net.URI;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.log4j.Logger;
+import org.apache.olingo.odata2.api.commons.HttpHeaders;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.core.commons.ContentType;
+import org.apache.olingo.odata2.testutil.helper.StringHelper;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class BasicContentNegotiationTest extends AbstractContentNegotiationTest {
+
+ private static final Logger LOG = Logger.getLogger(BasicContentNegotiationTest.class);
+
+ @Test
+ public void acceptHeaderAppAtomXml() throws Exception {
+ performRequestAndValidateResponseForAcceptHeader("Rooms('1')", APPLICATION_ATOM_XML, APPLICATION_ATOM_XML_ENTRY_UTF8);
+ }
+
+ @Test
+ public void acceptHeaderAppXml() throws Exception {
+ performRequestAndValidateResponseForAcceptHeader("Rooms('1')", APPLICATION_XML, APPLICATION_XML_UTF8);
+ }
+
+ @Test
+ public void acceptHeaderAppXmlCharsetUtf8() throws Exception {
+ performRequestAndValidateResponseForAcceptHeader("Rooms('1')", APPLICATION_XML_UTF8, APPLICATION_XML_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Employees('1')", APPLICATION_XML_UTF8, APPLICATION_XML_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Employees('1')/$count", APPLICATION_XML_UTF8, TEXT_PLAIN_UTF8);
+ }
+
+ @Test
+ public void acceptHeaderToContentTypeODataVerboseParameter() throws Exception {
+ final String parameter = ";odata=verbose";
+ performRequestAndValidateResponseForAcceptHeader("Employees('1')", APPLICATION_JSON + parameter, APPLICATION_JSON + parameter);
+ performRequestAndValidateResponseForAcceptHeader("Employees('1')", APPLICATION_JSON_UTF8 + parameter, APPLICATION_JSON_UTF8 + parameter);
+// performRequestAndValidateResponseForAcceptHeader("Rooms('1')", APPLICATION_XML + parameter, APPLICATION_XML_UTF8 + parameter);
+// performRequestAndValidateResponseForAcceptHeader("Employees('1')", APPLICATION_XML_UTF8 + parameter, APPLICATION_XML_UTF8 + parameter);
+ performRequestAndValidateResponseForAcceptHeader("Employees('1')/$count", APPLICATION_XML_UTF8 + parameter, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Employees('1')/$count", APPLICATION_JSON + parameter, TEXT_PLAIN_UTF8 );
+ performRequestAndValidateResponseForAcceptHeader("Buildings('1')/$count", APPLICATION_XML_UTF8 + parameter, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Buildings('1')/$count", APPLICATION_JSON + parameter, TEXT_PLAIN_UTF8);
+
+ performRequestAndValidateResponseForAcceptHeader("Employees/$count", APPLICATION_XML_UTF8 + parameter, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Employees/$count", APPLICATION_JSON + parameter, TEXT_PLAIN_UTF8 );
+ performRequestAndValidateResponseForAcceptHeader("Buildings/$count", APPLICATION_XML_UTF8 + parameter, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Buildings/$count", APPLICATION_JSON + parameter, TEXT_PLAIN_UTF8);
+ }
+
+ @Test
+ public void acceptHeaderToContentTypeIgnoredAcceptHeaders() throws Exception {
+ performRequestAndValidateResponseForAcceptHeader("Employees('1')/$count", APPLICATION_XML_UTF8, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Employees('1')/$count", APPLICATION_JSON, TEXT_PLAIN_UTF8 );
+ performRequestAndValidateResponseForAcceptHeader("Buildings('1')/$count", APPLICATION_XML_UTF8, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Buildings('1')/$count", APPLICATION_JSON, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Buildings('1')/$count", TEXT_PLAIN_UTF8, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Buildings('1')/$count", TEXT_PLAIN, TEXT_PLAIN_UTF8);
+
+ performRequestAndValidateResponseForAcceptHeader("Employees/$count", APPLICATION_XML_UTF8, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Employees/$count", APPLICATION_JSON, TEXT_PLAIN_UTF8 );
+ performRequestAndValidateResponseForAcceptHeader("Buildings/$count", APPLICATION_XML_UTF8, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Buildings/$count", APPLICATION_JSON, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Buildings/$count", TEXT_PLAIN_UTF8, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Buildings/$count", TEXT_PLAIN, TEXT_PLAIN_UTF8);
+
+ final String parameter = ";someUnknownParameter=withAValue";
+ performRequestAndValidateResponseForAcceptHeader("Employees('1')/$count", APPLICATION_XML_UTF8 + parameter, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Employees('1')/$count", APPLICATION_JSON + parameter, TEXT_PLAIN_UTF8 );
+ performRequestAndValidateResponseForAcceptHeader("Buildings('1')/$count", APPLICATION_XML_UTF8 + parameter, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Buildings('1')/$count", APPLICATION_JSON + parameter, TEXT_PLAIN_UTF8);
+
+ performRequestAndValidateResponseForAcceptHeader("Employees/$count", APPLICATION_XML_UTF8 + parameter, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Employees/$count", APPLICATION_JSON + parameter, TEXT_PLAIN_UTF8 );
+ performRequestAndValidateResponseForAcceptHeader("Buildings/$count", APPLICATION_XML_UTF8 + parameter, TEXT_PLAIN_UTF8);
+ performRequestAndValidateResponseForAcceptHeader("Buildings/$count", APPLICATION_JSON + parameter, TEXT_PLAIN_UTF8);
+ }
+
+ @Test
+ public void acceptHeaderToContentTypeNotAcceptable() throws Exception {
+ final String parameterUnknown = ";someUnknownParameter=withAValue";
+ performRequestAndValidateResponseForNotAcceptable("Employees('1')", APPLICATION_JSON + parameterUnknown);
+ performRequestAndValidateResponseForNotAcceptable("Employees('1')", APPLICATION_JSON_UTF8 + parameterUnknown);
+ performRequestAndValidateResponseForNotAcceptable("Rooms('1')", APPLICATION_XML + parameterUnknown);
+ performRequestAndValidateResponseForNotAcceptable("Employees('1')", APPLICATION_XML_UTF8 + parameterUnknown);
+ }
+
+ /**
+ *
+ * @param endPointPostfix
+ * @param requestAcceptHeader
+ * @param expectedResponseContentType
+ * @throws IOException
+ * @throws ClientProtocolException
+ */
+ private void performRequestAndValidateResponseForAcceptHeader(String endPointPostfix, String requestAcceptHeader, String expectedResponseContentType) throws IOException, ClientProtocolException {
+ HttpGet get = new HttpGet(URI.create(getEndpoint() + endPointPostfix));
+ get.setHeader(HttpHeaders.ACCEPT, requestAcceptHeader);
+ final HttpResponse response = new DefaultHttpClient().execute(get);
+
+ try {
+ assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode());
+ final String contentType = response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
+ assertEquals(ContentType.create(expectedResponseContentType), ContentType.create(contentType));
+ assertNotNull(StringHelper.inputStreamToString(response.getEntity().getContent()));
+ } catch (AssertionError e) {
+ LOG.debug("Response: \n#############\n#\n\n" +
+ StringHelper.inputStreamToString(response.getEntity().getContent()) + "\n\n#\n####################");
+ throw e;
+ }
+ }
+
+ /**
+ *
+ * @param endPointPostfix
+ * @param requestAcceptHeader
+ * @param expectedResponseContentType
+ * @throws IOException
+ * @throws ClientProtocolException
+ */
+ private void performRequestAndValidateResponseForNotAcceptable(String endPointPostfix, String requestAcceptHeader) throws IOException, ClientProtocolException {
+ HttpGet get = new HttpGet(URI.create(getEndpoint() + endPointPostfix));
+ get.setHeader(HttpHeaders.ACCEPT, requestAcceptHeader);
+ final HttpResponse response = new DefaultHttpClient().execute(get);
+
+ final String contentType = response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue();
+// assertEquals(expectedResponseContentType, contentType);
+ try {
+
+ assertEquals(ContentType.APPLICATION_XML, ContentType.create(contentType));
+ assertNotNull(StringHelper.inputStreamToString(response.getEntity().getContent()));
+ } catch (AssertionError e) {
+ LOG.debug("Response: \n#############\n#\n\n" +
+ StringHelper.inputStreamToString(response.getEntity().getContent()) + "\n\n#\n####################");
+ throw e;
+ }
+ }
+}
[2/2] git commit: Refactoring for OLINGO-15 (ATOM/XML-Part)
Posted by mi...@apache.org.
Refactoring for OLINGO-15 (ATOM/XML-Part)
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/060f9c65
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/060f9c65
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/060f9c65
Branch: refs/heads/master
Commit: 060f9c6569eab280f60a3e67300422a48c1a432d
Parents: ce78a0b
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Sep 10 16:08:33 2013 +0200
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Sep 10 18:55:58 2013 +0200
----------------------------------------------------------------------
.../olingo/odata2/core/ODataRequestHandler.java | 35 +++++++++++--
.../olingo/odata2/core/commons/ContentType.java | 5 +-
.../odata2/core/ep/AtomEntityProvider.java | 29 +++--------
.../odata2/core/ep/ProviderFacadeImplTest.java | 2 +-
.../core/ep/producer/AtomEntryProducerTest.java | 5 +-
.../core/ep/producer/AtomFeedProducerTest.java | 5 +-
.../core/ep/producer/XmlErrorProducerTest.java | 3 +-
.../core/ep/producer/XmlExpandProducerTest.java | 5 +-
.../core/ep/producer/XmlFunctionImportTest.java | 13 +++--
.../ep/producer/XmlLinkEntityProducerTest.java | 5 +-
.../ep/producer/XmlLinksEntityProducerTest.java | 5 +-
.../ep/producer/XmlPropertyProducerTest.java | 20 ++++---
.../core/ep/producer/XmlSelectProducerTest.java | 5 +-
.../odata2/fit/ref/EntryXmlChangeTest.java | 55 +++++++++++++++++++-
14 files changed, 125 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
index 7a375d9..cf09bb3 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
@@ -19,6 +19,7 @@
package org.apache.olingo.odata2.core;
import java.util.Arrays;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -119,7 +120,7 @@ public class ODataRequestHandler {
extendedResponse = extendedResponse.header(ODataHttpHeaders.DATASERVICEVERSION, serverDataServiceVersion);
}
if(!odataResponse.containsHeader("Content-Type")) {
- extendedResponse.header(HttpHeaders.CONTENT_TYPE, acceptContentType);
+ setContentType(extendedResponse, acceptContentType, method, uriInfo.getUriType());
}
final UriType uriType = uriInfo.getUriType();
@@ -127,9 +128,7 @@ public class ODataRequestHandler {
final HttpStatusCodes s = odataResponse.getStatus() == null ? method == ODataHttpMethod.POST ? uriType == UriType.URI9 ? HttpStatusCodes.OK : uriType == UriType.URI7B ? HttpStatusCodes.NO_CONTENT : HttpStatusCodes.CREATED : method == ODataHttpMethod.PUT || method == ODataHttpMethod.PATCH || method == ODataHttpMethod.MERGE || method == ODataHttpMethod.DELETE ? HttpStatusCodes.NO_CONTENT : HttpStatusCodes.OK : odataResponse.getStatus();
extendedResponse = extendedResponse.idLiteral(location).status(s);
-
odataResponse = extendedResponse.build();
-
} catch (final Exception e) {
exception = e;
odataResponse = new ODataExceptionWrapper(context, request.getQueryParameters(), request.getAcceptHeaders()).wrapInExceptionResponse(e);
@@ -140,6 +139,24 @@ public class ODataRequestHandler {
return debugValue == null ? odataResponse : new ODataDebugResponseWrapper(context, odataResponse, uriInfo, exception, debugValue).wrapResponse();
}
+ private void setContentType(ODataResponseBuilder extendedResponse, String acceptContentType, ODataHttpMethod method, UriType uriType) {
+ ContentType contentType = ContentType.parse(acceptContentType);
+ if(contentType != null && contentType.getODataFormat() == ODataFormat.ATOM) {
+ if(uriType == UriType.URI1 || uriType == UriType.URI6B) {
+ if(ODataHttpMethod.GET.equals(method)) {
+ contentType = ContentType.create(contentType, ContentType.PARAMETER_TYPE, "feed");
+ } else {
+ contentType = ContentType.create(contentType, ContentType.PARAMETER_TYPE, "entry");
+ }
+ } else if(uriType == UriType.URI2 || uriType == UriType.URI6A) {
+ contentType = ContentType.create(contentType, ContentType.PARAMETER_TYPE, "entry");
+ }
+ extendedResponse.header(HttpHeaders.CONTENT_TYPE, contentType.toContentTypeString());
+ } else {
+ extendedResponse.header(HttpHeaders.CONTENT_TYPE, acceptContentType);
+ }
+ }
+
/**
* Do the content negotiation based on requested content type (in HTTP accept header) and from {@link ODataService}
* supported content types (via {@link ODataService#getSupportedContentTypes(Class)}).
@@ -152,11 +169,21 @@ public class ODataRequestHandler {
private String doContentNegotiation(final ODataRequest request, UriInfoImpl uriInfo) throws ODataException {
if(uriInfo.isCount() || uriInfo.isValue()) {
return request.getRequestHeaderValue("Accept");
+ } else if(ODataHttpMethod.POST.equals(request.getMethod()) &&
+ (uriInfo.getUriType() == UriType.URI1 || uriInfo.getUriType() == UriType.URI6B)) {
+
+ List<String> supportedContentTypes = new LinkedList<String>(getSupportedContentTypes(uriInfo));
+ supportedContentTypes.add(0, ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString());
+ supportedContentTypes.add(1, ContentType.APPLICATION_ATOM_XML_ENTRY.toContentTypeString());
+ supportedContentTypes.remove(ContentType.APPLICATION_ATOM_XML_FEED.toContentTypeString());
+ supportedContentTypes.remove(ContentType.APPLICATION_ATOM_XML_FEED_CS_UTF_8.toContentTypeString());
+
+ return new ContentNegotiator().doContentNegotiation(uriInfo, request.getAcceptHeaders(), supportedContentTypes);
} else {
return new ContentNegotiator().doContentNegotiation(uriInfo, request.getAcceptHeaders(), getSupportedContentTypes(uriInfo));
}
}
-
+
private String getServerDataServiceVersion() throws ODataException {
return service.getVersion() == null ? ODataServiceVersion.V20 : service.getVersion();
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java
index a1499f8..80ab262 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java
@@ -96,6 +96,7 @@ public class ContentType {
public static final String PARAMETER_CHARSET = "charset";
public static final String PARAMETER_ODATA = "odata";
public static final String PARAMETER_Q = "q";
+ public static final String PARAMETER_TYPE = "type";
public static final String CHARSET_UTF_8 = "utf-8";
public static final ContentType WILDCARD = new ContentType(MEDIA_TYPE_WILDCARD, MEDIA_TYPE_WILDCARD);
@@ -104,9 +105,9 @@ public class ContentType {
public static final ContentType APPLICATION_XML_CS_UTF_8 = ContentType.create(APPLICATION_XML, PARAMETER_CHARSET, CHARSET_UTF_8);
public static final ContentType APPLICATION_ATOM_XML = new ContentType("application", "atom+xml", ODataFormat.ATOM);
public static final ContentType APPLICATION_ATOM_XML_CS_UTF_8 = ContentType.create(APPLICATION_ATOM_XML, PARAMETER_CHARSET, CHARSET_UTF_8);
- public static final ContentType APPLICATION_ATOM_XML_ENTRY = new ContentType("application", "atom+xml", ODataFormat.ATOM, parameterMap("type", "entry"));
+ public static final ContentType APPLICATION_ATOM_XML_ENTRY = new ContentType("application", "atom+xml", ODataFormat.ATOM, parameterMap(PARAMETER_TYPE, "entry"));
public static final ContentType APPLICATION_ATOM_XML_ENTRY_CS_UTF_8 = ContentType.create(APPLICATION_ATOM_XML_ENTRY, PARAMETER_CHARSET, CHARSET_UTF_8);
- public static final ContentType APPLICATION_ATOM_XML_FEED = new ContentType("application", "atom+xml", ODataFormat.ATOM, parameterMap("type", "feed"));
+ public static final ContentType APPLICATION_ATOM_XML_FEED = new ContentType("application", "atom+xml", ODataFormat.ATOM, parameterMap(PARAMETER_TYPE, "feed"));
public static final ContentType APPLICATION_ATOM_XML_FEED_CS_UTF_8 = ContentType.create(APPLICATION_ATOM_XML_FEED, PARAMETER_CHARSET, CHARSET_UTF_8);
public static final ContentType APPLICATION_ATOM_SVC = new ContentType("application", "atomsvc+xml", ODataFormat.ATOM);
public static final ContentType APPLICATION_ATOM_SVC_CS_UTF_8 = ContentType.create(APPLICATION_ATOM_SVC, PARAMETER_CHARSET, CHARSET_UTF_8);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
index 41a71ec..bffbe70 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
@@ -73,7 +73,6 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
/** Default used charset for writer and response content header */
private static final String DEFAULT_CHARSET = ContentType.CHARSET_UTF_8;
private static final String XML_VERSION = "1.0";
- private final ODataFormat odataFormat;
public AtomEntityProvider() throws EntityProviderException {
this(ODataFormat.ATOM);
@@ -84,12 +83,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
}
public AtomEntityProvider(final ODataFormat odataFormat) throws EntityProviderException {
- switch (odataFormat) {
- case ATOM:
- case XML:
- this.odataFormat = odataFormat;
- break;
- default:
+ if(odataFormat != ODataFormat.ATOM && odataFormat != ODataFormat.XML) {
throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT.addContent("Got unsupported ODataFormat '" + odataFormat + "'."));
}
}
@@ -120,7 +114,6 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
csb.closeWrite();
ODataResponseBuilder response = ODataResponse.entity(csb.getInputStream())
- .contentHeader(ContentType.APPLICATION_XML.toContentTypeString())
.header(ODataHttpHeaders.DATASERVICEVERSION, ODataServiceVersion.V10)
.status(status);
return response.build();
@@ -150,7 +143,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
csb.closeWrite();
ODataResponse response = ODataResponse.entity(csb.getInputStream())
- .contentHeader(ContentType.APPLICATION_ATOM_SVC_CS_UTF_8.toContentTypeString())
+ .contentHeader(ContentType.APPLICATION_ATOM_SVC.receiveWithCharsetParameter(DEFAULT_CHARSET).toContentTypeString())
.build();
return response;
@@ -180,7 +173,6 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
csb.closeWrite();
ODataResponseBuilder response = ODataResponse.entity(csb.getInputStream())
- .contentHeader(getContentHeader(ContentType.APPLICATION_ATOM_XML_ENTRY))
.eTag(as.getETag())
.idLiteral(as.getLocation());
return response.build();
@@ -213,7 +205,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
csb.closeWrite();
- return ODataResponse.entity(csb.getInputStream()).contentHeader(getContentHeader(ContentType.APPLICATION_XML)).build();
+ return ODataResponse.entity(csb.getInputStream()).build();
} catch (EntityProviderException e) {
csb.close();
throw e;
@@ -239,7 +231,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
csb.closeWrite();
- ODataResponse response = ODataResponse.entity(csb.getInputStream()).contentHeader(getContentHeader(ContentType.APPLICATION_ATOM_XML_FEED)).build();
+ ODataResponse response = ODataResponse.entity(csb.getInputStream()).build();
return response;
} catch (EntityProviderException e) {
csb.close();
@@ -250,13 +242,6 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
}
}
- private String getContentHeader(final ContentType mediaType) {
- if (odataFormat == ODataFormat.XML) {
- return ContentType.APPLICATION_XML_CS_UTF_8.toContentTypeString();
- }
- return ContentType.create(mediaType, ContentType.PARAMETER_CHARSET, DEFAULT_CHARSET).toContentTypeString();
- }
-
@Override
public ODataResponse writeLink(final EdmEntitySet entitySet, final Map<String, Object> data, final EntityProviderWriteProperties properties) throws EntityProviderException {
CircleStreamBuffer csb = new CircleStreamBuffer();
@@ -273,7 +258,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
csb.closeWrite();
- return ODataResponse.entity(csb.getInputStream()).contentHeader(getContentHeader(ContentType.APPLICATION_XML)).build();
+ return ODataResponse.entity(csb.getInputStream()).build();
} catch (EntityProviderException e) {
csb.close();
throw e;
@@ -300,7 +285,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
csb.closeWrite();
- return ODataResponse.entity(csb.getInputStream()).contentHeader(getContentHeader(ContentType.APPLICATION_XML)).build();
+ return ODataResponse.entity(csb.getInputStream()).build();
} catch (EntityProviderException e) {
csb.close();
throw e;
@@ -323,7 +308,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
csb.closeWrite();
- return ODataResponse.entity(csb.getInputStream()).contentHeader(getContentHeader(ContentType.APPLICATION_XML)).build();
+ return ODataResponse.entity(csb.getInputStream()).build();
} catch (EntityProviderException e) {
csb.close();
throw e;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImplTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImplTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImplTest.java
index 08f83d8..c3820c5 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImplTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImplTest.java
@@ -166,7 +166,7 @@ public class ProviderFacadeImplTest {
public void writeProperty() throws Exception {
final EdmProperty property = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("EntryDate");
final ODataResponse result = new ProviderFacadeImpl().writeProperty(HttpContentType.APPLICATION_XML, property, 987654321000L);
- assertEquals(HttpContentType.APPLICATION_XML_UTF8, result.getContentHeader());
+ assertNull("EntityProvider should not set content header", result.getContentHeader());
assertTrue(StringHelper.inputStreamToString((InputStream) result.getEntity())
.endsWith("\">2001-04-19T04:25:21</EntryDate>"));
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
index 92fc37a..efcab4f 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
@@ -23,6 +23,7 @@ import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -301,7 +302,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
private String verifyResponse(final ODataResponse response) throws IOException {
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString(), response.getContentHeader());
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
String xmlString = StringHelper.inputStreamToString((InputStream) response.getEntity());
return xmlString;
}
@@ -567,7 +568,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString(), response.getContentHeader());
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
assertEquals("W/\"<\">.3\"", response.getETag());
String xmlString = StringHelper.inputStreamToString((InputStream) response.getEntity());
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
index 3fe183d..7d1d957 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
@@ -21,8 +21,8 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -36,7 +36,6 @@ import org.apache.olingo.odata2.api.ep.EntityProviderException;
import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
import org.apache.olingo.odata2.api.processor.ODataResponse;
import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.core.ep.AtomEntityProvider;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
@@ -123,7 +122,7 @@ public class AtomFeedProducerTest extends AbstractProviderTest {
private String verifyResponse(final ODataResponse response) throws IOException {
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_ATOM_XML_FEED_CS_UTF_8.toContentTypeString(), response.getContentHeader());
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
String xmlString = StringHelper.inputStreamToString((InputStream) response.getEntity());
return xmlString;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlErrorProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlErrorProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlErrorProducerTest.java
index 9421eae..6049ccc 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlErrorProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlErrorProducerTest.java
@@ -23,6 +23,7 @@ import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.io.InputStream;
@@ -227,7 +228,7 @@ public class XmlErrorProducerTest extends AbstractXmlProducerTestHelper {
private String verifyResponse(final ODataResponse response) throws IOException {
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toContentTypeString(), response.getContentHeader());
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
assertEquals(expectedStatus, response.getStatus());
assertNotNull(response.getHeader(ODataHttpHeaders.DATASERVICEVERSION));
assertEquals(ODataServiceVersion.V10, response.getHeader(ODataHttpHeaders.DATASERVICEVERSION));
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlExpandProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlExpandProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlExpandProducerTest.java
index 30fafef..c8221e1 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlExpandProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlExpandProducerTest.java
@@ -20,8 +20,8 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.io.InputStream;
@@ -51,7 +51,6 @@ import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
import org.apache.olingo.odata2.api.uri.PathSegment;
import org.apache.olingo.odata2.api.uri.UriInfo;
import org.apache.olingo.odata2.core.ODataPathSegmentImpl;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.core.ep.AtomEntityProvider;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
@@ -399,7 +398,7 @@ public class XmlExpandProducerTest extends AbstractProviderTest {
private String verifyResponse(final ODataResponse response) throws IOException {
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString(), response.getContentHeader());
+ assertNull("EntitypProvider should not set content header", response.getContentHeader());
String xmlString = StringHelper.inputStreamToString((InputStream) response.getEntity());
return xmlString;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlFunctionImportTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlFunctionImportTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlFunctionImportTest.java
index ecc6f0a..126a7b4 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlFunctionImportTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlFunctionImportTest.java
@@ -20,15 +20,14 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.InputStream;
import java.util.Arrays;
import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
import org.apache.olingo.odata2.testutil.mock.MockFacade;
@@ -50,7 +49,7 @@ public class XmlFunctionImportTest extends AbstractProviderTest {
final ODataResponse response = createAtomEntityProvider().writeFunctionImport(functionImport, employeeData.get("Age"), DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -66,7 +65,7 @@ public class XmlFunctionImportTest extends AbstractProviderTest {
final ODataResponse response = createAtomEntityProvider().writeFunctionImport(functionImport, employeeData.get("Location"), DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -83,7 +82,7 @@ public class XmlFunctionImportTest extends AbstractProviderTest {
final ODataResponse response = createAtomEntityProvider().writeFunctionImport(functionImport, Arrays.asList("1", "2", "3"), DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -101,7 +100,7 @@ public class XmlFunctionImportTest extends AbstractProviderTest {
final ODataResponse response = createAtomEntityProvider().writeFunctionImport(functionImport, Arrays.asList(employeeData.get("Location")), DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -119,7 +118,7 @@ public class XmlFunctionImportTest extends AbstractProviderTest {
final ODataResponse response = createAtomEntityProvider().writeFunctionImport(functionImport, employeeData, DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString(), response.getContentHeader());
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinkEntityProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinkEntityProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinkEntityProducerTest.java
index c9c40db..9dd2a27 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinkEntityProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinkEntityProducerTest.java
@@ -20,14 +20,13 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.InputStream;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
import org.apache.olingo.odata2.testutil.mock.MockFacade;
@@ -49,7 +48,7 @@ public class XmlLinkEntityProducerTest extends AbstractProviderTest {
final ODataResponse content = createAtomEntityProvider().writeLink(entitySet, employeeData, DEFAULT_PROPERTIES);
assertNotNull(content);
assertNotNull(content.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", content.getContentHeader());
+ assertNull("EntitypProvider should not set content header", content.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) content.getEntity());
assertNotNull(xml);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinksEntityProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinksEntityProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinksEntityProducerTest.java
index 34292c3..8fa36ff 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinksEntityProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinksEntityProducerTest.java
@@ -20,15 +20,14 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.InputStream;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
import org.apache.olingo.odata2.testutil.mock.MockFacade;
@@ -51,7 +50,7 @@ public class XmlLinksEntityProducerTest extends AbstractProviderTest {
final ODataResponse response = createAtomEntityProvider().writeLinks(entitySet, roomsData, DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyProducerTest.java
index a0e13e6..06690d1 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyProducerTest.java
@@ -20,17 +20,15 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.InputStream;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.edm.EdmEntityType;
import org.apache.olingo.odata2.api.edm.EdmProperty;
import org.apache.olingo.odata2.api.edm.EdmTyped;
import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.core.ep.AtomEntityProvider;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
@@ -56,7 +54,7 @@ public class XmlPropertyProducerTest extends AbstractProviderTest {
ODataResponse response = s.writeProperty(edmProperty, employeeData.get("EmployeeId"));
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+
String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -75,7 +73,7 @@ public class XmlPropertyProducerTest extends AbstractProviderTest {
ODataResponse response = s.writeProperty(edmProperty, employeeData.get("Age"));
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+
String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -93,7 +91,7 @@ public class XmlPropertyProducerTest extends AbstractProviderTest {
ODataResponse response = s.writeProperty(edmProperty, employeeData.get("ImageUrl"));
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+
String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -108,8 +106,8 @@ public class XmlPropertyProducerTest extends AbstractProviderTest {
ODataResponse response = createAtomEntityProvider().writeProperty(property, photoData.get("Image"));
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_XML_UTF8, response.getContentHeader());
-
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
+
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
assertXpathExists("/d:Image", xml);
@@ -123,8 +121,8 @@ public class XmlPropertyProducerTest extends AbstractProviderTest {
ODataResponse response = createAtomEntityProvider().writeProperty(property, photoData.get("BinaryData"));
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_XML_UTF8, response.getContentHeader());
-
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
+
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
assertXpathExists("/d:BinaryData", xml);
@@ -143,7 +141,7 @@ public class XmlPropertyProducerTest extends AbstractProviderTest {
ODataResponse response = s.writeProperty(edmProperty, employeeData.get("Location"));
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+
String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlSelectProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlSelectProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlSelectProducerTest.java
index 8c0f98c..b762e68 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlSelectProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlSelectProducerTest.java
@@ -20,8 +20,8 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.io.InputStream;
@@ -38,7 +38,6 @@ import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
import org.apache.olingo.odata2.api.uri.PathSegment;
import org.apache.olingo.odata2.api.uri.UriInfo;
import org.apache.olingo.odata2.core.ODataPathSegmentImpl;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.core.ep.AtomEntityProvider;
import org.apache.olingo.odata2.core.uri.ExpandSelectTreeCreator;
@@ -287,7 +286,7 @@ public class XmlSelectProducerTest extends AbstractProviderTest {
private String verifyResponse(final ODataResponse response) throws IOException {
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString(), response.getContentHeader());
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
String xmlString = StringHelper.inputStreamToString((InputStream) response.getEntity());
return xmlString;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java
----------------------------------------------------------------------
diff --git a/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java b/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java
index 67304f8..343001e 100644
--- a/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java
+++ b/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java
@@ -25,14 +25,13 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import org.apache.http.HttpResponse;
-import org.junit.Test;
-
import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.commons.HttpHeaders;
import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
import org.apache.olingo.odata2.api.commons.ODataHttpMethod;
import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
+import org.junit.Test;
/**
* Tests employing the reference scenario changing entities in XML format.
@@ -88,6 +87,58 @@ public class EntryXmlChangeTest extends AbstractRefXmlTest {
}
@Test
+ public void createWithAcceptHeaderEntry() throws Exception {
+ // Create an entry for a type that has no media resource.
+ String requestBody = getBody(callUri("Teams('1')"))
+ .replace("'1'", "'9'")
+ .replace("Id>1", "Id>9")
+ .replace("Team 1", "Team X")
+ .replaceAll("<link.+?/>", "");
+ String requestContentType = HttpContentType.APPLICATION_ATOM_XML_ENTRY;
+ HttpStatusCodes expectedStatusCode = HttpStatusCodes.CREATED;
+ String headerName = "Accept";
+ String headerValue = "application/atom+xml;type=entry";
+ HttpResponse response = callUri(ODataHttpMethod.POST, "Teams()", headerName, headerValue, requestBody, requestContentType, expectedStatusCode );
+
+ checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry");
+ assertEquals(getEndpoint() + "Teams('4')", response.getFirstHeader(HttpHeaders.LOCATION).getValue());
+ assertNull(response.getFirstHeader(HttpHeaders.ETAG));
+ assertXpathEvaluatesTo("Team X", "/atom:entry/atom:content/m:properties/d:Name", getBody(response));
+
+ // Create an entry for a type that has no media resource.
+ // Add navigation to Employee('4') and Employee('5').
+ requestBody = "<entry xmlns=\"" + Edm.NAMESPACE_ATOM_2005 + "\"" + "\n"
+ + " xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + "\n"
+ + " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "\n"
+ + " <author><name>no author</name></author>" + "\n"
+ + " <content type=\"application/xml\">" + "\n"
+ + " <m:properties>" + "\n"
+ + " <d:Id>109</d:Id>" + "\n"
+ + " <d:Name/>" + "\n"
+ + " <d:Seats>4</d:Seats>" + "\n"
+ + " <d:Version>2</d:Version>" + "\n"
+ + " </m:properties>" + "\n"
+ + " </content>" + "\n"
+ + " <id>Rooms('104')</id>" + "\n"
+ + " <title>Room 104</title>" + "\n"
+ + " <updated>2011-08-10T12:00:23Z</updated>" + "\n"
+ + " <link href=\"Employees('4')\"" + "\n"
+ + " rel=\"" + Edm.NAMESPACE_REL_2007_08 + "nr_Employees\"" + "\n"
+ + " type=\"" + HttpContentType.APPLICATION_ATOM_XML_FEED_UTF8 + "\"/>" + "\n"
+ + " <link href=\"Employees('5')\"" + "\n"
+ + " rel=\"" + Edm.NAMESPACE_REL_2007_08 + "nr_Employees\"" + "\n"
+ + " type=\"" + HttpContentType.APPLICATION_ATOM_XML_FEED_UTF8 + "\"/>" + "\n"
+ + "</entry>";
+ response = postUri("Rooms", requestBody, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.CREATED);
+ checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry");
+ assertEquals(getEndpoint() + "Rooms('104')", response.getFirstHeader(HttpHeaders.LOCATION).getValue());
+ checkEtag(response, "W/\"2\"");
+ assertXpathEvaluatesTo("4", "/atom:entry/atom:content/m:properties/d:Seats", getBody(response));
+ checkUri("Rooms('104')/nr_Employees('4')");
+ checkUri("Rooms('104')/nr_Employees('5')");
+ }
+
+ @Test
public void createWithLargeProperty() throws Exception {
final String largeTeamName = StringHelper.generateData(888888);
// Create an entry for a type that has no media resource.