You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2013/09/06 22:01:09 UTC

git commit: Add javadoc, renamed method and add more tests

Updated Branches:
  refs/heads/master 6f5e2b430 -> c631f168c


Add javadoc, renamed method and add more tests


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/c631f168
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/c631f168
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/c631f168

Branch: refs/heads/master
Commit: c631f168cc17ff62120872fe99a6159b716907bc
Parents: 6f5e2b4
Author: Michael Bolz <mi...@apache.org>
Authored: Fri Sep 6 22:00:02 2013 +0200
Committer: Michael Bolz <mi...@apache.org>
Committed: Fri Sep 6 22:00:02 2013 +0200

----------------------------------------------------------------------
 .../olingo/odata2/core/ContentNegotiator.java   |  4 +-
 .../olingo/odata2/core/ODataRequestHandler.java |  2 +-
 .../olingo/odata2/core/commons/ContentType.java | 50 +++++++++++++++++---
 .../odata2/core/ep/ProviderFacadeImpl.java      |  2 +-
 .../odata2/core/commons/ContentTypeTest.java    | 43 +++++++++++++++++
 5 files changed, 90 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c631f168/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 fbb676d..1e5cea2 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
@@ -56,7 +56,7 @@ public class ContentNegotiator {
     if (uriInfo.getFormat() == null) {
       contentType = doContentNegotiationForAcceptHeader(acceptHeaderContentTypes, ContentType.create(supportedContentTypes));
     } else {
-      contentType = doContentNegotiationForFormat(uriInfo, ContentType.createCustom(supportedContentTypes));
+      contentType = doContentNegotiationForFormat(uriInfo, ContentType.createAsCustom(supportedContentTypes));
     }
 
     if (contentType.getODataFormat() == ODataFormat.CUSTOM) {
@@ -106,7 +106,7 @@ public class ContentNegotiator {
       return ContentType.APPLICATION_JSON;
     }
 
-    return ContentType.createCustom(format);
+    return ContentType.createAsCustom(format);
   }
 
   private ContentType doContentNegotiationForAcceptHeader(final List<String> acceptHeaderContentTypes, final List<ContentType> supportedContentTypes) throws ODataException {

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c631f168/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 38e59a9..e938a1f 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
@@ -422,7 +422,7 @@ public class ODataRequestHandler {
   }
 
   private List<ContentType> getSupportedContentTypes(final Class<? extends ODataProcessor> processorFeature) throws ODataException {
-    return ContentType.createCustom(service.getSupportedContentTypes(processorFeature));
+    return ContentType.createAsCustom(service.getSupportedContentTypes(processorFeature));
   }
 
   private static String getDebugValue(final ODataContext context, final Map<String, String> queryParameters) {

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c631f168/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java
index 58579f5..a1499f8 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java
@@ -118,10 +118,10 @@ public class ContentType {
   public static final ContentType TEXT_PLAIN_CS_UTF_8 = ContentType.create(TEXT_PLAIN, PARAMETER_CHARSET, CHARSET_UTF_8);
   public static final ContentType MULTIPART_MIXED = new ContentType("multipart", "mixed");
 
-  private String type;
-  private String subtype;
-  private Map<String, String> parameters;
-  private ODataFormat odataFormat;
+  private final String type;
+  private final String subtype;
+  private final Map<String, String> parameters;
+  private final ODataFormat odataFormat;
 
   private ContentType(final String type) {
     if (type == null) {
@@ -130,6 +130,7 @@ public class ContentType {
     this.odataFormat = ODataFormat.CUSTOM;
     this.type = validateType(type);
     this.subtype = null;
+    this.parameters = Collections.emptyMap();
   }
 
   private ContentType(final String type, final String subtype) {
@@ -265,7 +266,24 @@ public class ContentType {
     }
   }
 
-  public static ContentType createCustom(final String format) {
+  /**
+   * Create a {@link ContentType} based on given input string (<code>format</code>).
+   * 
+   * Supported format is <code>Media Type</code> format as defined in <code>RFC 2616 chapter 3.7</code>.
+   * and {@link ContentType} with {@link ODataFormat#CUSTOM}.
+   * 
+   * The <code>Media Type</code> format can be used as
+   * <code>HTTP Accept HEADER</code> format as defined in <code>RFC 2616 chapter 14.1</code>
+   * and 
+   * <code>HTTP Content-Type HEADER</code> format as defined in <code>RFC 2616 chapter 14.17</code>.
+   * The {@link ContentType} with {@link ODataFormat#CUSTOM} can only be used as <code>$format</code> system query option 
+   * (as defined http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/#47_Format_System_Query_Option_format).
+   * 
+   * @param format a string in format as defined in <code>RFC 2616 section 3.7</code>
+   * @return a new <code>ContentType</code> object
+   * @throws IllegalArgumentException if input string is not parseable
+   */
+  public static ContentType createAsCustom(final String format) {
     ContentType parsedContentType = parse(format);
     if(parsedContentType == null) {
       return new ContentType(format);
@@ -297,10 +315,28 @@ public class ContentType {
     return contentTypes;
   }
 
-  public static List<ContentType> createCustom(final List<String> contentTypeStrings) {
+  /**
+   * Create a list of {@link ContentType} based on given input strings (<code>contentTypes</code>).
+   * 
+   * Supported format is <code>Media Type</code> format as defined in <code>RFC 2616 chapter 3.7</code>.
+   * and {@link ContentType} with {@link ODataFormat#CUSTOM}.
+   * 
+   * The <code>Media Type</code> format can be used as
+   * <code>HTTP Accept HEADER</code> format as defined in <code>RFC 2616 chapter 14.1</code>
+   * and 
+   * <code>HTTP Content-Type HEADER</code> format as defined in <code>RFC 2616 chapter 14.17</code>.
+   * The {@link ContentType} with {@link ODataFormat#CUSTOM} can only be used as <code>$format</code> system query option 
+   * (as defined http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/#47_Format_System_Query_Option_format).
+   * 
+   * @param contentTypeStrings a list of strings in format as defined in <code>RFC 2616 section 3.7</code> or 
+   * as defined http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/#47_Format_System_Query_Option_format
+   * @return a list of new <code>ContentType</code> object
+   * @throws IllegalArgumentException if one of the given input string is not parseable this exceptions is thrown
+   */
+  public static List<ContentType> createAsCustom(final List<String> contentTypeStrings) {
     List<ContentType> contentTypes = new ArrayList<ContentType>(contentTypeStrings.size());
     for (String contentTypeString : contentTypeStrings) {
-      contentTypes.add(createCustom(contentTypeString));
+      contentTypes.add(createAsCustom(contentTypeString));
     }
     return contentTypes;
   }

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c631f168/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImpl.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImpl.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImpl.java
index 24466f8..58e47e5 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImpl.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImpl.java
@@ -63,7 +63,7 @@ public class ProviderFacadeImpl implements EntityProviderInterface {
   }
 
   private static ContentTypeBasedEntityProvider create(final String contentType) throws EntityProviderException {
-    return create(ContentType.createCustom(contentType));
+    return create(ContentType.createAsCustom(contentType));
   }
 
   private static ContentTypeBasedEntityProvider create(final ContentType contentType) throws EntityProviderException {

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c631f168/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/ContentTypeTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/ContentTypeTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/ContentTypeTest.java
index 3b1af77..7734df4 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/ContentTypeTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/commons/ContentTypeTest.java
@@ -102,6 +102,49 @@ public class ContentTypeTest extends BaseTest {
   }
 
   @Test
+  public void creationCustomContentType() {
+    ContentType mt = ContentType.createAsCustom("custom");
+
+    assertEquals("custom", mt.getType());
+    assertNull(mt.getSubtype());
+    assertEquals("custom", mt.toString());
+    assertEquals(ODataFormat.CUSTOM, mt.getODataFormat());
+  }
+
+  @Test
+  public void creationCustomContentTypeImageJpeg() {
+    ContentType mt = ContentType.createAsCustom("image/jpeg");
+
+    assertEquals("image", mt.getType());
+    assertEquals("jpeg", mt.getSubtype());
+    assertEquals("image/jpeg", mt.toString());
+    assertEquals(ODataFormat.MIME, mt.getODataFormat());
+  }
+
+  @Test
+  public void creationCustomContentTypes() {
+    List<ContentType> contentTypes = ContentType.createAsCustom(Arrays.asList("custom", "image/jpeg"));
+
+    Assert.assertEquals(2, contentTypes.size());
+    
+    for (ContentType contentType: contentTypes) {
+      if(contentType.getType().equals("custom")) {
+        assertEquals("custom", contentType.getType());
+        assertNull(contentType.getSubtype());
+        assertEquals("custom", contentType.toString());
+        assertEquals(ODataFormat.CUSTOM, contentType.getODataFormat());
+      } else if(contentType.getType().equals("image")) {
+        assertEquals("image", contentType.getType());
+        assertEquals("jpeg", contentType.getSubtype());
+        assertEquals("image/jpeg", contentType.toString());
+        assertEquals(ODataFormat.MIME, contentType.getODataFormat());
+      } else {
+        Assert.fail("Found unexpected content type with value " + contentType.toContentTypeString());
+      }
+    }
+  }
+
+  @Test
   public void creationContentTypeImageJpeg() {
     ContentType mt = ContentType.create("image/jpeg");