olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [1/2] git commit: Refactoring for OLINGO-15 (JSON-Part)
Date Tue, 10 Sep 2013 17:04:10 GMT
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 <mibo@apache.org>
Authored: Mon Sep 9 14:12:11 2013 +0200
Committer: Michael Bolz <mibo@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;
+    }
+  }
+}


Mime
View raw message