You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/07/08 10:28:22 UTC

[12/15] git commit: [OLINGO-337] more tests and fixes

[OLINGO-337] more tests and fixes


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

Branch: refs/heads/master
Commit: aff42fcee5e189d5cc506ff1cdc05421528fbeb5
Parents: 6383ab0
Author: Stephan Klevenz <st...@sap.com>
Authored: Tue Jul 8 10:07:16 2014 +0200
Committer: Stephan Klevenz <st...@sap.com>
Committed: Tue Jul 8 10:07:16 2014 +0200

----------------------------------------------------------------------
 .../apache/olingo/fit/tecsvc/BasicITCase.java   |  3 ++-
 .../olingo/commons/api/format/AcceptType.java   |  8 +++---
 .../olingo/commons/api/format/ContentType.java  | 27 ++++++++++----------
 .../commons/api/format/AcceptTypeTest.java      | 23 +++++++++++++++--
 .../server/core/ContentNegotiatorTest.java      |  2 +-
 5 files changed, 40 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/aff42fce/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
index c188568..da2f711 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/BasicITCase.java
@@ -30,6 +30,7 @@ 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;
 
@@ -49,7 +50,6 @@ public class BasicITCase {
   public void readServiceDocument() {
     ODataServiceDocumentRequest request =
             odata.getRetrieveRequestFactory().getServiceDocumentRequest(REF_SERVICE);
-    request.setAccept("application/json;odata.metadata=minimal");
     assertNotNull(request);
 
     ODataRetrieveResponse<ODataServiceDocument> response = request.execute();
@@ -73,6 +73,7 @@ public class BasicITCase {
     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());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/aff42fce/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java
index 736b747..12ebf9a 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java
@@ -193,9 +193,6 @@ public class AcceptType {
     for (final String key : parameters.keySet()) {
       result.append(';').append(key).append('=').append(parameters.get(key));
     }
-    if (quality < 1F) {
-      result.append(';').append(TypeUtil.PARAMETER_Q).append('=').append(quality);
-    }
     return result.toString();
   }
 
@@ -225,8 +222,9 @@ public class AcceptType {
     }
     Map<String, String> compareParameters = contentType.getParameters();
     for (final String key : parameters.keySet()) {
-      if (compareParameters.containsKey(key)) {
-        if (!parameters.get(key).equalsIgnoreCase(compareParameters.get(key))) {
+      if (compareParameters.containsKey(key) || TypeUtil.PARAMETER_Q.equalsIgnoreCase(key)) {
+        if (!parameters.get(key).equalsIgnoreCase(compareParameters.get(key))
+            && !TypeUtil.PARAMETER_Q.equalsIgnoreCase(key)) {
           return false;
         }
       } else {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/aff42fce/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 a686880..4aee30e 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
@@ -45,31 +45,30 @@ import java.util.TreeMap;
  */
 public class ContentType {
 
-
   public static final ContentType APPLICATION_XML = create("application", "xml");
   public static final ContentType APPLICATION_XML_CS_UTF_8 = create(APPLICATION_XML, TypeUtil.PARAMETER_CHARSET,
       TypeUtil.CHARSET_UTF_8);
   public static final ContentType APPLICATION_ATOM_XML = create("application", "atom+xml");
   public static final ContentType APPLICATION_ATOM_XML_CS_UTF_8 = create(APPLICATION_ATOM_XML,
       TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
-  public static final ContentType APPLICATION_ATOM_XML_ENTRY = 
-      create(APPLICATION_ATOM_XML,TypeUtil. PARAMETER_TYPE, "entry");
+  public static final ContentType APPLICATION_ATOM_XML_ENTRY =
+      create(APPLICATION_ATOM_XML, TypeUtil.PARAMETER_TYPE, "entry");
   public static final ContentType APPLICATION_ATOM_XML_ENTRY_CS_UTF_8 = create(APPLICATION_ATOM_XML_ENTRY,
-      TypeUtil.  PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
-  public static final ContentType APPLICATION_ATOM_XML_FEED = 
-      create(APPLICATION_ATOM_XML,TypeUtil. PARAMETER_TYPE, "feed");
+      TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
+  public static final ContentType APPLICATION_ATOM_XML_FEED =
+      create(APPLICATION_ATOM_XML, TypeUtil.PARAMETER_TYPE, "feed");
   public static final ContentType APPLICATION_ATOM_XML_FEED_CS_UTF_8 = create(APPLICATION_ATOM_XML_FEED,
-      TypeUtil.  PARAMETER_CHARSET,TypeUtil.CHARSET_UTF_8);
+      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);
+      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);
+      TypeUtil.PARAMETER_CHARSET, TypeUtil.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 = 
-      create(TEXT_PLAIN, TypeUtil.PARAMETER_CHARSET,TypeUtil. CHARSET_UTF_8);
+  public static final ContentType TEXT_PLAIN_CS_UTF_8 =
+      create(TEXT_PLAIN, TypeUtil.PARAMETER_CHARSET, TypeUtil.CHARSET_UTF_8);
   public static final ContentType MULTIPART_MIXED = create("multipart", "mixed");
 
   public static final ContentType APPLICATION_XHTML_XML = create("application", "xhtml+xml");
@@ -209,10 +208,10 @@ public class ContentType {
         }
       } else {
         throw new IllegalArgumentException(
-          "Too many '" +TypeUtil.TYPE_SUBTYPE_SEPARATOR + "' in format '" + format + "'.");
+            "Too many '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR + "' in format '" + format + "'.");
       }
     } else {
-      throw new IllegalArgumentException("No separator '" +TypeUtil.TYPE_SUBTYPE_SEPARATOR
+      throw new IllegalArgumentException("No separator '" + TypeUtil.TYPE_SUBTYPE_SEPARATOR
           + "' was found in format '" + format + "'.");
     }
 
@@ -305,7 +304,7 @@ public class ContentType {
     }
     return compatible.booleanValue();
   }
-  
+
   /**
    * Check equal without parameters.
    * It is possible that no decision about <code>equal/none equal</code> can be determined a <code>NULL</code> is

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/aff42fce/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java b/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java
index 4427bf0..935b001 100644
--- a/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java
+++ b/lib/commons-api/src/test/java/org/apache/olingo/commons/api/format/AcceptTypeTest.java
@@ -20,6 +20,7 @@ package org.apache.olingo.commons.api.format;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 
@@ -45,15 +46,33 @@ public class AcceptTypeTest {
     assertEquals("a/a", atl.get(0).toString());
   }
 
+  @Test
+  public void testWithQParameter() {
+    List<AcceptType> atl = AcceptType.create("application/json;q=0.2");
+
+    assertEquals(1, atl.size());
+    assertEquals("application", atl.get(0).getType());
+    assertEquals("json", atl.get(0).getSubtype());
+    assertEquals("0.2", atl.get(0).getParameters().get("q"));
+    assertEquals("application/json;q=0.2", atl.get(0).toString());
+  }
+
+  @Test
+  public void testMatchWithQParameter() {
+    List<AcceptType> atl = AcceptType.create("application/json;q=0.2");
+    assertEquals(1, atl.size());
+    assertTrue(atl.get(0).matches(ContentType.APPLICATION_JSON));
+  }
+
   @Test(expected = IllegalArgumentException.class)
   public void testWrongQParameter() {
     AcceptType.create(" a/a;q=z ");
   }
-  
+
   @Test
   public void testWildcard() {
     List<AcceptType> atl = AcceptType.create("*; q=.2");
-    
+
     assertNotNull(atl);
     assertEquals(1, atl.size());
     assertEquals("*", atl.get(0).getType());

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/aff42fce/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 88896da..6c1d67f 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
@@ -104,7 +104,7 @@ public class ContentNegotiatorTest {
 
   @Test
   public void testServiceDocumentSingleCase() {
-    String[] useCase = { ACCEPT_CASE_FULL, null, ACCEPT_CASE_FULL, "dummy", ACCEPT_CASE_FULL };
+    String[] useCase = { "application/json", null, ACCEPT_CASE_JSON, null, null };
 
     testContentNegotiation(useCase, ServiceDocumentProcessor.class);
   }