diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandSelectITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandSelectITCase.java index 149966cce..939cd583e 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandSelectITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandSelectITCase.java @@ -90,7 +90,7 @@ public class ExpandSelectITCase extends AbstractParamTecSvcITCase { final ClientEntity entity = response.getBody(); assertNotNull(entity); - assertNull(entity.getProperty("PropertyInt16")); + assertNotNull(entity.getProperty("PropertyInt16")); final ClientProperty property = entity.getProperty("PropertyString"); assertNotNull(property); @@ -114,7 +114,7 @@ public class ExpandSelectITCase extends AbstractParamTecSvcITCase { assertNotNull(entities); assertEquals(2, entities.size()); final ClientEntity inlineEntity = entities.get(0); - assertEquals(2, inlineEntity.getProperties().size()); + assertEquals(3, inlineEntity.getProperties().size()); assertShortOrInt(-128, inlineEntity.getProperty("PropertySByte").getPrimitiveValue().toValue()); Calendar time = Calendar.getInstance(); time.clear(); diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java index 5d7e2b23d..270b1614c 100644 --- a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java +++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java @@ -357,7 +357,7 @@ public class TripPinServiceTest { public void testSelectOption() throws Exception { HttpResponse response = httpGET(baseURL + "/People('russellwhyte')?$select=FirstName,LastName", 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People(FirstName,LastName)/$entity", node.get("@odata.context").asText()); + assertEquals("$metadata#People(UserName,FirstName,LastName)/$entity", node.get("@odata.context").asText()); assertEquals("Russell", node.get("FirstName").asText()); } @@ -432,13 +432,13 @@ public class TripPinServiceTest { HttpResponse response = httpGET(baseURL+"/$entity?$id="+baseURL + "/People('kristakemp')&$select=FirstName", 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People(FirstName)/$entity", node.get("@odata.context").asText()); + assertEquals("$metadata#People(UserName,FirstName)/$entity", node.get("@odata.context").asText()); assertEquals("Krista", node.get("FirstName").asText()); // using relative URL response = httpGET(baseURL+"/$entity?$id="+"People('kristakemp')&$select=FirstName", 200); node = getJSONNode(response); - assertEquals("$metadata#People(FirstName)/$entity", node.get("@odata.context").asText()); + assertEquals("$metadata#People(UserName,FirstName)/$entity", node.get("@odata.context").asText()); assertEquals("Krista", node.get("FirstName").asText()); } 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 9d9c47abd..970d0c281 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 @@ -530,6 +530,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer { final boolean all = ExpandSelectHelper.isAll(select); final Set selected = all ? new HashSet() : ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems()); + addKeyPropertiesToSelected(selected, type); for (final String propertyName : type.getPropertyNames()) { if (all || selected.contains(propertyName)) { final EdmProperty edmProperty = type.getStructuralProperty(propertyName); @@ -540,6 +541,17 @@ public class ODataJsonSerializer extends AbstractODataSerializer { } } } + + private void addKeyPropertiesToSelected(Set selected, EdmStructuredType type) { + if (!selected.isEmpty() && type instanceof EdmEntityType) { + List keyNames = ((EdmEntityType) type).getKeyPredicateNames(); + for (String key : keyNames) { + if (!selected.contains(key)) { + selected.add(key); + } + } + } + } protected void writeNavigationProperties(final ServiceMetadata metadata, final EdmStructuredType type, final Linked linked, final ExpandOption expand, final Integer toDepth, diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java index 10e21b653..8e2a1bee3 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelper.java @@ -27,6 +27,7 @@ import org.apache.olingo.commons.api.edm.EdmAction; import org.apache.olingo.commons.api.edm.EdmComplexType; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmFunction; +import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; import org.apache.olingo.commons.api.edm.EdmNavigationProperty; import org.apache.olingo.commons.api.edm.EdmProperty; import org.apache.olingo.commons.api.edm.EdmStructuredType; @@ -85,10 +86,7 @@ public final class ContextURLHelper { for (final String propertyName : type.getNavigationPropertyNames()) { constructSelectItemList(type, result, selectItems, selectedPropertyNames, propertyName); } - if ((result.toString().length() == 0 && !selectItems.isEmpty()) || - (result.toString().split(",").length < selectItems.size())) { - constructSelectItemListForActionsAndFunctions(type, result, selectItems); - } + constructSelectItemListForActionsAndFunctions(type, result, selectItems); } } @@ -202,6 +200,16 @@ public final class ContextURLHelper { } } } + } else { + if (type instanceof EdmEntityType) { + final List keyNames = ((EdmEntityType) type).getKeyPredicateNames(); + if (keyNames.contains(propertyName)) { + if (result.length() > 0) { + result.append(','); + } + result.append(Encoder.encode(propertyName)); + } + } } } diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java index 4c1524bab..120638c86 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java @@ -630,6 +630,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer { final boolean all = ExpandSelectHelper.isAll(select); final Set selected = all ? new HashSet() : ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems()); + addKeyPropertiesToSelected(selected, type); for (final String propertyName : type.getPropertyNames()) { if (all || selected.contains(propertyName)) { final EdmProperty edmProperty = type.getStructuralProperty(propertyName); @@ -641,6 +642,17 @@ public class ODataXmlSerializer extends AbstractODataSerializer { } } + private void addKeyPropertiesToSelected(Set selected, EdmStructuredType type) { + if (!selected.isEmpty() && type instanceof EdmEntityType) { + List keyNames = ((EdmEntityType) type).getKeyPredicateNames(); + for (String key : keyNames) { + if (!selected.contains(key)) { + selected.add(key); + } + } + } + } + protected void writeNavigationProperties(final ServiceMetadata metadata, final EdmStructuredType type, final Linked linked, final ExpandOption expand, final Integer toDepth, final String xml10InvalidCharReplacement, final Set ancestors, String name, final XMLStreamWriter writer) diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java index f7bf6180d..dd7041b11 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java @@ -892,7 +892,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor throws ODataLibraryException { ContextURL contextUrl = isODataMetadataNone(requestedFormat) ? null : - getContextUrl(request.getRawODataPath(), edmEntitySet, edmEntityType, true, expand, null,isContNav); + getContextUrl(request.getRawODataPath(), edmEntitySet, edmEntityType, true, expand, select,isContNav); return odata.createSerializer(requestedFormat, request.getHeaders(HttpHeader.ODATA_VERSION)).entity( serviceMetadata, edmEntityType, diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerTest.java index af4c683ff..3e221d6c1 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerTest.java @@ -453,7 +453,7 @@ public class JsonDeltaSerializerTest { .select(select).build()).getContent(); String jsonString = IOUtils.toString(stream); Assert.assertEquals("{" - +"\"@odata.context\":\"$metadata#ESDelta(PropertyString)/$entity/$delta\"," + +"\"@odata.context\":\"$metadata#ESDelta(PropertyInt16,PropertyString)/$entity/$delta\"," + "\"value\":[{\"@odata.id\":\"ESDelta(32767)\",\"PropertyString\":\"Number:32767\"}," + "{\"@odata.id\":\"ESDelta(-32768)\",\"PropertyString\":\"Number:-32768\"}]}", jsonString); diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerWithNavigationsTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerWithNavigationsTest.java index 46c791cd5..c09caf96a 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerWithNavigationsTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/JsonDeltaSerializerWithNavigationsTest.java @@ -608,7 +608,8 @@ public class JsonDeltaSerializerWithNavigationsTest { .build()).getContent(); String jsonString = IOUtils.toString(stream); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESDelta(PropertyString,NavPropertyETAllPrimOne(PropertyString))/$delta\"," + + "\"@context\":\"$metadata#ESDelta(PropertyInt16,PropertyString,NavPropertyETAllPrimOne(" + + "PropertyInt16,PropertyString))/$delta\"," + "\"value\":[{\"@id\":\"ESDelta(100)\",\"PropertyInt16\":100,\"PropertyString\":\"Number:100\"," + "\"NavPropertyETAllPrimOne@delta\":{\"@id\":\"ESAllPrim(32767)\"," + "\"PropertyString\":\"First Resource - positive values\"}}]}", @@ -642,7 +643,7 @@ public class JsonDeltaSerializerWithNavigationsTest { .select(select).build()).getContent(); String jsonString = IOUtils.toString(stream); Assert.assertEquals("{" - +"\"@context\":\"$metadata#ESDelta(PropertyString)/$entity/$delta\"," + +"\"@context\":\"$metadata#ESDelta(PropertyInt16,PropertyString)/$entity/$delta\"," + "\"value\":[{\"@id\":\"ESDelta(32767)\",\"PropertyString\":\"Number:32767\"}," + "{\"@id\":\"ESDelta(-32768)\",\"PropertyString\":\"Number:-32768\"}]}", jsonString); 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 c5406939d..378ad1d2d 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 @@ -1162,9 +1162,9 @@ public class ODataJsonSerializerTest { .build()).getContent(); final String resultString = IOUtils.toString(result); final String expectedResult = "{" - + "\"@odata.context\":\"$metadata#ESAllPrim(PropertyBoolean,PropertyDate)/$entity\"," + + "\"@odata.context\":\"$metadata#ESAllPrim(PropertyInt16,PropertyBoolean,PropertyDate)/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," - + "\"@odata.id\":\"ESAllPrim(32767)\"," + + "\"@odata.id\":\"ESAllPrim(32767)\",\"PropertyInt16\":32767," + "\"PropertyBoolean\":true,\"PropertyDate\":\"2012-12-03\"}"; Assert.assertEquals(expectedResult, resultString); } @@ -1275,11 +1275,11 @@ public class ODataJsonSerializerTest { String expected = "{" + "\"@odata.context\":\"$metadata#ESFourKeyAlias" - + "(PropertyComp/PropertyString,PropertyCompComp/PropertyComp)\"," + + "(PropertyInt16,PropertyComp/PropertyString,PropertyCompComp/PropertyComp)\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[{" + "\"@odata.id\":\"ESFourKeyAlias(PropertyInt16=1,KeyAlias1=11,KeyAlias2='Num11',KeyAlias3='Num111')\"," - + "\"PropertyComp\":{" + + "\"PropertyInt16\":1,\"PropertyComp\":{" + "\"PropertyString\":\"Num11\"" + "}," + "\"PropertyCompComp\":{" @@ -1433,9 +1433,10 @@ public class ODataJsonSerializerTest { .build()).getContent(); Assert.assertNotNull(result); final String resultString = IOUtils.toString(result); - Assert.assertEquals( "{\"@odata.context\":\"$metadata#ESAllPrim(PropertyBoolean,PropertyDate)/$entity\","+ + Assert.assertEquals( "{\"@odata.context\":\"$metadata#ESAllPrim(PropertyInt16," + + "PropertyBoolean,PropertyDate)/$entity\","+ "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\",\"@odata.id\":\"ESAllPrim(32767)\","+ - "\"PropertyBoolean\":true,\"PropertyDate\":\"2012-12-03\"}", + "\"PropertyInt16\":32767,\"PropertyBoolean\":true,\"PropertyDate\":\"2012-12-03\"}", resultString); } @@ -1493,10 +1494,12 @@ public class ODataJsonSerializerTest { .expand(expand) .build()).getContent()); Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESTwoPrim(NavPropertyETAllPrimOne(PropertyDate))/$entity\"," + + "\"@odata.context\":\"$metadata#ESTwoPrim(PropertyInt16," + + "NavPropertyETAllPrimOne(PropertyInt16,PropertyDate))/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"," - + "\"NavPropertyETAllPrimOne\":{\"@odata.id\":\"ESAllPrim(32767)\",\"PropertyDate\":\"2012-12-03\"}}", + + "\"NavPropertyETAllPrimOne\":{\"@odata.id\":\"ESAllPrim(32767)\"," + + "\"PropertyInt16\":32767,\"PropertyDate\":\"2012-12-03\"}}", resultString); } @@ -1522,9 +1525,9 @@ public class ODataJsonSerializerTest { .select(select) .build()).getContent()); Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESAllPrim(PropertySByte)/$entity\"," + + "\"@odata.context\":\"$metadata#ESAllPrim(PropertyInt16,PropertySByte)/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," - + "\"@odata.id\":\"ESAllPrim(32767)\"," + + "\"@odata.id\":\"ESAllPrim(32767)\",\"PropertyInt16\":32767," + "\"PropertySByte\":127," + "\"NavPropertyETTwoPrimOne\":{\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"}," + "\"NavPropertyETTwoPrimMany\":[{\"PropertyInt16\":-365,\"PropertyString\":\"Test String2\"}]}", @@ -1551,9 +1554,9 @@ public class ODataJsonSerializerTest { .select(select) .build()).getContent()); Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESAllPrim(PropertyTimeOfDay)/$entity\"," + + "\"@odata.context\":\"$metadata#ESAllPrim(PropertyInt16,PropertyTimeOfDay)/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," - + "\"@odata.id\":\"ESAllPrim(-32768)\"," + + "\"@odata.id\":\"ESAllPrim(-32768)\",\"PropertyInt16\":-32768," + "\"PropertyTimeOfDay\":\"23:49:14\"," + "\"NavPropertyETTwoPrimOne\":null,\"NavPropertyETTwoPrimMany\":[]}", resultString); @@ -1583,13 +1586,14 @@ public class ODataJsonSerializerTest { .expand(expand) .build()).getContent()); Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESTwoPrim(NavPropertyETAllPrimMany(PropertyInt32))/$entity\"," + + "\"@odata.context\":\"$metadata#ESTwoPrim(PropertyInt16," + + "NavPropertyETAllPrimMany(PropertyInt16,PropertyInt32))/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":-365,\"PropertyString\":\"Test String2\"," + "\"NavPropertyETAllPrimMany\":[" - + "{\"@odata.id\":\"ESAllPrim(-32768)\",\"PropertyInt32\":-2147483648," + + "{\"@odata.id\":\"ESAllPrim(-32768)\",\"PropertyInt16\":-32768,\"PropertyInt32\":-2147483648," + "\"NavPropertyETTwoPrimOne\":null,\"NavPropertyETTwoPrimMany\":[]}," - + "{\"@odata.id\":\"ESAllPrim(0)\",\"PropertyInt32\":0,\"NavPropertyETTwoPrimOne\":{" + + "{\"@odata.id\":\"ESAllPrim(0)\",\"PropertyInt16\":0,\"PropertyInt32\":0,\"NavPropertyETTwoPrimOne\":{" + "\"@odata.type\":\"#olingo.odata.test1.ETBase\",\"PropertyInt16\":111," + "\"PropertyString\":\"TEST A\",\"AdditionalPropertyString_5\":\"TEST A 0815\"}," + "\"NavPropertyETTwoPrimMany\":[" @@ -1621,7 +1625,7 @@ public class ODataJsonSerializerTest { .suffix(Suffix.ENTITY).build()) .expand(expand) .build()).getContent()); - Assert.assertEquals("{\"@odata.context\":\"$metadata#ESTwoPrim/$entity\"," + Assert.assertEquals("{\"@odata.context\":\"$metadata#ESTwoPrim(PropertyInt16)/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":-365,\"PropertyString\":\"Test String2\"," + "\"NavPropertyETAllPrimOne\":null," @@ -2693,7 +2697,7 @@ public class ODataJsonSerializerTest { final String expectedResult = "{\"@odata.context\":\"$metadata#ESTwoKeyNav/$entity\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@odata.id\":\"ESTwoKeyNav(PropertyInt16=1,PropertyString='1')\"," - + "\"CollPropertyCompNav\":[{}]}"; + + "\"PropertyInt16\":1,\"PropertyString\":\"1\",\"CollPropertyCompNav\":[{}]}"; Assert.assertEquals(expectedResult, resultString); } } diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerv01Test.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerv01Test.java index 3b4187373..193758c8b 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerv01Test.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerv01Test.java @@ -1175,9 +1175,9 @@ public class ODataJsonSerializerv01Test { .build()).getContent(); final String resultString = IOUtils.toString(result); final String expectedResult = "{" - + "\"@context\":\"$metadata#ESAllPrim(PropertyBoolean,PropertyDate)/$entity\"," + + "\"@context\":\"$metadata#ESAllPrim(PropertyInt16,PropertyBoolean,PropertyDate)/$entity\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," - + "\"@id\":\"ESAllPrim(32767)\"," + + "\"@id\":\"ESAllPrim(32767)\",\"PropertyInt16\":32767," + "\"PropertyBoolean\":true,\"PropertyDate\":\"2012-12-03\"}"; Assert.assertEquals(expectedResult, resultString); } @@ -1288,11 +1288,11 @@ public class ODataJsonSerializerv01Test { String expected = "{" + "\"@context\":\"$metadata#ESFourKeyAlias" - + "(PropertyComp/PropertyString,PropertyCompComp/PropertyComp)\"," + + "(PropertyInt16,PropertyComp/PropertyString,PropertyCompComp/PropertyComp)\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[{" + "\"@id\":\"ESFourKeyAlias(PropertyInt16=1,KeyAlias1=11,KeyAlias2='Num11',KeyAlias3='Num111')\"," - + "\"PropertyComp\":{" + + "\"PropertyInt16\":1,\"PropertyComp\":{" + "\"PropertyString\":\"Num11\"" + "}," + "\"PropertyCompComp\":{" @@ -1446,9 +1446,10 @@ public class ODataJsonSerializerv01Test { .build()).getContent(); Assert.assertNotNull(result); final String resultString = IOUtils.toString(result); - Assert.assertEquals( "{\"@context\":\"$metadata#ESAllPrim(PropertyBoolean,PropertyDate)/$entity\","+ + Assert.assertEquals( "{\"@context\":\"$metadata#ESAllPrim(PropertyInt16," + + "PropertyBoolean,PropertyDate)/$entity\","+ "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\",\"@id\":\"ESAllPrim(32767)\","+ - "\"PropertyBoolean\":true,\"PropertyDate\":\"2012-12-03\"}", + "\"PropertyInt16\":32767,\"PropertyBoolean\":true,\"PropertyDate\":\"2012-12-03\"}", resultString); } @@ -1506,10 +1507,12 @@ public class ODataJsonSerializerv01Test { .expand(expand) .build()).getContent()); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESTwoPrim(NavPropertyETAllPrimOne(PropertyDate))/$entity\"," + + "\"@context\":\"$metadata#ESTwoPrim(PropertyInt16," + + "NavPropertyETAllPrimOne(PropertyInt16,PropertyDate))/$entity\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"," - + "\"NavPropertyETAllPrimOne\":{\"@id\":\"ESAllPrim(32767)\",\"PropertyDate\":\"2012-12-03\"}}", + + "\"NavPropertyETAllPrimOne\":{\"@id\":\"ESAllPrim(32767)\"," + + "\"PropertyInt16\":32767,\"PropertyDate\":\"2012-12-03\"}}", resultString); } @@ -1535,9 +1538,9 @@ public class ODataJsonSerializerv01Test { .select(select) .build()).getContent()); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESAllPrim(PropertySByte)/$entity\"," + + "\"@context\":\"$metadata#ESAllPrim(PropertyInt16,PropertySByte)/$entity\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," - + "\"@id\":\"ESAllPrim(32767)\"," + + "\"@id\":\"ESAllPrim(32767)\",\"PropertyInt16\":32767," + "\"PropertySByte\":127," + "\"NavPropertyETTwoPrimOne\":{\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"}," + "\"NavPropertyETTwoPrimMany\":[{\"PropertyInt16\":-365,\"PropertyString\":\"Test String2\"}]}", @@ -1564,9 +1567,9 @@ public class ODataJsonSerializerv01Test { .select(select) .build()).getContent()); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESAllPrim(PropertyTimeOfDay)/$entity\"," + + "\"@context\":\"$metadata#ESAllPrim(PropertyInt16,PropertyTimeOfDay)/$entity\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," - + "\"@id\":\"ESAllPrim(-32768)\"," + + "\"@id\":\"ESAllPrim(-32768)\",\"PropertyInt16\":-32768," + "\"PropertyTimeOfDay\":\"23:49:14\"," + "\"NavPropertyETTwoPrimOne\":null,\"NavPropertyETTwoPrimMany\":[]}", resultString); @@ -1596,13 +1599,14 @@ public class ODataJsonSerializerv01Test { .expand(expand) .build()).getContent()); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESTwoPrim(NavPropertyETAllPrimMany(PropertyInt32))/$entity\"," + + "\"@context\":\"$metadata#ESTwoPrim(PropertyInt16," + + "NavPropertyETAllPrimMany(PropertyInt16,PropertyInt32))/$entity\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":-365,\"PropertyString\":\"Test String2\"," + "\"NavPropertyETAllPrimMany\":[" - + "{\"@id\":\"ESAllPrim(-32768)\",\"PropertyInt32\":-2147483648," + + "{\"@id\":\"ESAllPrim(-32768)\",\"PropertyInt16\":-32768,\"PropertyInt32\":-2147483648," + "\"NavPropertyETTwoPrimOne\":null,\"NavPropertyETTwoPrimMany\":[]}," - + "{\"@id\":\"ESAllPrim(0)\",\"PropertyInt32\":0,\"NavPropertyETTwoPrimOne\":{" + + "{\"@id\":\"ESAllPrim(0)\",\"PropertyInt16\":0,\"PropertyInt32\":0,\"NavPropertyETTwoPrimOne\":{" + "\"@type\":\"#olingo.odata.test1.ETBase\",\"PropertyInt16\":111," + "\"PropertyString\":\"TEST A\",\"AdditionalPropertyString_5\":\"TEST A 0815\"}," + "\"NavPropertyETTwoPrimMany\":[" @@ -1634,7 +1638,7 @@ public class ODataJsonSerializerv01Test { .suffix(Suffix.ENTITY).build()) .expand(expand) .build()).getContent()); - Assert.assertEquals("{\"@context\":\"$metadata#ESTwoPrim/$entity\"," + Assert.assertEquals("{\"@context\":\"$metadata#ESTwoPrim(PropertyInt16)/$entity\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":-365,\"PropertyString\":\"Test String2\"," + "\"NavPropertyETAllPrimOne\":null," diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java index 95bc60072..acbf2e4b7 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java @@ -223,8 +223,8 @@ public class ContextURLHelperTest { final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem)); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, select)).build(); - assertEquals("$metadata#ESTwoPrim(PropertyString,NavPropertyETAllPrimOne()," - + "NavPropertyETAllPrimMany(PropertyInt32))", + assertEquals("$metadata#ESTwoPrim(PropertyInt16,PropertyString,NavPropertyETAllPrimOne()," + + "NavPropertyETAllPrimMany(PropertyInt16,PropertyInt32))", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -342,7 +342,8 @@ public class ContextURLHelperTest { final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem)); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESCompCollDerived(PropertyCompAno/olingo.odata.test1.CTBaseAno/AdditionalPropString)", + assertEquals("$metadata#ESCompCollDerived(PropertyInt16,PropertyCompAno/" + + "olingo.odata.test1.CTBaseAno/AdditionalPropString)", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -356,7 +357,7 @@ public class ContextURLHelperTest { final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem)); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESCompCollComp(PropertyComp/CollPropertyComp/" + assertEquals("$metadata#ESCompCollComp(PropertyInt16,PropertyComp/CollPropertyComp/" + "olingo.odata.test1.CTBase/AdditionalPropString)", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -372,7 +373,9 @@ public class ContextURLHelperTest { final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem)); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESTwoKeyNav(olingo.odata.test1.ETBaseTwoKeyNav/NavPropertyETBaseTwoKeyNavOne)", + assertEquals("$metadata#ESTwoKeyNav(PropertyInt16,PropertyString," + + "olingo.odata.test1.ETBaseTwoKeyNav/" + + "NavPropertyETBaseTwoKeyNavOne)", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -387,7 +390,8 @@ public class ContextURLHelperTest { final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem)); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESTwoKeyNav(olingo.odata.test1.ETBaseTwoKeyNav/PropertyDate)", + assertEquals("$metadata#ESTwoKeyNav(PropertyInt16,PropertyString," + + "olingo.odata.test1.ETBaseTwoKeyNav/PropertyDate)", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -403,7 +407,8 @@ public class ContextURLHelperTest { final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem1, selectItem2)); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESTwoKeyNav(CollPropertyComp,olingo.odata.test1.ETBaseTwoKeyNav/" + assertEquals("$metadata#ESTwoKeyNav(PropertyInt16,PropertyString," + + "CollPropertyComp,olingo.odata.test1.ETBaseTwoKeyNav/" + "NavPropertyETTwoBaseTwoKeyNavOne)", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -421,7 +426,8 @@ public class ContextURLHelperTest { final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem)); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESTwoKeyNav(olingo.odata.test1.ETBaseTwoKeyNav/CollPropertyComp/" + assertEquals("$metadata#ESTwoKeyNav(PropertyInt16,PropertyString," + + "olingo.odata.test1.ETBaseTwoKeyNav/CollPropertyComp/" + "olingo.odata.test1.CTBasePrimCompNav/NavPropertyETTwoKeyNavOne)", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -443,7 +449,7 @@ public class ContextURLHelperTest { final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, null)).build(); assertEquals("$metadata#ESKeyNavCont(NavPropertyETTwoKeyNavContOne(" - + "olingo.odata.test1.ETBaseTwoKeyNav/PropertyDate))", + + "PropertyInt16,PropertyString,olingo.odata.test1.ETBaseTwoKeyNav/PropertyDate))", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -456,7 +462,8 @@ public class ContextURLHelperTest { selectItem)); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESTwoKeyNav(CollPropertyCompNav/NavPropertyETTwoKeyNavMany)", + assertEquals("$metadata#ESTwoKeyNav(PropertyInt16,PropertyString," + + "CollPropertyCompNav/NavPropertyETTwoKeyNavMany)", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -472,7 +479,8 @@ public class ContextURLHelperTest { selectItem)); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESTwoKeyNav(olingo.odata.test1.BAESTwoKeyNavRTESTwoKeyNav)", + assertEquals("$metadata#ESTwoKeyNav(PropertyInt16,PropertyString," + + "olingo.odata.test1.BAESTwoKeyNavRTESTwoKeyNav)", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -490,7 +498,8 @@ public class ContextURLHelperTest { selectItem1, selectItem2)); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESTwoKeyNav(PropertyString,olingo.odata.test1.BAESTwoKeyNavRTESTwoKeyNav)", + assertEquals("$metadata#ESTwoKeyNav(PropertyInt16,PropertyString," + + "olingo.odata.test1.BAESTwoKeyNavRTESTwoKeyNav)", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -506,7 +515,8 @@ public class ContextURLHelperTest { selectItem)); final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESTwoKeyNav(olingo.odata.test1.BFCESTwoKeyNavRTString)", + assertEquals("$metadata#ESTwoKeyNav(PropertyInt16,PropertyString," + + "olingo.odata.test1.BFCESTwoKeyNavRTString)", ContextURLBuilder.create(contextURL).toASCIIString()); } } 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 c1f112da6..40fa334e0 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 @@ -1521,7 +1521,7 @@ public class ODataXmlSerializerTest { "\n" + " ESAllPrim(32767)\n" + " \n" + @@ -1543,6 +1543,7 @@ public class ODataXmlSerializerTest { " term=\"#olingo.odata.test1.ETAllPrim\" />\n" + " \n" + " \n" + + " 32767" + " true\n" + " 2012-12-03\n" + " \n" + @@ -1685,7 +1686,7 @@ public class ODataXmlSerializerTest { "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" + "xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" \n" + "m:context=\"$metadata#ESFourKeyAlias" + - "(PropertyComp/PropertyString,PropertyCompComp/PropertyComp)\"\n" + + "(PropertyInt16,PropertyComp/PropertyString,PropertyCompComp/PropertyComp)\"\n" + "m:metadata-etag=\"metadataETag\">\n" + "http://host/svc/ESFourKeyAlias\n" + "\n" + @@ -1702,6 +1703,7 @@ public class ODataXmlSerializerTest { "term=\"#olingo.odata.test1.ETFourKeyAlias\"/>\n" + "\n" + "\n" + + " 1" + "\n" + "Num11\n" + "\n" + @@ -1951,7 +1953,8 @@ public class ODataXmlSerializerTest { "\n" + " ESTwoPrim(32767)\n" + " \n" + @@ -1987,6 +1990,7 @@ public class ODataXmlSerializerTest { " term=\"#olingo.odata.test1.ETAllPrim\" />\n" + " \n" + " \n" + + " 32767" + " 2012-12-03\n" + " \n" + " \n" + @@ -2051,7 +2055,7 @@ public class ODataXmlSerializerTest { "\n" + " ESAllPrim(32767)\n" + " \n" + @@ -2159,6 +2163,7 @@ public class ODataXmlSerializerTest { " term=\"#olingo.odata.test1.ETAllPrim\" />\n" + " \n" + " \n" + + " 32767" + " 127\n" + " \n" + " \n" + @@ -2195,7 +2200,7 @@ public class ODataXmlSerializerTest { "\n" + " ESAllPrim(-32768)\n" + " \n" + @@ -2223,6 +2228,7 @@ public class ODataXmlSerializerTest { " term=\"#olingo.odata.test1.ETAllPrim\" />\n" + " \n" + " \n" + + " -32768" + " 23:49:14\n" + " \n" + " \n" + @@ -2263,7 +2269,8 @@ public class ODataXmlSerializerTest { "\n" + " ESTwoPrim(-365)\n" + " \n" + @@ -2311,6 +2318,7 @@ public class ODataXmlSerializerTest { " term=\"#olingo.odata.test1.ETAllPrim\" />\n" + " \n" + " \n" + + " -32768" + " -2147483648\n" + " \n" + " \n" + @@ -2494,6 +2502,7 @@ public class ODataXmlSerializerTest { " term=\"#olingo.odata.test1.ETAllPrim\" />\n" + " \n" + " \n" + + " 0" + " 0\n" + " \n" + " \n" +