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 2014/05/18 07:06:59 UTC

[31/38] git commit: [OLINGO-243] Fixed wrong content type handling

[OLINGO-243] Fixed wrong content type handling


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: e85125093cb782103a112fe0f8368a0ab2aae8a1
Parents: 55b1c84
Author: Michael Bolz <mi...@apache.org>
Authored: Mon Apr 28 10:58:24 2014 +0200
Committer: Michael Bolz <mi...@apache.org>
Committed: Mon Apr 28 10:58:24 2014 +0200

----------------------------------------------------------------------
 .../olingo/odata2/core/ODataRequestHandler.java |  9 ++-
 .../odata2/core/ContentNegotiatorTest.java      |  8 +++
 .../odata2/fit/ref/FunctionImportXmlTest.java   | 68 +++++++++++++++++++-
 3 files changed, 80 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e8512509/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
index f244bf7..0b1da19 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
@@ -481,8 +481,13 @@ public class ODataRequestHandler {
   private List<String> getSupportedContentTypes(final UriInfoImpl uriInfo, final ODataHttpMethod method)
       throws ODataException {
     Class<? extends ODataProcessor> processorFeature = Dispatcher.mapUriTypeToProcessorFeature(uriInfo);
-    if (ODataHttpMethod.POST.equals(method)) {
-      UriType uriType = uriInfo.getUriType();
+    UriType uriType = uriInfo.getUriType();
+    //
+    if (uriType == UriType.URI11) {
+      processorFeature = EntitySetProcessor.class;
+    } else if ((uriType == UriType.URI10)) {
+      processorFeature = EntityProcessor.class;
+    } else if (ODataHttpMethod.POST.equals(method)) {
       if (uriType == UriType.URI1 || uriType == UriType.URI6B) {
         processorFeature = EntityProcessor.class;
       }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e8512509/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ContentNegotiatorTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ContentNegotiatorTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ContentNegotiatorTest.java
index a45da48..ff12314 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ContentNegotiatorTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ContentNegotiatorTest.java
@@ -47,6 +47,14 @@ public class ContentNegotiatorTest {
     assertEquals(expected, contentType.toContentTypeString());
   }
 
+  @Test
+  public void defaultContentTypeForEmptyList() throws ODataException {
+    List<ContentType> contentTypes = Arrays.asList();
+    List<ContentType> supportedTypes = Arrays.asList(ContentType.APPLICATION_ATOM_XML, ContentType.APPLICATION_XML);
+
+    negotiateContentType(contentTypes, supportedTypes, "application/atom+xml");
+  }
+
   @Test(expected = IllegalArgumentException.class)
   public void invalidContentNegotiatorCreation() throws ODataException {
     final ContentType contentType = new ContentNegotiator().doContentNegotiation(null, null, null);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/e8512509/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/FunctionImportXmlTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/FunctionImportXmlTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/FunctionImportXmlTest.java
index 6a45963..bdf62e5 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/FunctionImportXmlTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/FunctionImportXmlTest.java
@@ -25,10 +25,12 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import junit.framework.Assert;
 
 import org.apache.http.HttpResponse;
 import org.apache.olingo.odata2.api.commons.HttpContentType;
 import org.apache.olingo.odata2.api.commons.HttpHeaders;
+import org.apache.olingo.odata2.core.commons.ContentType;
 import org.apache.olingo.odata2.testutil.server.ServletType;
 import org.junit.Test;
 
@@ -51,10 +53,59 @@ public class FunctionImportXmlTest extends AbstractRefXmlTest {
 
     assertFalse(getBody(callUri("EmployeeSearch?q='-'")).contains("entry"));
 
-    response = callUri("AllLocations");
+    response = callUri("AllLocations", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML);
     checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
     assertXpathExists("/d:AllLocations/d:element/d:City[d:CityName=\"" + CITY_2_NAME + "\"]", getBody(response));
 
+    response = callUri("AllUsedRoomIds", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML);
+    checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
+    assertXpathExists("/d:AllUsedRoomIds[d:element=\"3\"]", getBody(response));
+
+    response = callUri("MaximalAge", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML);
+    checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
+    assertXpathEvaluatesTo(EMPLOYEE_3_AGE, "/d:MaximalAge", getBody(response));
+
+    response = callUri("MostCommonLocation", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML);
+    checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
+    assertXpathEvaluatesTo(CITY_2_NAME, "/d:MostCommonLocation/d:City/d:CityName", getBody(response));
+
+    checkUri("ManagerPhoto?Id='1'");
+
+    response = callUri("ManagerPhoto/$value?Id='1'");
+    checkMediaType(response, IMAGE_JPEG);
+    assertNull(response.getFirstHeader(HttpHeaders.ETAG));
+    assertNotNull(getBody(response));
+
+    response = callUri("OldestEmployee", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML);
+    checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
+    assertXpathEvaluatesTo(EMPLOYEE_3_NAME, "/atom:entry/m:properties/d:EmployeeName", getBody(response));
+
+    response = callUri("OldestEmployee?$format=xml");
+    checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
+    assertXpathEvaluatesTo(EMPLOYEE_3_NAME, "/atom:entry/m:properties/d:EmployeeName", getBody(response));
+
+    badRequest("AllLocations/$count");
+    badRequest("AllUsedRoomIds/$value");
+    badRequest("MaximalAge()");
+    badRequest("MostCommonLocation/City/CityName");
+    badRequest("ManagerPhoto");
+    badRequest("OldestEmployee()");
+    notFound("ManagerPhoto?Id='2'");
+  }
+
+  @Test
+  public void functionImportsDefaultAccept() throws Exception {
+    HttpResponse response = callUri("EmployeeSearch('1')/ne_Room/Id/$value?q='alter'");
+    checkMediaType(response, HttpContentType.TEXT_PLAIN_UTF8);
+    checkEtag(response, "W/\"1\"");
+    assertEquals("1", getBody(response));
+
+    assertFalse(getBody(callUri("EmployeeSearch?q='-'")).contains("entry"));
+
+    response = callUri("AllLocations");
+    checkMediaType(response, ContentType.APPLICATION_ATOM_XML_FEED_CS_UTF_8);
+    assertXpathExists("/d:AllLocations/d:element/d:City[d:CityName=\"" + CITY_2_NAME + "\"]", getBody(response));
+
     response = callUri("AllUsedRoomIds");
     checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
     assertXpathExists("/d:AllUsedRoomIds[d:element=\"3\"]", getBody(response));
@@ -74,8 +125,8 @@ public class FunctionImportXmlTest extends AbstractRefXmlTest {
     assertNull(response.getFirstHeader(HttpHeaders.ETAG));
     assertNotNull(getBody(response));
 
-    response = callUri("OldestEmployee", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML);
-    checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
+    response = callUri("OldestEmployee");
+    checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8);
     assertXpathEvaluatesTo(EMPLOYEE_3_NAME, "/atom:entry/m:properties/d:EmployeeName", getBody(response));
 
     response = callUri("OldestEmployee?$format=xml");
@@ -91,6 +142,17 @@ public class FunctionImportXmlTest extends AbstractRefXmlTest {
     notFound("ManagerPhoto?Id='2'");
   }
 
+  @Override
+  public void checkMediaType(final HttpResponse response, final String expectedContentType) {
+    checkMediaType(response, ContentType.parse(expectedContentType));
+  }
+
+  private void checkMediaType(final HttpResponse response, final ContentType expectedContentType) {
+    ContentType responseContentType =
+        ContentType.parse(response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());
+    Assert.assertEquals(expectedContentType, responseContentType);
+  }
+
   @Test
   public void select() throws Exception {
     HttpResponse response = callUri("EmployeeSearch?q='ede'&$select=Age");