Repository: olingo-odata4
Updated Branches:
  refs/heads/master 1d31f596a -> 51e8d3e8d


[OLINGO-337] more fit tests


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/51e8d3e8
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/51e8d3e8
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/51e8d3e8

Branch: refs/heads/master
Commit: 51e8d3e8d87551d171e296b850721063e1a6eed4
Parents: 1d31f59
Author: Stephan Klevenz <[email protected]>
Authored: Tue Jul 8 14:49:05 2014 +0200
Committer: Stephan Klevenz <[email protected]>
Committed: Tue Jul 8 15:37:48 2014 +0200

----------------------------------------------------------------------
 .../apache/olingo/fit/tecsvc/BasicITCase.java   |  83 -------------
 .../apache/olingo/fit/tecsvc/PingITCase.java    |  66 -----------
 .../apache/olingo/fit/tecsvc/TecSvcConst.java   |   2 +-
 .../olingo/fit/tecsvc/client/BasicITCase.java   |  84 +++++++++++++
 .../olingo/fit/tecsvc/http/BasicHttpITCase.java | 118 +++++++++++++++++++
 .../olingo/fit/tecsvc/http/PingITCase.java      |  67 +++++++++++
 .../olingo/commons/api/format/ContentType.java  |   6 +
 .../olingo/commons/api/format/TypeUtil.java     |   2 +-
 .../olingo/server/core/ContentNegotiator.java   |  16 ++-
 .../server/core/ContentNegotiatorTest.java      |  22 ++--
 10 files changed, 302 insertions(+), 164 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/51e8d3e8/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java
deleted file mode 100644
index da2f711..0000000
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.fit.tecsvc;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import 
org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest;
-import 
org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
-import 
org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.v4.ODataClient;
-import org.apache.olingo.client.core.ODataClientFactory;
-import org.apache.olingo.commons.api.domain.ODataServiceDocument;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.junit.Before;
-import org.junit.Test;
-
-public class BasicITCase {
-
-  private static final String REF_SERVICE = TecSvcConst.BASE_URL;
-
-  private ODataClient odata;
-
-  @Before
-  public void before() {
-    odata = ODataClientFactory.getV4();
-    odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON);
-  }
-
-  @Test
-  public void readServiceDocument() {
-    ODataServiceDocumentRequest request =
-            
odata.getRetrieveRequestFactory().getServiceDocumentRequest(REF_SERVICE);
-    assertNotNull(request);
-
-    ODataRetrieveResponse<ODataServiceDocument> response = request.execute();
-
-    assertEquals(200, response.getStatusCode());
-
-    ODataServiceDocument serviceDocument = response.getBody();
-    assertNotNull(serviceDocument);
-
-    assertTrue(serviceDocument.getEntitySetNames().contains("ESAllPrim"));
-    
assertTrue(serviceDocument.getFunctionImportNames().contains("FICRTCollCTTwoPrim"));
-    assertTrue(serviceDocument.getSingletonNames().contains("SIMedia"));
-  }
-
-  @Test
-  public void readMetadata() {
-    EdmMetadataRequest request = 
odata.getRetrieveRequestFactory().getMetadataRequest(REF_SERVICE);
-    assertNotNull(request);
-
-    ODataRetrieveResponse<Edm> response = request.execute();
-    assertEquals(200, response.getStatusCode());
-
-    Edm edm = response.getBody();
-
-    assertNotNull(edm);
-    assertEquals("com.sap.odata.test1", 
edm.getSchema("com.sap.odata.test1").getNamespace());
-    assertEquals("Namespace1_Alias", 
edm.getSchema("com.sap.odata.test1").getAlias());
-    assertNotNull(edm.getTerm(new FullQualifiedName("Core.Description")));
-    assertEquals(2, edm.getSchemas().size());
-  }
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/51e8d3e8/fit/src/test/java/org/apache/olingo/fit/tecsvc/PingITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/PingITCase.java 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/PingITCase.java
deleted file mode 100644
index 46ea276..0000000
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/PingITCase.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.fit.tecsvc;
-
-import static org.junit.Assert.assertEquals;
-
-import java.net.HttpURLConnection;
-import java.net.URL;
-
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PingITCase {
-
-  private static final Logger LOG = LoggerFactory.getLogger(PingITCase.class);
-
-  private static final String REF_SERVICE = TecSvcConst.BASE_URL + "/";
-  private static final String REDIRECT_URL = TecSvcConst.BASE_URL;
-
-  @Test
-  public void ping() throws Exception {
-    URL url = new URL(REF_SERVICE);
-
-    LOG.debug("ping request: " + REF_SERVICE);
-
-    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-    connection.setRequestMethod("GET");
-    connection.connect();
-
-    int code = connection.getResponseCode();
-    assertEquals(200, code);
-  }
-
-  @Test
-  public void redirect() throws Exception {
-
-    URL url = new URL(REDIRECT_URL);
-
-    LOG.debug("redirect request: " + REDIRECT_URL);
-
-    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-    connection.setRequestMethod("GET");
-    connection.connect();
-
-    int code = connection.getResponseCode();
-    assertEquals(200, code);
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/51e8d3e8/fit/src/test/java/org/apache/olingo/fit/tecsvc/TecSvcConst.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/TecSvcConst.java 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/TecSvcConst.java
index 197151e..45e603e 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/TecSvcConst.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/TecSvcConst.java
@@ -20,6 +20,6 @@ package org.apache.olingo.fit.tecsvc;
 
 public class TecSvcConst {
 
-  public final static String BASE_URL = 
"http://localhost:9080/olingo-server-tecsvc/odata.svc";;
+  public final static String BASE_URI = 
"http://localhost:9080/olingo-server-tecsvc/odata.svc";;
   
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/51e8d3e8/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
new file mode 100644
index 0000000..d4223a0
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
@@ -0,0 +1,84 @@
+/*
+ * 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.fit.tecsvc.client;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import 
org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest;
+import 
org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
+import 
org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.v4.ODataClient;
+import org.apache.olingo.client.core.ODataClientFactory;
+import org.apache.olingo.commons.api.domain.ODataServiceDocument;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.fit.tecsvc.TecSvcConst;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BasicITCase {
+
+  private static final String SERVICE_URI = TecSvcConst.BASE_URI;
+
+  private ODataClient odata;
+
+  @Before
+  public void before() {
+    odata = ODataClientFactory.getV4();
+    odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON);
+  }
+
+  @Test
+  public void readServiceDocument() {
+    ODataServiceDocumentRequest request =
+            
odata.getRetrieveRequestFactory().getServiceDocumentRequest(SERVICE_URI);
+    assertNotNull(request);
+
+    ODataRetrieveResponse<ODataServiceDocument> response = request.execute();
+
+    assertEquals(200, response.getStatusCode());
+
+    ODataServiceDocument serviceDocument = response.getBody();
+    assertNotNull(serviceDocument);
+
+    assertTrue(serviceDocument.getEntitySetNames().contains("ESAllPrim"));
+    
assertTrue(serviceDocument.getFunctionImportNames().contains("FICRTCollCTTwoPrim"));
+    assertTrue(serviceDocument.getSingletonNames().contains("SIMedia"));
+  }
+
+  @Test
+  public void readMetadata() {
+    EdmMetadataRequest request = 
odata.getRetrieveRequestFactory().getMetadataRequest(SERVICE_URI);
+    assertNotNull(request);
+
+    ODataRetrieveResponse<Edm> response = request.execute();
+    assertEquals(200, response.getStatusCode());
+
+    Edm edm = response.getBody();
+
+    assertNotNull(edm);
+    assertEquals("com.sap.odata.test1", 
edm.getSchema("com.sap.odata.test1").getNamespace());
+    assertEquals("Namespace1_Alias", 
edm.getSchema("com.sap.odata.test1").getAlias());
+    assertNotNull(edm.getTerm(new FullQualifiedName("Core.Description")));
+    assertEquals(2, edm.getSchemas().size());
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/51e8d3e8/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java
new file mode 100644
index 0000000..cc49c28
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java
@@ -0,0 +1,118 @@
+/*
+ * 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.fit.tecsvc.http;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.apache.olingo.commons.api.http.HttpHeader;
+import org.apache.olingo.fit.tecsvc.TecSvcConst;
+import org.junit.Test;
+
+public class BasicHttpITCase {
+
+  private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/";
+
+  @Test
+  public void testFormat() throws Exception {
+    URL url = new URL(SERVICE_URI + "?$format=json");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod("GET");
+    connection.connect();
+
+    int code = connection.getResponseCode();
+    assertEquals(200, code);
+    String ct = connection.getHeaderField(HttpHeader.CONTENT_TYPE);
+    assertEquals("application/json;odata.metadata=minimal", ct);
+  }
+
+  @Test
+  public void testAccept() throws Exception {
+    URL url = new URL(SERVICE_URI);
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+    connection.setRequestMethod("GET");
+    connection.setRequestProperty(HttpHeader.ACCEPT, 
"application/json;q=0.2;odata.metadata=minimal");
+    
+    connection.connect();
+
+    int code = connection.getResponseCode();
+    assertEquals(200, code);
+    String ct = connection.getHeaderField(HttpHeader.CONTENT_TYPE);
+    assertEquals("application/json;odata.metadata=minimal", ct);
+  }
+
+  @Test
+  public void testAcceptSimple() throws Exception {
+    URL url = new URL(SERVICE_URI);
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+    connection.setRequestMethod("GET");
+    connection.setRequestProperty(HttpHeader.ACCEPT, "application/json");
+    
+    connection.connect();
+
+    int code = connection.getResponseCode();
+    assertEquals(200, code);
+    String ct = connection.getHeaderField(HttpHeader.CONTENT_TYPE);
+    assertEquals("application/json;odata.metadata=minimal", ct);
+  }
+
+  @Test
+  public void testAcceptCharset() throws Exception {
+    URL url = new URL(SERVICE_URI);
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+    connection.setRequestMethod("GET");
+    connection.setRequestProperty(HttpHeader.ACCEPT, 
"application/json;q=0.2;odata.metadata=minimal;charset=utf-8");
+    
+    connection.connect();
+
+    int code = connection.getResponseCode();
+    assertEquals(200, code);
+    String ct = connection.getHeaderField(HttpHeader.CONTENT_TYPE);
+    assertEquals("application/json;odata.metadata=minimal;charset=UTF-8", ct);
+  }
+
+  @Test
+  public void testODataMaxVersion() throws Exception {
+    URL url = new URL(SERVICE_URI);
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+    connection.setRequestMethod("GET");
+    connection.setRequestProperty(HttpHeader.ODATA_MAX_VERSION, "4.0");
+    
+    connection.connect();
+
+    int code = connection.getResponseCode();
+    assertEquals(200, code);
+    String v = connection.getHeaderField(HttpHeader.ODATA_VERSION);
+    assertEquals("4.0", v);
+  }
+
+  
+  
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/51e8d3e8/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java
new file mode 100644
index 0000000..90c501b
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java
@@ -0,0 +1,67 @@
+/*
+ * 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.fit.tecsvc.http;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.apache.olingo.fit.tecsvc.TecSvcConst;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PingITCase {
+
+  private static final Logger LOG = LoggerFactory.getLogger(PingITCase.class);
+
+  private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/";
+  private static final String REDIRECT_URI = TecSvcConst.BASE_URI;
+
+  @Test
+  public void ping() throws Exception {
+    URL url = new URL(SERVICE_URI);
+
+    LOG.debug("ping request: " + SERVICE_URI);
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod("GET");
+    connection.connect();
+
+    int code = connection.getResponseCode();
+    assertEquals(200, code);
+  }
+
+  @Test
+  public void redirect() throws Exception {
+
+    URL url = new URL(REDIRECT_URI);
+
+    LOG.debug("redirect request: " + REDIRECT_URI);
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod("GET");
+    connection.connect();
+
+    int code = connection.getResponseCode();
+    assertEquals(200, code);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/51e8d3e8/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
index 4aee30e..b01d047 100644
--- 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
+++ 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
@@ -61,10 +61,16 @@ public class ContentType {
       TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
   public static final ContentType APPLICATION_ATOM_SVC = create("application", 
"atomsvc+xml");
   public static final ContentType APPLICATION_ATOM_SVC_CS_UTF_8 = 
create(APPLICATION_ATOM_SVC,
+
       TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
   public static final ContentType APPLICATION_JSON = create("application", 
"json");
   public static final ContentType APPLICATION_JSON_CS_UTF_8 = 
create(APPLICATION_JSON,
       TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
+
+  public static final ContentType APPLICATION_JSON_MIN = 
create("application/json;odata.metadata=minimal");
+  public static final ContentType APPLICATION_JSON_MIN_CS_UTF_8 =
+      create("application/json;odata.metadata=minimal;charset=UTF-8");
+
   public static final ContentType APPLICATION_OCTET_STREAM = 
create("application", "octet-stream");
   public static final ContentType TEXT_PLAIN = create("text", "plain");
   public static final ContentType TEXT_PLAIN_CS_UTF_8 =

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/51e8d3e8/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/TypeUtil.java
----------------------------------------------------------------------
diff --git 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/TypeUtil.java
 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/TypeUtil.java
index bbc4463..373829b 100644
--- 
a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/TypeUtil.java
+++ 
b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/TypeUtil.java
@@ -35,7 +35,7 @@ class TypeUtil {
   static final String PARAMETER_TYPE = "type";
   static final String PARAMETER_CHARSET = "charset";
   static final String CHARSET_UTF_8 = "UTF-8";
-
+ 
   /**
    * Valid input are <code>;</code> separated <code>key=value</code> pairs
    * without spaces between key and value.

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/51e8d3e8/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
index 749fd27..20348ab 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
@@ -33,6 +33,8 @@ import 
org.apache.olingo.server.api.uri.queryoption.FormatOption;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.fasterxml.jackson.dataformat.xml.util.TypeUtil;
+
 public class ContentNegotiator {
 
   private final static Logger LOG = 
LoggerFactory.getLogger(ContentNegotiator.class);
@@ -46,7 +48,7 @@ public class ContentNegotiator {
     if (processorClass == MetadataProcessor.class) {
       defaults.add(new FormatContentTypeMapping("xml", 
ContentType.APPLICATION_XML.toContentTypeString()));
     } else {
-      defaults.add(new FormatContentTypeMapping("json", 
ContentType.APPLICATION_JSON.toContentTypeString()));
+//      defaults.add(new FormatContentTypeMapping("json", 
ContentType.APPLICATION_JSON.toContentTypeString()));
       defaults.add(new FormatContentTypeMapping("json", 
ContentType.APPLICATION_JSON.toContentTypeString()
           + ";odata.metadata=minimal"));
     }
@@ -81,7 +83,7 @@ public class ContentNegotiator {
     if (formatOption != null) {
 
       if ("json".equalsIgnoreCase(formatOption.getText().trim())) {
-        requestedContentType = ContentType.APPLICATION_JSON;
+        requestedContentType = ContentType.APPLICATION_JSON_MIN;
         for (FormatContentTypeMapping entry : supportedContentTypes) {
           if 
(requestedContentType.isCompatible(ContentType.create(entry.getContentType().trim())))
 {
             supported = true;
@@ -115,7 +117,15 @@ public class ContentNegotiator {
 
       for (AcceptType acceptedType : acceptedContentTypes) {
         for (FormatContentTypeMapping supportedType : supportedContentTypes) {
+
           ContentType ct = ContentType.create(supportedType.getContentType());
+          if (acceptedType.getParameters().containsKey("charset")) {
+            String value = acceptedType.getParameters().get("charset");
+            if ("utf8".equalsIgnoreCase(value) || 
"utf-8".equalsIgnoreCase(value)) {
+              ct = ContentType.create(ct, "charset", "UTF-8");
+            }
+          }
+
           if (acceptedType.matches(ct)) {
             requestedContentType = ct;
             supported = true;
@@ -136,7 +146,7 @@ public class ContentNegotiator {
       if (processorClass == MetadataProcessor.class) {
         requestedContentType = ContentType.APPLICATION_XML;
       } else {
-        requestedContentType = ContentType.APPLICATION_JSON;
+        requestedContentType = ContentType.APPLICATION_JSON_MIN;
       }
 
       for (FormatContentTypeMapping entry : supportedContentTypes) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/51e8d3e8/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
index 6c1d67f..e189f79 100644
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
@@ -51,8 +51,9 @@ import org.slf4j.LoggerFactory;
 public class ContentNegotiatorTest {
 
   static final private String ACCEPT_CASE_MIN = 
"application/json;odata.metadata=minimal";
+  static final private String ACCEPT_CASE_MIN_UTF8 = 
"application/json;charset=UTF-8;odata.metadata=minimal";
   static final private String ACCEPT_CASE_FULL = 
"application/json;odata.metadata=full";
-  static final private String ACCEPT_CASE_JSON = "application/json;q=0.2";
+  static final private String ACCEPT_CASE_JSONQ = "application/json;q=0.2";
   static final private String ACCEPT_CASE_XML = "application/xml";
   static final private String ACCEPT_CASE_WILDCARD1 = "*/*";
   static final private String ACCEPT_CASE_WILDCARD2 = "application/*";
@@ -62,18 +63,19 @@ public class ContentNegotiatorTest {
 
   String[][] casesServiceDocument = {
       /* expected               $format           accept                 alias 
       ct mapping    */
-      { "application/json",     null,             null,                  null  
       ,null             },
-      { "application/json",     "json",           null,                  null  
       ,null             },
-      { "application/json",     "json",           ACCEPT_CASE_JSON,      null  
       ,null             },
+      { ACCEPT_CASE_MIN,        null,             null,                  null  
       ,null             },
+      { ACCEPT_CASE_MIN,        "json",           null,                  null  
       ,null             },
+      { ACCEPT_CASE_MIN,        "json",           ACCEPT_CASE_JSONQ,     null  
       ,null             },
       { "a/a",                  "a",              null,                  "a"   
       ,"a/a"            },
-      { "application/json",     null,             ACCEPT_CASE_JSON,      null  
       ,null             },
-      { "application/json",     null,             ACCEPT_CASE_WILDCARD1, null  
       ,null             },
-      { "application/json",     null,             ACCEPT_CASE_WILDCARD2, null  
       ,null             },
+      { ACCEPT_CASE_MIN,        null,             ACCEPT_CASE_JSONQ,     null  
       ,null             },
+      { ACCEPT_CASE_MIN,        null,             ACCEPT_CASE_WILDCARD1, null  
       ,null             },
+      { ACCEPT_CASE_MIN,        null,             ACCEPT_CASE_WILDCARD2, null  
       ,null             },
       { "a/a",                  "a",              null,                  "a, 
b"       ,"a/a,b/b"        },
       { "a/a",                  " a ",            null,                  " a , 
b"     ," a/a , b/b "    },
       { "a/a;x=y",              "a",              ACCEPT_CASE_WILDCARD1, "a"   
       ,"a/a;x=y"        },
-      { "application/json",     "json",           ACCEPT_CASE_MIN,       null  
       ,null             },
+      { ACCEPT_CASE_MIN,        "json",           ACCEPT_CASE_MIN,       null  
       ,null             },
       { ACCEPT_CASE_FULL,       null,             ACCEPT_CASE_FULL,      
"dummy"     ,ACCEPT_CASE_FULL  }, 
+      { ACCEPT_CASE_MIN_UTF8,   null,             ACCEPT_CASE_MIN_UTF8,  null  
       ,null             },
   };                                                                           
               
 
   String[][] casesMetadata = {                                                 
                
@@ -94,7 +96,7 @@ public class ContentNegotiatorTest {
       /* expected               $format           accept                 alias 
       ct mapping    */
       { "application/xml",      "xxx",            null,                  null  
       ,null             },
       { "a/a",                  "a",              null,                  "b"   
       ,"b/b"            },
-      { "application/xml",      null,             ACCEPT_CASE_JSON,      null  
       ,null             },
+      { "application/xml",      null,             ACCEPT_CASE_JSONQ,     null  
       ,null             },
       { "application/json",     null,             ACCEPT_CASE_FULL,      null  
       ,null             }, // not jet supported
   };
   //CHECKSTYLE:ON
@@ -104,7 +106,7 @@ public class ContentNegotiatorTest {
 
   @Test
   public void testServiceDocumentSingleCase() {
-    String[] useCase = { "application/json", null, ACCEPT_CASE_JSON, null, 
null };
+    String[] useCase = { ACCEPT_CASE_MIN_UTF8, null, ACCEPT_CASE_MIN_UTF8, 
null, null };
 
     testContentNegotiation(useCase, ServiceDocumentProcessor.class);
   }

Reply via email to