You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ra...@apache.org on 2016/06/26 14:58:56 UTC
[2/4] olingo-odata4 git commit: OLINGO-567: Support for
odata.metadata=full
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3c0225c9/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index e4f62c2..9540dda 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -26,6 +26,7 @@ import java.nio.channels.WritableByteChannel;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
+import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
@@ -35,6 +36,7 @@ import org.apache.olingo.commons.api.data.ContextURL.Suffix;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.EntityCollection;
import org.apache.olingo.commons.api.data.EntityIterator;
+import org.apache.olingo.commons.api.data.Operation;
import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ValueType;
import org.apache.olingo.commons.api.edm.EdmComplexType;
@@ -83,6 +85,7 @@ public class ODataJsonSerializerTest {
private final DataProvider data = new DataProvider(odata, metadata.getEdm());
private final ODataSerializer serializer = new ODataJsonSerializer(ContentType.JSON);
private final ODataSerializer serializerNoMetadata = new ODataJsonSerializer(ContentType.JSON_NO_METADATA);
+ private final ODataSerializer serializerFullMetadata = new ODataJsonSerializer(ContentType.JSON_FULL_METADATA);
private final ODataSerializer serializerIEEECompatible =
new ODataJsonSerializer(ContentType.create(ContentType.JSON, ContentType.PARAMETER_IEEE754_COMPATIBLE, "true"));
private final UriHelper helper = odata.createUriHelper();
@@ -118,7 +121,130 @@ public class ODataJsonSerializerTest {
+ "}";
Assert.assertEquals(expectedResult, resultString);
}
+
+ @Test
+ public void entitySimpleMetadataFull() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
+ final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
+ InputStream result = serializerFullMetadata.entity(metadata, edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
+ .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
+ .build()).getContent();
+ final String resultString = IOUtils.toString(result);
+ final String expected = "{\"@odata.context\":\"$metadata#ESAllPrim/$entity\","
+ + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
+ + "\"@odata.type\":\"#olingo.odata.test1.ETAllPrim\","
+ + "\"@odata.id\":\"ESAllPrim(32767)\","
+ + "\"PropertyInt16@odata.type\":\"#Int16\","
+ + "\"PropertyInt16\":32767,"
+ + "\"PropertyString\":\"First Resource - positive values\","
+ + "\"PropertyBoolean\":true,"
+ + "\"PropertyByte@odata.type\":\"#Byte\","
+ + "\"PropertyByte\":255,"
+ + "\"PropertySByte@odata.type\":\"#SByte\","
+ + "\"PropertySByte\":127,"
+ + "\"PropertyInt32@odata.type\":\"#Int32\","
+ + "\"PropertyInt32\":2147483647,"
+ + "\"PropertyInt64@odata.type\":\"#Int64\","
+ + "\"PropertyInt64\":9223372036854775807,"
+ + "\"PropertySingle@odata.type\":\"#Single\","
+ + "\"PropertySingle\":1.79E20,"
+ + "\"PropertyDouble\":-1.79E19,"
+ + "\"PropertyDecimal@odata.type\":\"#Decimal\","
+ + "\"PropertyDecimal\":34,"
+ + "\"PropertyBinary@odata.type\":\"#Binary\","
+ + "\"PropertyBinary\":\"ASNFZ4mrze8=\","
+ + "\"PropertyDate@odata.type\":\"#Date\","
+ + "\"PropertyDate\":\"2012-12-03\","
+ + "\"PropertyDateTimeOffset@odata.type\":\"#DateTimeOffset\","
+ + "\"PropertyDateTimeOffset\":\"2012-12-03T07:16:23Z\","
+ + "\"PropertyDuration@odata.type\":\"#Duration\","
+ + "\"PropertyDuration\":\"PT6S\","
+ + "\"PropertyGuid@odata.type\":\"#Guid\","
+ + "\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\","
+ + "\"PropertyTimeOfDay@odata.type\":\"#TimeOfDay\","
+ + "\"PropertyTimeOfDay\":\"03:26:05\","
+ + "\"NavPropertyETTwoPrimOne@odata.navigationLink\":\"ESTwoPrim(32767)\","
+ + "\"NavPropertyETTwoPrimMany@odata.navigationLink\":\"ESAllPrim(32767)/NavPropertyETTwoPrimMany\","
+ + "\"#olingo.odata.test1.BAETAllPrimRT\":{"
+ + "\"title\":\"olingo.odata.test1.BAETAllPrimRT\","
+ + "\"target\":\"ESAllPrim(32767)/olingo.odata.test1.BAETAllPrimRT\""
+ + "}}";
+ Assert.assertEquals(expected, resultString);
+ }
+
+ @Test
+ public void entitySetMetadataFull() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
+ final EntityCollection entityCol = data.readAll(edmEntitySet);
+ InputStream result = serializerFullMetadata.entityCollection(metadata, edmEntitySet.getEntityType(), entityCol,
+ EntityCollectionSerializerOptions.with()
+ .contextURL(ContextURL.with().entitySet(edmEntitySet).build())
+ .build()).getContent();
+ final String resultString = IOUtils.toString(result);
+ final String expected = "{" +
+ "\"@odata.context\":\"$metadata#ESAllPrim\"," +
+ "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," +
+ "\"#olingo.odata.test1.BAESAllPrimRTETAllPrim\":{" +
+ "\"title\":\"olingo.odata.test1.BAESAllPrimRTETAllPrim\"," +
+ "\"target\":\"ESAllPrim/olingo.odata.test1.BAESAllPrimRTETAllPrim\"" +
+ "}," +
+ "\"#olingo.odata.test1.BAESAllPrimRT\":{" +
+ "\"title\":\"olingo.odata.test1.BAESAllPrimRT\"," +
+ "\"target\":\"ESAllPrim/olingo.odata.test1.BAESAllPrimRT\"" +
+ "}," +
+ "\"#olingo.odata.test1.BFNESAllPrimRTCTAllPrim\":{" +
+ "\"title\":\"olingo.odata.test1.BFNESAllPrimRTCTAllPrim\"," +
+ "\"target\":\"ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim\"" +
+ "}," +
+ "\"#olingo.odata.test1.BFNESAllPrimRTCTAllPrim(Param2)\":{" +
+ "\"title\":\"olingo.odata.test1.BFNESAllPrimRTCTAllPrim\"," +
+ "\"target\":\"ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim(Param2=@Param2)\"" +
+ "}," +
+ "\"value\":[" +
+ "{" +
+ "\"@odata.type\":\"#olingo.odata.test1.ETAllPrim\"," +
+ "\"@odata.id\":\"ESAllPrim(32767)\"," +
+ "\"PropertyInt16@odata.type\":\"#Int16\"," +
+ "\"PropertyInt16\":32767," +
+ "\"PropertyString\":\"First Resource - positive values\"," +
+ "\"PropertyBoolean\":true," +
+ "\"PropertyByte@odata.type\":\"#Byte\"," +
+ "\"PropertyByte\":255," +
+ "\"PropertySByte@odata.type\":\"#SByte\"," +
+ "\"PropertySByte\":127," +
+ "\"PropertyInt32@odata.type\":\"#Int32\"," +
+ "\"PropertyInt32\":2147483647," +
+ "\"PropertyInt64@odata.type\":\"#Int64\"," +
+ "\"PropertyInt64\":9223372036854775807," +
+ "\"PropertySingle@odata.type\":\"#Single\"," +
+ "\"PropertySingle\":1.79E20," +
+ "\"PropertyDouble\":-1.79E19," +
+ "\"PropertyDecimal@odata.type\":\"#Decimal\"," +
+ "\"PropertyDecimal\":34," +
+ "\"PropertyBinary@odata.type\":\"#Binary\"," +
+ "\"PropertyBinary\":\"ASNFZ4mrze8=\"," +
+ "\"PropertyDate@odata.type\":\"#Date\"," +
+ "\"PropertyDate\":\"2012-12-03\"," +
+ "\"PropertyDateTimeOffset@odata.type\":\"#DateTimeOffset\"," +
+ "\"PropertyDateTimeOffset\":\"2012-12-03T07:16:23Z\"," +
+ "\"PropertyDuration@odata.type\":\"#Duration\"," +
+ "\"PropertyDuration\":\"PT6S\"," +
+ "\"PropertyGuid@odata.type\":\"#Guid\"," +
+ "\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," +
+ "\"PropertyTimeOfDay@odata.type\":\"#TimeOfDay\"," +
+ "\"PropertyTimeOfDay\":\"03:26:05\"," +
+ "\"NavPropertyETTwoPrimOne@odata.navigationLink\":\"ESTwoPrim(32767)\"," +
+ "\"NavPropertyETTwoPrimMany@odata.navigationLink\":\"ESAllPrim(32767)/NavPropertyETTwoPrimMany\"," +
+ "\"#olingo.odata.test1.BAETAllPrimRT\":{" +
+ "\"title\":\"olingo.odata.test1.BAETAllPrimRT\"," +
+ "\"target\":\"ESAllPrim(32767)/olingo.odata.test1.BAETAllPrimRT\"" +
+ "}},";
+
+ Assert.assertTrue(resultString.startsWith(expected));
+ }
+
@Test
public void entityAllPrimAllNull() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
@@ -207,7 +333,14 @@ public class ODataJsonSerializerTest {
public void entityCollectionStreamed() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
final EntityIterator entityIterator = new EntityIterator() {
- Iterator<Entity> innerIterator = data.readAll(edmEntitySet).iterator();
+ EntityCollection entityCollection = data.readAll(edmEntitySet);
+ Iterator<Entity> innerIterator = entityCollection.iterator();
+
+ @Override
+ public List<Operation> getOperations() {
+ return entityCollection.getOperations();
+ }
+
@Override
public boolean hasNext() {
return innerIterator.hasNext();
@@ -248,7 +381,14 @@ public class ODataJsonSerializerTest {
public void entityCollectionStreamedWithError() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
final EntityIterator entityIterator = new EntityIterator() {
- Iterator<Entity> innerIterator = data.readAll(edmEntitySet).iterator();
+ EntityCollection entityCollection = data.readAll(edmEntitySet);
+ Iterator<Entity> innerIterator = entityCollection.iterator();
+
+ @Override
+ public List<Operation> getOperations() {
+ return entityCollection.getOperations();
+ }
+
@Override
public boolean hasNext() {
return innerIterator.hasNext();
@@ -502,6 +642,114 @@ public class ODataJsonSerializerTest {
}
@Test
+ public void entityTwoPrimWithMetadataMinimal() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
+ final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
+ InputStream result = serializer
+ .entity(metadata, edmEntitySet.getEntityType(), entity, EntitySerializerOptions.with()
+ .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
+ .build()).getContent();
+ final String resultString = IOUtils.toString(result);
+ final String expectedResult = "{\"@odata.context\":\"$metadata#ESTwoPrim/$entity\"," +
+ "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," +
+ "\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}";
+ Assert.assertEquals(expectedResult, resultString);
+ }
+
+ @Test
+ public void entitySetTwoPrimWithMetadataFull() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
+ final EntityCollection entitySet = data.readAll(edmEntitySet);
+ InputStream result = serializerFullMetadata
+ .entityCollection(metadata, edmEntitySet.getEntityType(), entitySet,
+ EntityCollectionSerializerOptions.with()
+ .contextURL(ContextURL.with().entitySet(edmEntitySet).build())
+ .build())
+ .getContent();
+ final String resultString = IOUtils.toString(result);
+ final String expectedResult = "{\"@odata.context\":\"$metadata#ESTwoPrim\","
+ + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
+ + "\"value\":[{\"@odata.type\":\"#olingo.odata.test1.ETTwoPrim\",\"@odata.id\":\"ESTwoPrim(32766)\","
+ + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":32766,"
+ + "\"PropertyString\":\"Test String1\"},"
+ + "{\"@odata.type\":\"#olingo.odata.test1.ETTwoPrim\",\"@odata.id\":\"ESTwoPrim(-365)\","
+ + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":-365,"
+ + "\"PropertyString\":\"Test String2\","
+ + "\"NavPropertyETAllPrimMany@odata.navigationLink\":\"ESTwoPrim(-365)/NavPropertyETAllPrimMany\"},"
+ + "{\"@odata.type\":\"#olingo.odata.test1.ETTwoPrim\",\"@odata.id\":\"ESTwoPrim(-32766)\","
+ + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":-32766,"
+ + "\"PropertyString\":null},"
+ + "{\"@odata.type\":\"#olingo.odata.test1.ETTwoPrim\",\"@odata.id\":\"ESTwoPrim(32767)\","
+ + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":32767,"
+ + "\"PropertyString\":\"Test String4\","
+ + "\"NavPropertyETAllPrimOne@odata.navigationLink\":\"ESAllPrim(32767)\"}]}";
+ Assert.assertEquals(expectedResult, resultString);
+ }
+
+ @Test
+ public void entityWithStreamMetadataMinimal() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESWithStream");
+ final EntityCollection collection = data.readAll(edmEntitySet);
+ InputStream result = serializer.entityCollection(metadata, edmEntitySet.getEntityType(), collection,
+ EntityCollectionSerializerOptions.with()
+ .contextURL(ContextURL.with().entitySet(edmEntitySet).build())
+ .build()).getContent();
+ final String resultString = IOUtils.toString(result);
+ final String expectedResult = "{\"@odata.context\":\"$metadata#ESWithStream\","
+ + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
+ + "\"value\":[{\"PropertyInt16\":32767},"
+ + "{\"PropertyInt16\":7,\"PropertyStream@odata.mediaEtag\":\"eTag\","
+ + "\"PropertyStream@odata.mediaContentType\":\"image/jpeg\"}]}";
+ Assert.assertEquals(expectedResult, resultString);
+ }
+
+ @Test
+ public void entityWithStreamMetadataNone() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESWithStream");
+ final EntityCollection collection = data.readAll(edmEntitySet);
+ InputStream result = serializerNoMetadata.entityCollection(metadata, edmEntitySet.getEntityType(), collection,
+ EntityCollectionSerializerOptions.with()
+ .contextURL(ContextURL.with().entitySet(edmEntitySet).build())
+ .build()).getContent();
+ final String resultString = IOUtils.toString(result);
+ final String expectedResult = "{"
+ + "\"value\":[{\"PropertyInt16\":32767},"
+ + "{\"PropertyInt16\":7}]}";
+ Assert.assertEquals(expectedResult, resultString);
+ }
+
+ @Test
+ public void entityWithStreamMetadataFull() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESWithStream");
+ final EntityCollection collection = data.readAll(edmEntitySet);
+ InputStream result = serializerFullMetadata.entityCollection(metadata, edmEntitySet.getEntityType(), collection,
+ EntityCollectionSerializerOptions.with()
+ .contextURL(ContextURL.with().entitySet(edmEntitySet).build())
+ .build()).getContent();
+ final String resultString = IOUtils.toString(result);
+ final String expectedResult = "{\"@odata.context\":\"$metadata#ESWithStream\","
+ + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
+ + "\"value\":[{"
+ + "\"@odata.type\":\"#olingo.odata.test1.ETWithStream\","
+ + "\"@odata.id\":\"ESWithStream(32767)\","
+ + "\"PropertyInt16@odata.type\":\"#Int16\","
+ + "\"PropertyInt16\":32767,"
+ + "\"PropertyStream@odata.type\":\"#Stream\","
+ + "\"PropertyStream@odata.mediaReadLink\":\"readLink\"},"
+ + "{"
+ + "\"@odata.type\":\"#olingo.odata.test1.ETWithStream\","
+ + "\"@odata.id\":\"ESWithStream(7)\","
+ + "\"PropertyInt16@odata.type\":\"#Int16\","
+ + "\"PropertyInt16\":7,"
+ + "\"PropertyStream@odata.type\":\"#Stream\","
+ + "\"PropertyStream@odata.mediaEtag\":\"eTag\","
+ + "\"PropertyStream@odata.mediaContentType\":\"image/jpeg\","
+ + "\"PropertyStream@odata.mediaEditLink\":\"http://mediaserver:1234/editLink\""
+ + "}]}";
+ Assert.assertEquals(expectedResult, resultString);
+ }
+
+ @Test
public void entitySetTwoPrimNoMetadata() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final EntityCollection entitySet = data.readAll(edmEntitySet);
@@ -559,6 +807,26 @@ public class ODataJsonSerializerTest {
}
@Test
+ public void entityMediaWithMetadataFull() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia");
+ final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
+ entity.setMediaETag("W/\\\"08D25949E3BFB7AB\\\"");
+ InputStream result = serializerFullMetadata
+ .entity(metadata, edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with().contextURL(ContextURL.with()
+ .entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()).build())
+ .getContent();
+ final String resultString = IOUtils.toString(result);
+ final String expectedResult = "{\"@odata.context\":\"$metadata#ESMedia/$entity\","
+ + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
+ + "\"@odata.mediaEtag\":\"W/\\\\\\\"08D25949E3BFB7AB\\\\\\\"\",\"@odata.mediaContentType\":\"image/svg+xml\","
+ + "\"@odata.mediaEditLink\":\"ESMedia(1)/$value\","
+ + "\"@odata.type\":\"#olingo.odata.test1.ETMedia\",\"@odata.id\":\"ESMedia(1)\","
+ + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":1}";
+ Assert.assertEquals(expectedResult, resultString);
+ }
+
+ @Test
public void primitiveValuesAllNull() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllNullable");
final EntityCollection entitySet = data.readAll(edmEntitySet);
@@ -932,6 +1200,29 @@ public class ODataJsonSerializerTest {
.primitive(metadata, (EdmPrimitiveType) edmProperty.getType(), property, null).getContent());
Assert.assertEquals("{\"value\":\"First Resource - positive values\"}", resultString);
}
+
+ @Test
+ public void primitivePropertyWithMetadataFull() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
+ final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType()
+ .getProperty("PropertyString");
+ final Property property = data.readAll(edmEntitySet).getEntities().get(0)
+ .getProperty(edmProperty.getName());
+ final String resultString = IOUtils
+ .toString(serializerFullMetadata
+ .primitive(metadata, (EdmPrimitiveType) edmProperty.getType(), property,
+ PrimitiveSerializerOptions.with()
+ .contextURL(ContextURL.with().entitySet(edmEntitySet)
+ .keyPath("32767")
+ .navOrPropertyPath(edmProperty.getName()).build())
+ .build())
+ .getContent());
+ Assert.assertEquals(
+ "{\"@odata.context\":\"$metadata#ESAllPrim(32767)/PropertyString\","
+ + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
+ + "\"value\":\"First Resource - positive values\"}",
+ resultString);
+ }
@Test(expected = SerializerException.class)
public void primitivePropertyNull() throws Exception {
@@ -979,6 +1270,25 @@ public class ODataJsonSerializerTest {
}
@Test
+ public void primitiveCollectionPropertyWithMetadataFull() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim");
+ final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyString");
+ final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName());
+
+ final String resultString = IOUtils.toString(serializerFullMetadata
+ .primitiveCollection(metadata, (EdmPrimitiveType) edmProperty.getType(), property,
+ PrimitiveSerializerOptions.with()
+ .contextURL(ContextURL.with()
+ .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName())
+ .build())
+ .build()).getContent());
+ Assert.assertEquals("{\"@odata.context\":\"$metadata#ESCollAllPrim(1)/CollPropertyString\"," +
+ "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," +
+ "\"@odata.type\":\"#Collection(String)\",\"value\":[\"Employee1@company.example\"," +
+ "\"Employee2@company.example\",\"Employee3@company.example\"]}", resultString);
+ }
+
+ @Test
public void complexProperty() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyComp");
@@ -1009,6 +1319,24 @@ public class ODataJsonSerializerTest {
}
@Test
+ public void complexPropertyWithMetadataFull() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
+ final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyComp");
+ final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty("PropertyComp");
+ final String resultString = IOUtils.toString(serializerFullMetadata
+ .complex(metadata, (EdmComplexType) edmProperty.getType(), property,
+ ComplexSerializerOptions.with()
+ .contextURL(ContextURL.with()
+ .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName())
+ .build()).build()).getContent());
+ Assert.assertEquals("{\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," +
+ "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," +
+ "\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," +
+ "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":111," +
+ "\"PropertyString\":\"TEST A\"}",resultString);
+ }
+
+ @Test
public void complexCollectionProperty() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyComp");
@@ -1044,6 +1372,34 @@ public class ODataJsonSerializerTest {
}
@Test
+ public void complexCollectionPropertyWithMetadataFull() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
+ final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyComp");
+ final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName());
+ final String resultString = IOUtils.toString(serializerFullMetadata
+ .complexCollection(metadata, (EdmComplexType) edmProperty.getType(),
+ property, ComplexSerializerOptions.with()
+ .contextURL(ContextURL.with().entitySet(edmEntitySet)
+ .keyPath("32767")
+ .navOrPropertyPath(edmProperty.getName()).build())
+ .build())
+ .getContent());
+ final String expectedResult = "{\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\","
+ + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
+ + "\"@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrim)\","
+ + "\"value\":[{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
+ + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":123,"
+ + "\"PropertyString\":\"TEST 1\"},"
+ + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
+ + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":456,"
+ + "\"PropertyString\":\"TEST 2\"},"
+ + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\","
+ + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":789,"
+ + "\"PropertyString\":\"TEST 3\"}]}";
+ Assert.assertEquals(expectedResult, resultString);
+ }
+
+ @Test
public void entityReference() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3c0225c9/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
index bd24f27..9a830d3 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
@@ -162,11 +162,171 @@ public class ODataXmlSerializerTest {
" </d:PropertyTimeOfDay>\n" +
" </m:properties>\n" +
" </a:content>\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAETAllPrimRT\" "+
+ " title=\"olingo.odata.test1.BAETAllPrimRT\" "+
+ " target=\"ESAllPrim(32767)/olingo.odata.test1.BAETAllPrimRT\" />\n" +
"</a:entry>";
checkXMLEqual(expected, resultString);
}
@Test
+ public void entitySetSimple() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
+ final EntityCollection entityCollection = data.readAll(edmEntitySet);
+ long currentTimeMillis = System.currentTimeMillis();
+ InputStream result = serializer.entityCollection(metadata, edmEntitySet.getEntityType(), entityCollection,
+ EntityCollectionSerializerOptions.with()
+ .contextURL(ContextURL.with().entitySet(edmEntitySet).build())
+ .build()).getContent();
+ final String resultString = IOUtils.toString(result);
+ String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\" "
+ + "xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ + "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ + "m:context=\"$metadata#ESAllPrim\" m:metadata-etag=\"metadataETag\">\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAESAllPrimRTETAllPrim\" "
+ + "title=\"olingo.odata.test1.BAESAllPrimRTETAllPrim\" "
+ + "target=\"ESAllPrim/olingo.odata.test1.BAESAllPrimRTETAllPrim\" />\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAESAllPrimRT\" "
+ + "title=\"olingo.odata.test1.BAESAllPrimRT\" "
+ + "target=\"ESAllPrim/olingo.odata.test1.BAESAllPrimRT\" />\n" +
+ " <m:function metadata=\"#olingo.odata.test1.BFNESAllPrimRTCTAllPrim\" "
+ + "title=\"olingo.odata.test1.BFNESAllPrimRTCTAllPrim\" "
+ + "target=\"ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim\" />\n" +
+ " <m:function metadata=\"#olingo.odata.test1.BFNESAllPrimRTCTAllPrim(Param2)\" "
+ + "title=\"olingo.odata.test1.BFNESAllPrimRTCTAllPrim\" "
+ + "target=\"ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim(Param2=@Param2)\" />\n" +
+ " <a:entry>\n" +
+ " <a:id>ESAllPrim(32767)</a:id>\n" +
+ " <a:title />\n" +
+ " <a:summary />\n" +
+ " <a:updated>"+ UPDATED_FORMAT.format(new Date(currentTimeMillis)) +"</a:updated>\n" +
+ " <a:author>\n" +
+ " <a:name />\n" +
+ " </a:author>\n" +
+ " <a:link rel=\"edit\" href=\"ESAllPrim(32767)\" />\n" +
+ " <a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimOne\" "
+ + "type=\"application/atom+xml;type=entry\" title=\"NavPropertyETTwoPrimOne\" "
+ + "href=\"ESTwoPrim(32767)\" />\n" +
+ " <a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimMany\" "
+ + "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETTwoPrimMany\" "
+ + "href=\"ESAllPrim(32767)/NavPropertyETTwoPrimMany\" />\n" +
+ " <a:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" "
+ + "term=\"#olingo.odata.test1.ETAllPrim\" />\n" +
+ " <a:content type=\"application/xml\">\n" +
+ " <m:properties>\n" +
+ " <d:PropertyInt16 m:type=\"Int16\">32767</d:PropertyInt16>\n" +
+ " <d:PropertyString>First Resource - positive values</d:PropertyString>\n" +
+ " <d:PropertyBoolean m:type=\"Boolean\">true</d:PropertyBoolean>\n" +
+ " <d:PropertyByte m:type=\"Byte\">255</d:PropertyByte>\n" +
+ " <d:PropertySByte m:type=\"SByte\">127</d:PropertySByte>\n" +
+ " <d:PropertyInt32 m:type=\"Int32\">2147483647</d:PropertyInt32>\n" +
+ " <d:PropertyInt64 m:type=\"Int64\">9223372036854775807</d:PropertyInt64>\n" +
+ " <d:PropertySingle m:type=\"Single\">1.79E20</d:PropertySingle>\n" +
+ " <d:PropertyDouble m:type=\"Double\">-1.79E19</d:PropertyDouble>\n" +
+ " <d:PropertyDecimal m:type=\"Decimal\">34</d:PropertyDecimal>\n" +
+ " <d:PropertyBinary m:type=\"Binary\">ASNFZ4mrze8=</d:PropertyBinary>\n" +
+ " <d:PropertyDate m:type=\"Date\">2012-12-03</d:PropertyDate>\n" +
+ " <d:PropertyDateTimeOffset m:type=\"DateTimeOffset\">2012-12-03T07:16:23Z"
+ + "</d:PropertyDateTimeOffset>\n" +
+ " <d:PropertyDuration m:type=\"Duration\">PT6S</d:PropertyDuration>\n" +
+ " <d:PropertyGuid m:type=\"Guid\">01234567-89ab-cdef-0123-456789abcdef</d:PropertyGuid>\n" +
+ " <d:PropertyTimeOfDay m:type=\"TimeOfDay\">03:26:05</d:PropertyTimeOfDay>\n" +
+ " </m:properties>\n" +
+ " </a:content>\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAETAllPrimRT\" "
+ + "title=\"olingo.odata.test1.BAETAllPrimRT\" "
+ + "target=\"ESAllPrim(32767)/olingo.odata.test1.BAETAllPrimRT\" />\n" +
+ " </a:entry>\n" +
+ " <a:entry>\n" +
+ " <a:id>ESAllPrim(-32768)</a:id>\n" +
+ " <a:title />\n" +
+ " <a:summary />\n" +
+ " <a:updated>"+ UPDATED_FORMAT.format(new Date(currentTimeMillis)) +"</a:updated>\n" +
+ " <a:author>\n" +
+ " <a:name />\n" +
+ " </a:author>\n" +
+ " <a:link rel=\"edit\" href=\"ESAllPrim(-32768)\" />\n" +
+ " <a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimOne\" "
+ + "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETTwoPrimOne\" "
+ + "href=\"ESAllPrim(-32768)/NavPropertyETTwoPrimOne\" />\n" +
+ " <a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimMany\" "
+ + "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETTwoPrimMany\" "
+ + "href=\"ESAllPrim(-32768)/NavPropertyETTwoPrimMany\" />\n" +
+ " <a:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" "
+ + "term=\"#olingo.odata.test1.ETAllPrim\" />\n" +
+ " <a:content type=\"application/xml\">\n" +
+ " <m:properties>\n" +
+ " <d:PropertyInt16 m:type=\"Int16\">-32768</d:PropertyInt16>\n" +
+ " <d:PropertyString>Second Resource - negative values</d:PropertyString>\n" +
+ " <d:PropertyBoolean m:type=\"Boolean\">false</d:PropertyBoolean>\n" +
+ " <d:PropertyByte m:type=\"Byte\">0</d:PropertyByte>\n" +
+ " <d:PropertySByte m:type=\"SByte\">-128</d:PropertySByte>\n" +
+ " <d:PropertyInt32 m:type=\"Int32\">-2147483648</d:PropertyInt32>\n" +
+ " <d:PropertyInt64 m:type=\"Int64\">-9223372036854775808</d:PropertyInt64>\n" +
+ " <d:PropertySingle m:type=\"Single\">-1.79E8</d:PropertySingle>\n" +
+ " <d:PropertyDouble m:type=\"Double\">-179000.0</d:PropertyDouble>\n" +
+ " <d:PropertyDecimal m:type=\"Decimal\">-34</d:PropertyDecimal>\n" +
+ " <d:PropertyBinary m:type=\"Binary\">ASNFZ4mrze8=</d:PropertyBinary>\n" +
+ " <d:PropertyDate m:type=\"Date\">2015-11-05</d:PropertyDate>\n" +
+ " <d:PropertyDateTimeOffset m:type=\"DateTimeOffset\">2005-12-03T07:17:08Z"
+ + "</d:PropertyDateTimeOffset>\n" +
+ " <d:PropertyDuration m:type=\"Duration\">PT9S</d:PropertyDuration>\n" +
+ " <d:PropertyGuid m:type=\"Guid\">76543201-23ab-cdef-0123-456789dddfff</d:PropertyGuid>\n" +
+ " <d:PropertyTimeOfDay m:type=\"TimeOfDay\">23:49:14</d:PropertyTimeOfDay>\n" +
+ " </m:properties>\n" +
+ " </a:content>\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAETAllPrimRT\" "
+ + "title=\"olingo.odata.test1.BAETAllPrimRT\" "
+ + "target=\"ESAllPrim(-32768)/olingo.odata.test1.BAETAllPrimRT\" />\n" +
+ " </a:entry>\n" +
+ " <a:entry>\n" +
+ " <a:id>ESAllPrim(0)</a:id>\n" +
+ " <a:title />\n" +
+ " <a:summary />\n" +
+ " <a:updated>"+ UPDATED_FORMAT.format(new Date(currentTimeMillis)) +"</a:updated>\n" +
+ " <a:author>\n" +
+ " <a:name />\n" +
+ " </a:author>\n" +
+ " <a:link rel=\"edit\" href=\"ESAllPrim(0)\" />\n" +
+ " <a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimOne\" "
+ + "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETTwoPrimOne\" "
+ + "href=\"ESAllPrim(0)/NavPropertyETTwoPrimOne\" />\n" +
+ " <a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimMany\" "
+ + "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETTwoPrimMany\" "
+ + "href=\"ESAllPrim(0)/NavPropertyETTwoPrimMany\" />\n" +
+ " <a:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" "
+ + "term=\"#olingo.odata.test1.ETAllPrim\" />\n" +
+ " <a:content type=\"application/xml\">\n" +
+ " <m:properties>\n" +
+ " <d:PropertyInt16 m:type=\"Int16\">0</d:PropertyInt16>\n" +
+ " <d:PropertyString />\n" +
+ " <d:PropertyBoolean m:type=\"Boolean\">false</d:PropertyBoolean>\n" +
+ " <d:PropertyByte m:type=\"Byte\">0</d:PropertyByte>\n" +
+ " <d:PropertySByte m:type=\"SByte\">0</d:PropertySByte>\n" +
+ " <d:PropertyInt32 m:type=\"Int32\">0</d:PropertyInt32>\n" +
+ " <d:PropertyInt64 m:type=\"Int64\">0</d:PropertyInt64>\n" +
+ " <d:PropertySingle m:type=\"Single\">0.0</d:PropertySingle>\n" +
+ " <d:PropertyDouble m:type=\"Double\">0.0</d:PropertyDouble>\n" +
+ " <d:PropertyDecimal m:type=\"Decimal\">0</d:PropertyDecimal>\n" +
+ " <d:PropertyBinary m:type=\"Binary\" />\n" +
+ " <d:PropertyDate m:type=\"Date\">1970-01-01</d:PropertyDate>\n" +
+ " <d:PropertyDateTimeOffset m:type=\"DateTimeOffset\">2005-12-03T00:00:00Z"
+ + "</d:PropertyDateTimeOffset>\n" +
+ " <d:PropertyDuration m:type=\"Duration\">PT0S</d:PropertyDuration>\n" +
+ " <d:PropertyGuid m:type=\"Guid\">76543201-23ab-cdef-0123-456789cccddd</d:PropertyGuid>\n" +
+ " <d:PropertyTimeOfDay m:type=\"TimeOfDay\">00:01:01</d:PropertyTimeOfDay>\n" +
+ " </m:properties>\n" +
+ " </a:content>\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAETAllPrimRT\" "
+ + "title=\"olingo.odata.test1.BAETAllPrimRT\" "
+ + "target=\"ESAllPrim(0)/olingo.odata.test1.BAETAllPrimRT\" />\n" +
+ " </a:entry>\n" +
+ "</a:feed>";
+ checkXMLEqual(expected, resultString);
+ }
+
+ @Test
public void entityAllPrimAllNull() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
@@ -223,6 +383,9 @@ public class ODataXmlSerializerTest {
" <d:PropertyTimeOfDay m:null=\"true\" />\n" +
" </m:properties>\n" +
" </a:content>\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAETAllPrimRT\" "+
+ " title=\"olingo.odata.test1.BAETAllPrimRT\" "+
+ " target=\"ESAllPrim(32767)/olingo.odata.test1.BAETAllPrimRT\" />\n" +
"</a:entry>\n" +
"";
checkXMLEqual(expected, resultString);
@@ -950,7 +1113,7 @@ public class ODataXmlSerializerTest {
.suffix(Suffix.ENTITY).build())
.select(select)
.build()).getContent();
- final String resultString = IOUtils.toString(result);
+ final String resultString = IOUtils.toString(result);
final String expectedResult = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<a:entry xmlns:a=\"http://www.w3.org/2005/Atom\"\n" +
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
@@ -981,6 +1144,9 @@ public class ODataXmlSerializerTest {
" <d:PropertyDate m:type=\"Date\">2012-12-03</d:PropertyDate>\n" +
" </m:properties>\n" +
" </a:content>\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAETAllPrimRT\" "+
+ " title=\"olingo.odata.test1.BAETAllPrimRT\" "+
+ " target=\"ESAllPrim(32767)/olingo.odata.test1.BAETAllPrimRT\" />\n" +
"</a:entry>";
checkXMLEqual(expectedResult, resultString);
}
@@ -1282,6 +1448,9 @@ public class ODataXmlSerializerTest {
" </d:PropertyTimeOfDay>\n" +
" </m:properties>\n" +
" </a:content>\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAETAllPrimRT\" "+
+ " title=\"olingo.odata.test1.BAETAllPrimRT\" "+
+ " target=\"ESAllPrim(32767)/olingo.odata.test1.BAETAllPrimRT\" />\n" +
" </a:entry>\n" +
" </m:inline>\n" +
" </a:link>\n" +
@@ -1321,7 +1490,7 @@ public class ODataXmlSerializerTest {
.suffix(Suffix.ENTITY).build())
.expand(expand)
.build()).getContent();
- final String resultString = IOUtils.toString(inputStream);
+ final String resultString = IOUtils.toString(inputStream);
String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<a:entry xmlns:a=\"http://www.w3.org/2005/Atom\" "
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
@@ -1365,6 +1534,9 @@ public class ODataXmlSerializerTest {
" <d:PropertyDate m:type=\"Date\">2012-12-03</d:PropertyDate>\n" +
" </m:properties>\n" +
" </a:content>\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAETAllPrimRT\" "+
+ " title=\"olingo.odata.test1.BAETAllPrimRT\" "+
+ " target=\"ESAllPrim(32767)/olingo.odata.test1.BAETAllPrimRT\" />\n" +
" </a:entry>\n" +
" </m:inline>\n" +
" </a:link>\n" +
@@ -1498,6 +1670,9 @@ public class ODataXmlSerializerTest {
" <d:PropertySByte m:type=\"SByte\">127</d:PropertySByte>\n" +
" </m:properties>\n" +
" </a:content>\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAETAllPrimRT\" "+
+ " title=\"olingo.odata.test1.BAETAllPrimRT\" "+
+ " target=\"ESAllPrim(32767)/olingo.odata.test1.BAETAllPrimRT\" />\n" +
"</a:entry>\n" +
"";
checkXMLEqual(expected, resultString);
@@ -1560,6 +1735,9 @@ public class ODataXmlSerializerTest {
" </d:PropertyTimeOfDay>\n" +
" </m:properties>\n" +
" </a:content>\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAETAllPrimRT\" "+
+ " title=\"olingo.odata.test1.BAETAllPrimRT\" "+
+ " target=\"ESAllPrim(-32768)/olingo.odata.test1.BAETAllPrimRT\" />\n" +
"</a:entry>";
checkXMLEqual(expected, resultString);
}
@@ -1644,6 +1822,9 @@ public class ODataXmlSerializerTest {
" <d:PropertyInt32 m:type=\"Int32\">-2147483648</d:PropertyInt32>\n" +
" </m:properties>\n" +
" </a:content>\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAETAllPrimRT\" "+
+ " title=\"olingo.odata.test1.BAETAllPrimRT\" "+
+ " target=\"ESAllPrim(-32768)/olingo.odata.test1.BAETAllPrimRT\" />\n" +
" </a:entry>\n" +
" <a:entry>\n" +
" <a:id>ESAllPrim(0)</a:id>\n" +
@@ -1758,6 +1939,9 @@ public class ODataXmlSerializerTest {
" <d:PropertyInt32 m:type=\"Int32\">0</d:PropertyInt32>\n" +
" </m:properties>\n" +
" </a:content>\n" +
+ " <m:action metadata=\"#olingo.odata.test1.BAETAllPrimRT\" "+
+ " title=\"olingo.odata.test1.BAETAllPrimRT\" "+
+ " target=\"ESAllPrim(0)/olingo.odata.test1.BAETAllPrimRT\" />\n" +
" </a:entry>\n" +
" </a:feed>\n" +
" </m:inline>\n" +