You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/09/25 15:32:40 UTC

[1/3] git commit: minor improvements

Repository: olingo-odata4
Updated Branches:
  refs/heads/master 68f51d84d -> 7e0b013ce


minor improvements

Change-Id: Ia9872a613f3221e2de885f9d325a14f3c50b4beb

Signed-off-by: Christian Amend <ch...@apache.org>


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

Branch: refs/heads/master
Commit: f947afc1088092e7f54c38250c92c717a01d0bdc
Parents: 68f51d8
Author: Klaus Straubinger <kl...@sap.com>
Authored: Thu Sep 25 13:50:32 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Thu Sep 25 15:25:55 2014 +0200

----------------------------------------------------------------------
 .../olingo/fit/server/TomcatTestServer.java     | 46 ++++++++++----------
 .../olingo/fit/AbstractBaseTestITCase.java      | 13 +++---
 .../olingo/fit/tecsvc/client/BasicITCase.java   | 28 +++++-------
 .../serializer/json/ODataJsonSerializer.java    |  2 +-
 .../xml/MetadataDocumentXmlSerializer.java      |  9 ++--
 .../tecsvc/processor/TechnicalProcessor.java    | 19 ++++----
 6 files changed, 59 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f947afc1/fit/src/main/java/org/apache/olingo/fit/server/TomcatTestServer.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/server/TomcatTestServer.java b/fit/src/main/java/org/apache/olingo/fit/server/TomcatTestServer.java
index ff855c1..231d9c0 100644
--- a/fit/src/main/java/org/apache/olingo/fit/server/TomcatTestServer.java
+++ b/fit/src/main/java/org/apache/olingo/fit/server/TomcatTestServer.java
@@ -85,16 +85,16 @@ public class TomcatTestServer {
 
       boolean keepRunning = false;
       for (String param : params) {
-        if(param.equalsIgnoreCase("keeprunning")) {
+        if (param.equalsIgnoreCase("keeprunning")) {
           keepRunning = true;
-        } else if(param.equalsIgnoreCase("addwebapp")) {
+        } else if (param.equalsIgnoreCase("addwebapp")) {
           server.addWebApp();
-        } else if(param.startsWith("port")) {
+        } else if (param.startsWith("port")) {
           server.atPort(extractPortParam(param));
         }
       }
 
-      if(keepRunning) {
+      if (keepRunning) {
         LOG.info("...and keep server running.");
         server.startAndWait();
       } else {
@@ -110,16 +110,14 @@ public class TomcatTestServer {
 
   public static int extractPortParam(String portParameter) {
     String[] portParam = portParameter.split("=");
-    if(portParam.length == 2) {
+    if (portParam.length == 2) {
       try {
         return Integer.parseInt(portParam[1]);
       } catch (NumberFormatException e) {
-        throw new IllegalArgumentException("Port parameter (" + portParameter +
-            ") could not be parsed.");
+        throw new IllegalArgumentException("Port parameter (" + portParameter + ") could not be parsed.");
       }
     }
-    throw new IllegalArgumentException("Port parameter (" + portParameter +
-        ") could not be parsed.");
+    throw new IllegalArgumentException("Port parameter (" + portParameter + ") could not be parsed.");
   }
 
   public static class StaticContent extends HttpServlet {
@@ -138,7 +136,7 @@ public class TomcatTestServer {
 
       String result;
       File resourcePath = new File(resource);
-      if(resourcePath.exists() && resourcePath.isFile()) {
+      if (resourcePath.exists() && resourcePath.isFile()) {
         FileInputStream fin = new FileInputStream(resourcePath);
         result = IOUtils.toString(fin, "UTF-8");
         LOG.info("Mapped uri '{}' to resource '{}'.", uri, resource);
@@ -152,8 +150,9 @@ public class TomcatTestServer {
   }
 
   private static TestServerBuilder builder;
+
   public static TestServerBuilder init(int port) {
-    if(builder == null) {
+    if (builder == null) {
       builder = new TestServerBuilder(port);
     }
     return builder;
@@ -173,7 +172,7 @@ public class TomcatTestServer {
       initializeProperties();
       //baseDir = new File(System.getProperty("java.io.tmpdir"), "tomcat-test");
       baseDir = getFileForDirProperty(TOMCAT_BASE_DIR);
-      if(!baseDir.exists() && !baseDir.mkdirs()) {
+      if (!baseDir.exists() && !baseDir.mkdirs()) {
         throw new RuntimeException("Unable to create temporary test directory at {" + baseDir.getAbsolutePath() + "}");
       }
       //
@@ -204,14 +203,14 @@ public class TomcatTestServer {
     }
 
     public TestServerBuilder addWebApp() throws IOException {
-      if(server != null) {
+      if (server != null) {
         return this;
       }
 
       File webAppProjectDir = getFileForDirProperty(PROJECT_WEB_APP_DIR);
       File webAppDir = new File(baseDir, webAppProjectDir.getName());
       FileUtils.deleteDirectory(webAppDir);
-      if(!webAppDir.mkdirs()) {
+      if (!webAppDir.mkdirs()) {
         throw new RuntimeException("Unable to create temporary directory at {" + webAppDir.getAbsolutePath() + "}");
       }
       FileUtils.copyDirectory(webAppProjectDir, webAppDir);
@@ -226,22 +225,23 @@ public class TomcatTestServer {
 
     private File getFileForDirProperty(String propertyName) {
       File targetFile = new File(properties.getProperty(propertyName));
-      if(targetFile.exists() && targetFile.isDirectory()) {
+      if (targetFile.exists() && targetFile.isDirectory()) {
         return targetFile;
-      } else if(targetFile.mkdirs()) {
+      } else if (targetFile.mkdirs()) {
         return targetFile;
       }
 
       URL targetURL = Thread.currentThread().getContextClassLoader().getResource(targetFile.getPath());
-      if(targetURL == null) {
+      if (targetURL == null) {
         throw new RuntimeException("Project target was not found at '" +
             properties.getProperty(propertyName) + "'.");
       }
       return new File(targetURL.getFile());
     }
 
-    public TestServerBuilder addServlet(final Class<? extends HttpServlet> factoryClass, String path) throws Exception {
-      if(server != null) {
+    public TestServerBuilder addServlet(final Class<? extends HttpServlet> factoryClass, String path)
+        throws InstantiationException, IllegalAccessException, ClassNotFoundException {
+      if (server != null) {
         return this;
       }
       String odataServlet = factoryClass.getName();
@@ -264,7 +264,7 @@ public class TomcatTestServer {
     }
 
     public TestServerBuilder addServlet(HttpServlet httpServlet, String name, String path) throws IOException {
-      if(server != null) {
+      if (server != null) {
         return this;
       }
       Context cxt = getContext();
@@ -278,14 +278,14 @@ public class TomcatTestServer {
     private Context baseContext = null;
 
     private Context getContext() {
-      if(baseContext == null) {
+      if (baseContext == null) {
         baseContext = tomcat.addContext("/", baseDir.getAbsolutePath());
       }
       return baseContext;
     }
 
     public TomcatTestServer start() throws LifecycleException {
-      if(server != null) {
+      if (server != null) {
         return server;
       }
       tomcat.start();
@@ -313,4 +313,4 @@ public class TomcatTestServer {
       tomcat.destroy();
     }
   }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f947afc1/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
index c7186ff..f4cbf4d 100644
--- a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
@@ -18,6 +18,7 @@
  */
 package org.apache.olingo.fit;
 
+import org.apache.catalina.LifecycleException;
 import org.apache.commons.io.IOUtils;
 import org.apache.olingo.client.api.CommonODataClient;
 import org.apache.olingo.commons.api.data.Entity;
@@ -37,6 +38,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
@@ -48,12 +50,11 @@ public abstract class AbstractBaseTestITCase {
    */
   protected static final Logger LOG = LoggerFactory.getLogger(AbstractBaseTestITCase.class);
 
-  @SuppressWarnings("rawtypes")
-  protected abstract CommonODataClient getClient();
-
+  protected abstract CommonODataClient<?> getClient();
 
   @BeforeClass
-  public static void init() throws Exception {
+  public static void init()
+      throws LifecycleException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
     TomcatTestServer.init(9080)
         .addServlet(TechnicalServlet.class, "/olingo-server-tecsvc/odata.svc/*")
         .addServlet(StaticContent.class, "/olingo-server-tecsvc/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml")
@@ -128,8 +129,8 @@ public abstract class AbstractBaseTestITCase {
 
   public static class StaticContent extends HttpServlet {
     private static final long serialVersionUID = -6663569573355398997L;
-    @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp)
-        throws ServletException, IOException {
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       resp.getOutputStream().write(IOUtils.toByteArray(
           Thread.currentThread().getContextClassLoader().getResourceAsStream("org-odata-core-v1.xml")));
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f947afc1/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
index 49aa989..f7097a3 100644
--- 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
@@ -53,25 +53,16 @@ import org.apache.olingo.commons.api.format.ODataFormat;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 import org.apache.olingo.fit.AbstractBaseTestITCase;
 import org.apache.olingo.fit.tecsvc.TecSvcConst;
-import org.junit.Before;
 import org.junit.Test;
 
 public class BasicITCase extends AbstractBaseTestITCase {
 
   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);
+    ODataServiceDocumentRequest request = getClient().getRetrieveRequestFactory()
+        .getServiceDocumentRequest(SERVICE_URI);
     assertNotNull(request);
 
     ODataRetrieveResponse<ODataServiceDocument> response = request.execute();
@@ -87,7 +78,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
 
   @Test
   public void readMetadata() {
-    EdmMetadataRequest request = odata.getRetrieveRequestFactory().getMetadataRequest(SERVICE_URI);
+    EdmMetadataRequest request = getClient().getRetrieveRequestFactory().getMetadataRequest(SERVICE_URI);
     assertNotNull(request);
 
     ODataRetrieveResponse<Edm> response = request.execute();
@@ -104,7 +95,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
 
   @Test
   public void readEntitySet() {
-    final ODataEntitySetRequest<ODataEntitySet> request = odata.getRetrieveRequestFactory()
+    final ODataEntitySetRequest<ODataEntitySet> request = getClient().getRetrieveRequestFactory()
         .getEntitySetRequest(getClient().newURIBuilder(SERVICE_URI)
             .appendEntitySetSegment("ESMixPrimCollComp").build());
     assertNotNull(request);
@@ -134,7 +125,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
 
   @Test
   public void readException() throws Exception {
-    final ODataEntityRequest<ODataEntity> request = odata.getRetrieveRequestFactory()
+    final ODataEntityRequest<ODataEntity> request = getClient().getRetrieveRequestFactory()
         .getEntityRequest(getClient().newURIBuilder(SERVICE_URI)
             .appendEntitySetSegment("ESMixPrimCollComp").appendKeySegment("42").build());
     assertNotNull(request);
@@ -151,7 +142,7 @@ public class BasicITCase extends AbstractBaseTestITCase {
 
   @Test
   public void readEntityRawResult() throws IOException {
-    final ODataEntityRequest<ODataEntity> request = odata.getRetrieveRequestFactory()
+    final ODataEntityRequest<ODataEntity> request = getClient().getRetrieveRequestFactory()
         .getEntityRequest(getClient().newURIBuilder(SERVICE_URI)
             .appendEntitySetSegment("ESCollAllPrim").appendKeySegment(1).build());
     assertNotNull(request);
@@ -187,7 +178,10 @@ public class BasicITCase extends AbstractBaseTestITCase {
     assertEquals(expectedResult, IOUtils.toString(response.getRawResponse(), "UTF-8"));
   }
 
-  @Override protected CommonODataClient<?> getClient() {
-    return ODataClientFactory.getV4();
+  @Override
+  protected CommonODataClient<?> getClient() {
+    ODataClient odata = ODataClientFactory.getV4();
+    odata.getConfiguration().setDefaultPubFormat(ODataFormat.JSON);
+    return odata;
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f947afc1/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index 094b72e..1d5e549 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -223,7 +223,7 @@ public class ODataJsonSerializer implements ODataSerializer {
         ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems());
     for (final String propertyName : entityType.getPropertyNames()) {
       if (all || selected.contains(propertyName)) {
-        final EdmProperty edmProperty = (EdmProperty) entityType.getProperty(propertyName);
+        final EdmProperty edmProperty = entityType.getStructuralProperty(propertyName);
         final Property property = entity.getProperty(propertyName);
         final Set<List<String>> selectedPaths = all || edmProperty.isPrimitive() ? null :
             ExpandSelectHelper.getSelectedPaths(select.getSelectItems(), propertyName);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f947afc1/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
index 4e9b537..f25289b 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializer.java
@@ -527,15 +527,18 @@ public class MetadataDocumentXmlSerializer {
     }
   }
 
+  /** Appends a reference to the OData Core Vocabulary as defined in the OData specification
+   * and mentioned in its Common Schema Definition Language (CSDL) document.
+   */
   private void appendReference(final XMLStreamWriter writer) throws XMLStreamException {
     writer.writeStartElement(NS_EDMX, "Reference");
-    // TODO: Where is this value comming from?
+    // TODO: Which value can we use here?
+    // <http://docs.oasis-open.org/odata/odata/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml>
+    // is an external site we don't want to query each time an EDM-enabled client is used.
     writer.writeAttribute("Uri",
         "http://localhost:9080/olingo-server-tecsvc/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml");
     writer.writeEmptyElement(NS_EDMX, "Include");
-    // TODO: Where is this value comming from?
     writer.writeAttribute(XML_NAMESPACE, "Org.OData.Core.V1");
-    // TODO: Where is this value comming from?
     writer.writeAttribute(XML_ALIAS, "Core");
     writer.writeEndElement();
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f947afc1/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
index 926353f..77136b5 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java
@@ -32,7 +32,6 @@ import org.apache.olingo.server.api.OData;
 import org.apache.olingo.server.api.ODataApplicationException;
 import org.apache.olingo.server.api.ODataRequest;
 import org.apache.olingo.server.api.ODataResponse;
-import org.apache.olingo.server.api.ODataTranslatedException;
 import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
 import org.apache.olingo.server.api.processor.EntityProcessor;
 import org.apache.olingo.server.api.serializer.ODataSerializer;
@@ -76,12 +75,14 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc
       if (entitySet == null) {
         response.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode());
       } else {
-        ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
+        final ODataFormat format = ODataFormat.fromContentType(requestedContentType);
+        ODataSerializer serializer = odata.createSerializer(format);
         final ExpandOption expand = uriInfo.getExpandOption();
         final SelectOption select = uriInfo.getSelectOption();
         response.setContent(serializer.entitySet(edmEntitySet, entitySet,
             ODataSerializerOptions.with()
-                .contextURL(getContextUrl(serializer, edmEntitySet, false, expand, select))
+                .contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
+                    getContextUrl(serializer, edmEntitySet, false, expand, select))
                 .count(uriInfo.getCountOption())
                 .expand(expand).select(select)
                 .build()));
@@ -90,7 +91,7 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc
       }
     } catch (final DataProvider.DataProviderException e) {
       response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
-    } catch (final ODataTranslatedException e) {
+    } catch (final ODataSerializerException e) {
       response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
     } catch (final ODataApplicationException e) {
       response.setStatusCode(e.getStatusCode());
@@ -110,21 +111,23 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc
       if (entity == null) {
         response.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode());
       } else {
-        ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType));
+        final ODataFormat format = ODataFormat.fromContentType(requestedContentType);
+        ODataSerializer serializer = odata.createSerializer(format);
         final ExpandOption expand = uriInfo.getExpandOption();
         final SelectOption select = uriInfo.getSelectOption();
         response.setContent(serializer.entity(edmEntitySet, entity,
             ODataSerializerOptions.with()
-                .contextURL(getContextUrl(serializer, edmEntitySet, true, expand, select))
+                .contextURL(format == ODataFormat.JSON_NO_METADATA ? null :
+                    getContextUrl(serializer, edmEntitySet, true, expand, select))
                 .count(uriInfo.getCountOption())
-                .expand(uriInfo.getExpandOption()).select(uriInfo.getSelectOption())
+                .expand(expand).select(select)
                 .build()));
         response.setStatusCode(HttpStatusCode.OK.getStatusCode());
         response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
       }
     } catch (final DataProvider.DataProviderException e) {
       response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
-    } catch (final ODataTranslatedException e) {
+    } catch (final ODataSerializerException e) {
       response.setStatusCode(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode());
     } catch (final ODataApplicationException e) {
       response.setStatusCode(e.getStatusCode());


[2/3] git commit: better server error messages in case of $format errors

Posted by ch...@apache.org.
better server error messages in case of $format errors

Change-Id: If4495f5c91086618ee7d3824339aa5e7b99ff76c

Signed-off-by: Christian Amend <ch...@apache.org>


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

Branch: refs/heads/master
Commit: 788036db25637f9872c55346df208d4a0d4b93d4
Parents: f947afc
Author: Klaus Straubinger <kl...@sap.com>
Authored: Thu Sep 25 13:47:38 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Thu Sep 25 15:26:24 2014 +0200

----------------------------------------------------------------------
 .../apache/olingo/server/core/ODataExceptionHelper.java   |  9 ++++-----
 .../org/apache/olingo/server/core/uri/parser/Parser.java  |  3 +--
 .../server/core/uri/parser/UriParserSyntaxException.java  |  2 +-
 .../main/resources/server-core-exceptions-i18n.properties |  2 +-
 .../server/core/uri/antlr/TestFullResourcePath.java       | 10 +++++-----
 5 files changed, 12 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/788036db/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
index d0f248f..9b0ddfd 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataExceptionHelper.java
@@ -52,11 +52,10 @@ public class ODataExceptionHelper {
   
   public static ODataServerError createServerErrorObject(UriParserSyntaxException e, Locale requestedLocale) {
     ODataServerError serverError = basicTranslatedError(e, requestedLocale);
-    if(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE.equals(e.getMessageKey())){
-      serverError.setStatusCode(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode());
-    }else{
-      serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
-    }
+    serverError.setStatusCode(
+        UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT.equals(e.getMessageKey()) ?
+            HttpStatusCode.NOT_ACCEPTABLE.getStatusCode() :
+            HttpStatusCode.BAD_REQUEST.getStatusCode());
     return serverError;
   }
   

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/788036db/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
index 016aeb9..c2be438 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
@@ -188,8 +188,7 @@ public class Parser {
               formatOption.setFormat(option.value);
             } else {
               throw new UriParserSyntaxException("Illegal value of $format option!",
-                  UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE,
-                  option.name, option.value);
+                  UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT, option.value);
             }
             context.contextUriInfo.setSystemQueryOption(formatOption);
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/788036db/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
index e1506ee..454ed3b 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSyntaxException.java
@@ -28,7 +28,7 @@ public class UriParserSyntaxException extends UriParserException {
     /** parameters: query-option name, query-option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
     SYNTAX,
     SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE, 
-    /** parameter: query-option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE;
+    /** parameter: $format option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT;
 
     @Override
     public String getKey() {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/788036db/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
index 4695c73..57e805c 100644
--- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
+++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
@@ -26,7 +26,7 @@ ODataHandlerException.ODATA_VERSION_NOT_SUPPORTED=OData version '%1$s' is not su
 
 UriParserSyntaxException.UNKNOWN_SYSTEM_QUERY_OPTION=The system query option '%1$s' is not defined.
 UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION=The system query option '%1$s' has the not-allowed value '%2$s'.
-UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE=The system query option $value must be either json, xml, atom or a valid content-type. The value '%1$s' is neither.
+UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT=The system query option '$format' must be either 'json', 'xml', 'atom', or a valid content type; the value '%1$s' is neither.
 UriParserSyntaxException.SYNTAX=The URI is malformed.
 UriParserSyntaxException.SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE=The system query option '$levels' is not allowed here.
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/788036db/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index 5d7325b..856be6b 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -2553,15 +2553,15 @@ public class TestFullResourcePath {
         .isKind(UriInfoKind.resource).goPath()
         .isFormatText(HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8);
     testUri.runEx("ESKeyNav(1)?$format=noSlash")
-        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
+        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
     testUri.runEx("ESKeyNav(1)?$format=slashAtEnd/")
-        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
+        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
     testUri.runEx("ESKeyNav(1)?$format=/startsWithSlash")
-        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
+        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
     testUri.runEx("ESKeyNav(1)?$format=two/Slashes/tooMuch")
-        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
+        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
     testUri.runEx("ESKeyNav(1)?$format=")
-        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_VALUE);
+        .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
   }
 
   @Test


[3/3] git commit: better handling of parameters in server content negotiation

Posted by ch...@apache.org.
better handling of parameters in server content negotiation

Change-Id: Ie2771940b3afea6efb3dc84f8322bc60069052d1

Signed-off-by: Christian Amend <ch...@apache.org>


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

Branch: refs/heads/master
Commit: 7e0b013cef37c8353bcb29a25adf74721ba0afef
Parents: 788036d
Author: Klaus Straubinger <kl...@sap.com>
Authored: Thu Sep 25 13:45:39 2014 +0200
Committer: Christian Amend <ch...@apache.org>
Committed: Thu Sep 25 15:26:38 2014 +0200

----------------------------------------------------------------------
 .../olingo/commons/api/format/AcceptType.java   | 18 ++++--
 .../olingo/server/core/ContentNegotiator.java   | 58 ++++++++++----------
 .../server/core/ContentNegotiatorTest.java      | 43 ++++++++++-----
 3 files changed, 70 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7e0b013c/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 379eb95..2ac9a27 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
@@ -27,7 +27,7 @@ import java.util.TreeMap;
 
 /**
  * Internally used {@link AcceptType} for OData library.
- * 
+ *
  * See RFC 7231, chapter 5.3.2:
  * <pre>
  * Accept = #( media-range [ accept-params ] )
@@ -41,7 +41,7 @@ import java.util.TreeMap;
  * qvalue = ( "0" [ "." 0*3DIGIT ] ) / ( "1" [ "." 0*3("0") ] )
  * </pre>
  * 
- * Once created a {@link AcceptType} is <b>IMMUTABLE</b>.
+ * Once created an {@link AcceptType} is <b>IMMUTABLE</b>.
  */
 public class AcceptType {
 
@@ -82,7 +82,7 @@ public class AcceptType {
     if (TypeUtil.MEDIA_TYPE_WILDCARD.equals(this.type) && !TypeUtil.MEDIA_TYPE_WILDCARD.equals(subtype)) {
       throw new IllegalArgumentException("Illegal combination of WILDCARD type with NONE WILDCARD subtype.");
     }
-    
+
     final String q = parameters.get(TypeUtil.PARAMETER_Q);
     if (q == null) {
       quality = 1F;
@@ -124,7 +124,7 @@ public class AcceptType {
   }
 
   /**
-   * Create a list of {@link AcceptType} objects based on given input string (<code>format</code>).
+   * Creates a list of {@link AcceptType} objects based on given input string (<code>format</code>).
    * @param format accept types, comma-separated, as specified for the HTTP header <code>Accept</code>
    * @return a list of <code>AcceptType</code> objects
    * @throws IllegalArgumentException if input string is not parseable
@@ -142,6 +142,16 @@ public class AcceptType {
     return result;
   }
 
+  /**
+   * Creates a list of {@link AcceptType} objects based on given content type.
+   * @param contentType the content type
+   * @return an immutable one-element list of <code>AcceptType</code> objects that matches only the given content type
+   */
+  public static List<AcceptType> fromContentType(final ContentType contentType) {
+    return Collections.singletonList(new AcceptType(
+        contentType.getType(), contentType.getSubtype(), contentType.getParameters(), 1F));
+  }
+
   public String getType() {
     return type;
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7e0b013c/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 1adabf7..c6fb1bf 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
@@ -36,8 +36,7 @@ public class ContentNegotiator {
 
   private ContentNegotiator() {}
 
-  private static List<ContentType>
-      getDefaultSupportedContentTypes(final Class<? extends Processor> processorClass) {
+  private static List<ContentType> getDefaultSupportedContentTypes(final Class<? extends Processor> processorClass) {
     List<ContentType> defaults = new ArrayList<ContentType>();
 
     if (processorClass == MetadataProcessor.class) {
@@ -75,35 +74,23 @@ public class ContentNegotiator {
           ODataFormat.JSON.name().equalsIgnoreCase(formatString) ? ODataFormat.JSON :
           ODataFormat.XML.name().equalsIgnoreCase(formatString) ? ODataFormat.XML :
           ODataFormat.ATOM.name().equalsIgnoreCase(formatString) ? ODataFormat.ATOM : null;
-      result = getSupportedContentType(format == null ?
-          ContentType.create(formatOption.getFormat()) : format.getContentType(ODataServiceVersion.V40),
-          supportedContentTypes);
+      try {
+        result = getAcceptedType(
+            AcceptType.fromContentType(format == null ?
+                ContentType.create(formatOption.getFormat()) : format.getContentType(ODataServiceVersion.V40)),
+            supportedContentTypes);
+      } catch (final IllegalArgumentException e) {}
       if (result == null) {
         throw new ContentNegotiatorException("Unsupported $format = " + formatString,
             ContentNegotiatorException.MessageKeys.UNSUPPORTED_FORMAT_OPTION, formatString);
       }
     } else if (acceptHeaderValue != null) {
       final List<AcceptType> acceptedContentTypes = AcceptType.create(acceptHeaderValue);
-      for (AcceptType acceptedType : acceptedContentTypes) {
-        for (final ContentType supportedContentType : supportedContentTypes) {
-          ContentType contentType = supportedContentType;
-          if (acceptedType.getParameters().containsKey("charset")) {
-            final String value = acceptedType.getParameters().get("charset");
-            if ("utf8".equalsIgnoreCase(value) || "utf-8".equalsIgnoreCase(value)) {
-              contentType = ContentType.create(contentType, ContentType.PARAMETER_CHARSET_UTF8);
-            } else {
-              throw new ContentNegotiatorException("charset in accept header not supported: " + acceptHeaderValue,
-                  ContentNegotiatorException.MessageKeys.WRONG_CHARSET_IN_HEADER, HttpHeader.ACCEPT, acceptHeaderValue);
-            }
-          }
-          if (acceptedType.matches(contentType)) {
-            result = contentType;
-            break;
-          }
-        }
-        if (result != null) {
-          break;
-        }
+      try {
+        result = getAcceptedType(acceptedContentTypes, supportedContentTypes);
+      } catch (final IllegalArgumentException e) {
+        throw new ContentNegotiatorException("charset in accept header not supported: " + acceptHeaderValue, e,
+            ContentNegotiatorException.MessageKeys.WRONG_CHARSET_IN_HEADER, HttpHeader.ACCEPT, acceptHeaderValue);
       }
       if (result == null) {
         throw new ContentNegotiatorException(
@@ -114,7 +101,7 @@ public class ContentNegotiator {
       final ContentType requestedContentType = processorClass == MetadataProcessor.class ?
           ODataFormat.XML.getContentType(ODataServiceVersion.V40) :
           ODataFormat.JSON.getContentType(ODataServiceVersion.V40);
-      result = getSupportedContentType(requestedContentType, supportedContentTypes);
+      result = getAcceptedType(AcceptType.fromContentType(requestedContentType), supportedContentTypes);
       if (result == null) {
         throw new ContentNegotiatorException(
             "unsupported accept content type: " + requestedContentType + " != " + supportedContentTypes,
@@ -125,11 +112,22 @@ public class ContentNegotiator {
     return result;
   }
 
-  private static ContentType getSupportedContentType(final ContentType requestedContentType,
+  private static ContentType getAcceptedType(final List<AcceptType> acceptedContentTypes,
       final List<ContentType> supportedContentTypes) {
-    for (final ContentType supportedContentType : supportedContentTypes) {
-      if (requestedContentType.isCompatible(supportedContentType)) {
-        return supportedContentType;
+    for (final AcceptType acceptedType : acceptedContentTypes) {
+      for (final ContentType supportedContentType : supportedContentTypes) {
+        ContentType contentType = supportedContentType;
+        if (acceptedType.getParameters().containsKey("charset")) {
+          final String value = acceptedType.getParameters().get("charset");
+          if ("utf8".equalsIgnoreCase(value) || "utf-8".equalsIgnoreCase(value)) {
+            contentType = ContentType.create(contentType, ContentType.PARAMETER_CHARSET_UTF8);
+          } else {
+            throw new IllegalArgumentException("charset not supported: " + acceptedType);
+          }
+        }
+        if (acceptedType.matches(contentType)) {
+          return contentType;
+        }
       }
     }
     return null;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7e0b013c/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 61d0bc8..017a098 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
@@ -49,6 +49,7 @@ 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_NONE = "application/json;odata.metadata=none";
   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 = "*/*";
@@ -62,6 +63,7 @@ public class ContentNegotiatorTest {
       { ACCEPT_CASE_MIN,        null,             null,                  null             },
       { ACCEPT_CASE_MIN,        "json",           null,                  null             },
       { ACCEPT_CASE_MIN,        "json",           ACCEPT_CASE_JSONQ,     null             },
+      { ACCEPT_CASE_NONE,       ACCEPT_CASE_NONE, null,                  null             },
       { "a/a",                  "a/a",            null,                  "a/a"            },
       { ACCEPT_CASE_MIN,        null,             ACCEPT_CASE_JSONQ,     null             },
       { ACCEPT_CASE_MIN,        null,             ACCEPT_CASE_WILDCARD1, null             },
@@ -69,9 +71,11 @@ public class ContentNegotiatorTest {
       { "a/a",                  "a/a",            null,                  "a/a,b/b"        },
       { "a/a",                  " a/a ",          null,                  " a/a , b/b "    },
       { "a/a;x=y",              "a/a",            ACCEPT_CASE_WILDCARD1, "a/a;x=y"        },
+      { "a/a;v=w;x=y",          null,             "a/a;x=y",             "a/a;b=c,a/a;v=w;x=y" },
+      { "a/a;v=w;x=y",          "a/a;x=y",        null,                  "a/a;b=c,a/a;v=w;x=y" },
       { ACCEPT_CASE_MIN,        "json",           ACCEPT_CASE_MIN,       null             },
       { ACCEPT_CASE_FULL,       null,             ACCEPT_CASE_FULL,      ACCEPT_CASE_FULL }, 
-      { ACCEPT_CASE_MIN_UTF8,   null,             ACCEPT_CASE_MIN_UTF8,  null             },
+      { ACCEPT_CASE_MIN_UTF8,   null,             ACCEPT_CASE_MIN_UTF8,  null             }
   };                                                                                          
 
   String[][] casesMetadata = {                                                                 
@@ -85,24 +89,28 @@ public class ContentNegotiatorTest {
       { ACCEPT_CASE_XML,        null,             ACCEPT_CASE_WILDCARD2, null             },
       { "a/a",                  "a/a",            null,                  "a/a,b/b"        },
       { "a/a",                  " a/a ",          null,                  " a/a , b/b "    },
-      { "a/a;x=y",              "a/a",            ACCEPT_CASE_WILDCARD1, "a/a;x=y"        },
+      { "a/a;x=y",              "a/a",            ACCEPT_CASE_WILDCARD1, "a/a;x=y"        }
   };
 
   String[][] casesFail = {                                                                 
       /* expected               $format           accept                 additional content types */
-      { ACCEPT_CASE_XML,        "xxx/yyy",        null,                  null             },
-      { "a/a",                  "a/a",            null,                  "b/b"            },
-      { ACCEPT_CASE_XML,        null,             ACCEPT_CASE_JSONQ,     null             },
-      { "application/json",     null,             ACCEPT_CASE_FULL,      null             }, // not yet supported
+      { null,                   "xxx/yyy",        null,                  null             },
+      { null,                   "a/a",            null,                  "b/b"            },
+      { null,                   "a/a;x=y",        null,                  "a/a;v=w"        },
+      { null,                   null,             "a/a;x=y",             "a/a;v=w"        },
+      { null,                   "atom",           null,                  null             }, // not yet supported
+      { null,                   null,             ACCEPT_CASE_FULL,      null             }, // not yet supported
+      { null,                   "a/b;charset=ISO-8859-1", null,          "a/b"            },
+      { null,                   null,             "a/b;charset=ISO-8859-1", "a/b"         }
   };
   //CHECKSTYLE:ON
   //@formatter:on
 
   @Test
   public void testServiceDocumentSingleCase() throws Exception {
-    String[] useCase = { ACCEPT_CASE_MIN_UTF8, null, ACCEPT_CASE_MIN_UTF8, null };
-
-    testContentNegotiation(useCase, ServiceDocumentProcessor.class);
+    testContentNegotiation(
+        new String[] { ACCEPT_CASE_MIN_UTF8, null, ACCEPT_CASE_MIN_UTF8, null },
+        ServiceDocumentProcessor.class);
   }
 
   @Test
@@ -114,9 +122,12 @@ public class ContentNegotiatorTest {
 
   @Test
   public void testMetadataSingleCase() throws Exception {
-    String[] useCase = { ACCEPT_CASE_XML, null, null, null };
+    testContentNegotiation(new String[] { ACCEPT_CASE_XML, null, null, null }, MetadataProcessor.class);
+  }
 
-    testContentNegotiation(useCase, MetadataProcessor.class);
+  @Test(expected = ContentNegotiatorException.class)
+  public void testMetadataJsonFail() throws Exception {
+    testContentNegotiation(new String[] { null, "json", null, null }, MetadataProcessor.class);
   }
 
   @Test
@@ -127,11 +138,11 @@ public class ContentNegotiatorTest {
   }
 
   @Test
-  public void testMetadataFail() throws Exception {
+  public void testEntityCollectionFail() throws Exception {
     for (String[] useCase : casesFail) {
       try {
-        testContentNegotiation(useCase, MetadataProcessor.class);
-        fail("Exception expected!");
+        testContentNegotiation(useCase, EntityCollectionProcessor.class);
+        fail("Exception expected for '" + useCase[1] + '|' + useCase[2] + '|' + useCase[3] + "'!");
       } catch (final ContentNegotiatorException e) {}
     }
   }
@@ -157,7 +168,9 @@ public class ContentNegotiatorTest {
     final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(fo, request, p, processorClass);
 
     assertNotNull(requestedContentType);
-    assertEquals(ContentType.create(useCase[0]), requestedContentType);
+    if (useCase[0] != null) {
+      assertEquals(ContentType.create(useCase[0]), requestedContentType);
+    }
   }
 
   private List<ContentType> createCustomContentTypes(final String contentTypeString) {