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 2015/06/29 13:54:33 UTC

[29/34] olingo-odata4 git commit: [OLINGO-704] Fix: OData Server supports only odata.metadata=minimal

[OLINGO-704] Fix: OData Server supports only odata.metadata=minimal


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

Branch: refs/heads/olingo712
Commit: e32034bd54072b0db4acaa1e374c4e0166a9b86e
Parents: 9998ba6
Author: Christian Holzer <c....@sap.com>
Authored: Wed Jun 24 17:31:52 2015 +0200
Committer: Christian Holzer <c....@sap.com>
Committed: Wed Jun 24 17:31:52 2015 +0200

----------------------------------------------------------------------
 .../fit/tecsvc/client/ActionImportITCase.java   |   2 +-
 .../apache/olingo/server/core/ODataImpl.java    | 174 ++++++++++---------
 .../olingo/server/core/ODataImplTest.java       |  58 +++++++
 3 files changed, 153 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e32034bd/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
index 316f0ce..22aea29 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
@@ -309,7 +309,7 @@ public class ActionImportITCase extends AbstractBaseTestITCase {
   @Override
   protected ODataClient getClient() {
     ODataClient odata = ODataClientFactory.getClient();
-    odata.getConfiguration().setDefaultPubFormat(ContentType.JSON_NO_METADATA);
+    odata.getConfiguration().setDefaultPubFormat(ContentType.JSON);
     return odata;
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e32034bd/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
index c3da9b4..8d41005 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
@@ -51,85 +51,99 @@ import org.apache.olingo.server.core.uri.UriHelperImpl;
 
 public class ODataImpl extends OData {
 
-  @Override
-  public ODataSerializer createSerializer(final ContentType contentType) throws SerializerException {
-    ODataSerializer serializer;
-    
-    // odata.metadata=none, odata.metadata=minimal, odata.metadata=full
-    if(contentType.isCompatible(ContentType.APPLICATION_JSON)) {
-      serializer = new ODataJsonSerializer(contentType);
-    } else if(contentType.isCompatible(ContentType.APPLICATION_XML)) {
-      serializer = new ODataXmlSerializerImpl();
-    } else {
-      throw new SerializerException("Unsupported format: " + contentType.toContentTypeString(),
-          SerializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
-    }
-
-    return serializer;
-  }
-
-  @Override
-  public FixedFormatSerializer createFixedFormatSerializer() {
-    return new FixedFormatSerializerImpl();
-  }
-
-  @Override
-  public ODataHttpHandler createHandler(final ServiceMetadata edm) {
-    return new ODataHttpHandlerImpl(this, edm);
-  }
-
-  @Override
-  public ServiceMetadata createServiceMetadata(final CsdlEdmProvider edmProvider,
-      final List<EdmxReference> references) {
-    return createServiceMetadata(edmProvider, references, null);
-  }
-
-  @Override
-  public ServiceMetadata createServiceMetadata(CsdlEdmProvider edmProvider, List<EdmxReference> references,
-      ServiceMetadataETagSupport serviceMetadataETagSupport) {
-    return new ServiceMetadataImpl(edmProvider, references, serviceMetadataETagSupport);
-  }
-
-  @Override
-  public FixedFormatDeserializer createFixedFormatDeserializer() {
-    return new FixedFormatDeserializerImpl();
-  }
-
-  @Override
-  public UriHelper createUriHelper() {
-    return new UriHelperImpl();
-  }
-
-  @Override
-  public ODataDeserializer createDeserializer(final ContentType contentType) throws DeserializerException {
-    ODataDeserializer deserializer;
-    
-    // odata.metadata=none, odata.metadata=minimal, odata.metadata=full
-    if(contentType.isCompatible(ContentType.JSON)) {
-      deserializer = new ODataJsonDeserializer(contentType);
-      //} else if(contentType.isCompatible(ContentType.APPLICATION_XML)) {
-      // We do not support XML deserialization right now so this must lead to an error.
-    } else  {
-      throw new DeserializerException("Unsupported format: " + contentType.toContentTypeString(),
-          DeserializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
-    }
-    
-    return deserializer;
-  }
-
-  @Override
-  public EdmPrimitiveType createPrimitiveTypeInstance(final EdmPrimitiveTypeKind kind) {
-    return EdmPrimitiveTypeFactory.getInstance(kind);
-  }
-
-  @Override
-  public ETagHelper createETagHelper() {
-    return new ETagHelperImpl();
-  }
-
-  @Override
-  public Preferences createPreferences(final Collection<String> preferHeaders) {
-    return new PreferencesImpl(preferHeaders);
-  }
+	@Override
+	public ODataSerializer createSerializer(final ContentType contentType)
+			throws SerializerException {
+		ODataSerializer serializer;
+
+		// odata.metadata=none, odata.metadata=minimal, odata.metadata=full
+		if (contentType.isCompatible(ContentType.APPLICATION_JSON)
+				&& ContentType.VALUE_ODATA_METADATA_MINIMAL
+				.equals(contentType.getParameter(ContentType.PARAMETER_ODATA_METADATA))) {
+			serializer = new ODataJsonSerializer(contentType);
+		} else if (contentType.isCompatible(ContentType.APPLICATION_XML)) {
+			serializer = new ODataXmlSerializerImpl();
+		} else {
+			throw new SerializerException("Unsupported format: "
+					+ contentType.toContentTypeString(),
+					SerializerException.MessageKeys.UNSUPPORTED_FORMAT,
+					contentType.toContentTypeString());
+		}
+
+		return serializer;
+	}
+
+	@Override
+	public FixedFormatSerializer createFixedFormatSerializer() {
+		return new FixedFormatSerializerImpl();
+	}
+
+	@Override
+	public ODataHttpHandler createHandler(final ServiceMetadata edm) {
+		return new ODataHttpHandlerImpl(this, edm);
+	}
+
+	@Override
+	public ServiceMetadata createServiceMetadata(
+			final CsdlEdmProvider edmProvider,
+			final List<EdmxReference> references) {
+		return createServiceMetadata(edmProvider, references, null);
+	}
+
+	@Override
+	public ServiceMetadata createServiceMetadata(CsdlEdmProvider edmProvider,
+			List<EdmxReference> references,
+			ServiceMetadataETagSupport serviceMetadataETagSupport) {
+		return new ServiceMetadataImpl(edmProvider, references,
+				serviceMetadataETagSupport);
+	}
+
+	@Override
+	public FixedFormatDeserializer createFixedFormatDeserializer() {
+		return new FixedFormatDeserializerImpl();
+	}
+
+	@Override
+	public UriHelper createUriHelper() {
+		return new UriHelperImpl();
+	}
+
+	@Override
+	public ODataDeserializer createDeserializer(final ContentType contentType)
+			throws DeserializerException {
+		ODataDeserializer deserializer;
+
+		// odata.metadata=none, odata.metadata=minimal, odata.metadata=full
+		if (contentType.isCompatible(ContentType.JSON)) {
+			deserializer = new ODataJsonDeserializer(contentType);
+			// } else if(contentType.isCompatible(ContentType.APPLICATION_XML))
+			// We do not support XML deserialization right now so this must lead
+			// to an error.
+			// {
+		} else {
+			throw new DeserializerException("Unsupported format: "
+					+ contentType.toContentTypeString(),
+					DeserializerException.MessageKeys.UNSUPPORTED_FORMAT,
+					contentType.toContentTypeString());
+		}
+
+		return deserializer;
+	}
+
+	@Override
+	public EdmPrimitiveType createPrimitiveTypeInstance(
+			final EdmPrimitiveTypeKind kind) {
+		return EdmPrimitiveTypeFactory.getInstance(kind);
+	}
+
+	@Override
+	public ETagHelper createETagHelper() {
+		return new ETagHelperImpl();
+	}
+
+	@Override
+	public Preferences createPreferences(final Collection<String> preferHeaders) {
+		return new PreferencesImpl(preferHeaders);
+	}
 
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e32034bd/lib/server-core/src/test/java/org/apache/olingo/server/core/ODataImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/ODataImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/ODataImplTest.java
new file mode 100644
index 0000000..bc48de9
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/ODataImplTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.server.core;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.deserializer.DeserializerException;
+import org.apache.olingo.server.api.deserializer.ODataDeserializer;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.api.serializer.SerializerException;
+import org.junit.Test;
+
+public class ODataImplTest {
+	
+	private final OData odata = OData.newInstance();
+	
+	@Test(expected=SerializerException.class)
+	public void testJsonSerializerForOdataMetadataNone() throws SerializerException {
+		odata.createSerializer(ContentType.JSON_NO_METADATA);
+	}
+	
+	@Test(expected=SerializerException.class)
+	public void testJsonSerializerForODataMetadataFull() throws SerializerException {
+		odata.createSerializer(ContentType.JSON_FULL_METADATA);
+	}
+	
+	@Test
+	public void testCreateJsonSerializerForODataMetadataMinimal() throws SerializerException {
+		final ODataSerializer serializer = odata.createSerializer(ContentType.JSON);
+		
+		assertNotNull(serializer);
+	}
+	
+	@Test
+	public void testCreateJsonDeserialierForODataMetadataMinimal() throws DeserializerException {
+		final ODataDeserializer deserializer = odata.createDeserializer(ContentType.JSON);
+		
+		assertNotNull(deserializer);
+	}
+}