Repository: olingo-odata4 Updated Branches: refs/heads/master c81833d50 -> b07a7cfe2
[OLINGO-1246]Handling relative url's in odata context and few enhancements to technical service Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/b07a7cfe Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/b07a7cfe Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/b07a7cfe Branch: refs/heads/master Commit: b07a7cfe2616ec50cc1c068172d639ef3908e5de Parents: c81833d Author: ramya vasanth <ramya.vasa...@sap.com> Authored: Mon May 7 13:54:59 2018 +0530 Committer: ramya vasanth <ramya.vasa...@sap.com> Committed: Mon May 7 13:54:59 2018 +0530 ---------------------------------------------------------------------- .../tecsvc/client/PrimitiveComplexITCase.java | 4 +- .../fit/tecsvc/http/BasicAsyncITCase.java | 2 +- .../olingo/fit/tecsvc/http/BasicHttpITCase.java | 13 +++ .../fit/tecsvc/http/EntityReferenceITCase.java | 4 +- .../server/example/TripPinServiceTest.java | 26 +++--- .../serializer/utils/ContextURLBuilder.java | 13 ++- .../serializer/utils/ContextURLBuilderTest.java | 2 +- .../processor/TechnicalEntityProcessor.java | 1 + .../expression/ExpressionVisitorImpl.java | 6 +- .../queryoptions/options/SearchHandler.java | 83 ++++++++++++++++++-- .../json/ODataJsonSerializerTest.java | 38 ++++----- .../json/ODataJsonSerializerv01Test.java | 34 ++++---- .../serializer/utils/ContextURLHelperTest.java | 6 +- .../serializer/xml/ODataXmlSerializerTest.java | 20 ++--- 14 files changed, 177 insertions(+), 75 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java index 3c19028..86b965b 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/PrimitiveComplexITCase.java @@ -90,7 +90,7 @@ public class PrimitiveComplexITCase extends AbstractParamTecSvcITCase { if (isJson()) { String actualResult = IOUtils.toString(response.getRawResponse(), "UTF-8"); - assertTrue(actualResult.startsWith("{\"@odata.context\":\"$metadata#ESTwoPrim(32766)/PropertyString\",")); + assertTrue(actualResult.startsWith("{\"@odata.context\":\"../$metadata#ESTwoPrim(32766)/PropertyString\",")); assertTrue(actualResult.endsWith("\"value\":\"Test String1\"}")); } else { ClientProperty property = response.getBody(); @@ -179,7 +179,7 @@ public class PrimitiveComplexITCase extends AbstractParamTecSvcITCase { if (isJson()) { String actualResult = IOUtils.toString(response.getRawResponse(), "UTF-8"); - assertTrue(actualResult.startsWith("{\"@odata.context\":\"$metadata#ESMixPrimCollComp(7)/PropertyComp\",")); + assertTrue(actualResult.startsWith("{\"@odata.context\":\"../$metadata#ESMixPrimCollComp(7)/PropertyComp\",")); assertTrue(actualResult.endsWith("\"PropertyInt16\":222,\"PropertyString\":\"TEST B\"}")); } else { ClientProperty property = response.getBody(); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicAsyncITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicAsyncITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicAsyncITCase.java index 845330f..2763d48 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicAsyncITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicAsyncITCase.java @@ -137,7 +137,7 @@ public class BasicAsyncITCase extends AbstractBaseTestITCase { Map<String, List<String>> resultHeaderFields = result.getHeaderFields(); String resBody = resultBody.asString(); assertEquals("HTTP/1.1 200 OK", resultHeaderFields.get(null).get(0)); - assertEquals(2318, resultBody.byteLength()); + assertEquals(2321, resultBody.byteLength()); contains(resBody, "HTTP/1.1 200 OK", "OData-Version: 4.0", http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java index bb3bd57..7018e36 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicHttpITCase.java @@ -392,4 +392,17 @@ public class BasicHttpITCase extends AbstractBaseTestITCase { assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode()); } + + @Test + public void testCountWithSearch() throws Exception { + URL url = new URL(SERVICE_URI + "ESTwoPrim/$count?$search=%2232%22"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals("3", IOUtils.toString(connection.getInputStream())); + connection.disconnect(); + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/EntityReferenceITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/EntityReferenceITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/EntityReferenceITCase.java index 359feb7..6d63638 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/EntityReferenceITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/EntityReferenceITCase.java @@ -36,8 +36,8 @@ import org.junit.Test; public class EntityReferenceITCase extends AbstractBaseTestITCase { - private static final String CONTEXT_ENTITY_REFERENCE = "\"@odata.context\":\"$metadata#$ref\""; - private static final String CONTEXT_COLLECTION_REFERENCE = "\"@odata.context\":\"$metadata#Collection($ref)"; + private static final String CONTEXT_ENTITY_REFERENCE = "\"@odata.context\":\"../$metadata#$ref\""; + private static final String CONTEXT_COLLECTION_REFERENCE = "\"@odata.context\":\"../$metadata#Collection($ref)"; private static final String SERVICE_URI = TecSvcConst.BASE_URI; @Test http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java ---------------------------------------------------------------------- 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 270b161..7f56463 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 @@ -211,7 +211,7 @@ public class TripPinServiceTest { public void testReadPrimitiveProperty() throws Exception { HttpResponse response = httpGET(baseURL + "/Airlines('AA')/Name", 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#Airlines('AA')/Name", node.get("@odata.context").asText()); + assertEquals("../$metadata#Airlines('AA')/Name", node.get("@odata.context").asText()); assertEquals("American Airlines", node.get("value").asText()); } @@ -225,7 +225,7 @@ public class TripPinServiceTest { public void testReadPrimitiveArrayProperty() throws Exception { HttpResponse response = httpGET(baseURL + "/People('russellwhyte')/Emails", 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People('russellwhyte')/Emails", node.get("@odata.context").asText()); + assertEquals("../$metadata#People('russellwhyte')/Emails", node.get("@odata.context").asText()); assertTrue(node.get("value").isArray()); assertEquals("russ...@example.com", ((ArrayNode)node.get("value")).get(0).asText()); assertEquals("russ...@contoso.com", ((ArrayNode)node.get("value")).get(1).asText()); @@ -262,7 +262,7 @@ public class TripPinServiceTest { public void testReadComplexArrayProperty() throws Exception { HttpResponse response = httpGET(baseURL + "/People('russellwhyte')/AddressInfo", 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People('russellwhyte')/AddressInfo", node.get("@odata.context").asText()); + assertEquals("../$metadata#People('russellwhyte')/AddressInfo", node.get("@odata.context").asText()); assertTrue(node.get("value").isArray()); assertEquals("187 Suffolk Ln.", ((ArrayNode)node.get("value")).get(0).get("Address").asText()); } @@ -393,7 +393,7 @@ public class TripPinServiceTest { public void testReadReferences() throws Exception { HttpResponse response = httpGET(baseURL + "/People('russellwhyte')/Friends/$ref", 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#Collection($ref)", node.get("@odata.context").asText()); + assertEquals("../$metadata#Collection($ref)", node.get("@odata.context").asText()); assertTrue(node.get("value").isArray()); assertEquals("/People('scottketchum')", ((ArrayNode)node.get("value")).get(0).get("@odata.id").asText()); } @@ -565,7 +565,7 @@ public class TripPinServiceTest { response = httpGET(editUrl, 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People('russellwhyte')/FirstName", node.get("@odata.context").asText()); + assertEquals("../$metadata#People('russellwhyte')/FirstName", node.get("@odata.context").asText()); assertEquals("Pilar Ackerman", node.get("value").asText()); } @@ -585,7 +585,7 @@ public class TripPinServiceTest { response = httpGET(editUrl, 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People('russellwhyte')/Emails", node.get("@odata.context").asText()); + assertEquals("../$metadata#People('russellwhyte')/Emails", node.get("@odata.context").asText()); assertTrue(node.get("value").isArray()); assertEquals("oli...@apache.com", ((ArrayNode)node.get("value")).get(0).asText()); } @@ -637,7 +637,7 @@ public class TripPinServiceTest { String editUrl = baseURL + "/People('russellwhyte')/Friends('scottketchum')/Trips"; HttpResponse response = httpGET(editUrl, 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People('russellwhyte')/Friends('scottketchum')/Trips", + assertEquals("../../$metadata#People('russellwhyte')/Friends('scottketchum')/Trips", node.get("@odata.context").asText()); assertTrue(node.get("value").isArray()); assertEquals("1001", ((ArrayNode)node.get("value")).get(0).get("TripId").asText()); @@ -648,7 +648,7 @@ public class TripPinServiceTest { String editUrl = baseURL + "/People('russellwhyte')/Trips(1003)"; HttpResponse response = httpGET(editUrl, 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People('russellwhyte')/Trips/$entity", + assertEquals("../$metadata#People('russellwhyte')/Trips/$entity", node.get("@odata.context").asText()); assertEquals("f94e9116-8bdd-4dac-ab61-08438d0d9a71", node.get("ShareId").asText()); } @@ -665,7 +665,7 @@ public class TripPinServiceTest { String editUrl = baseURL + "/People('jhondoe')/Trips"; HttpResponse response = httpGET(editUrl, 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People('jhondoe')/Trips", + assertEquals("../$metadata#People('jhondoe')/Trips", node.get("@odata.context").asText()); assertEquals(0, ((ArrayNode)node.get("value")).size()); } @@ -682,7 +682,7 @@ public class TripPinServiceTest { String editUrl = baseURL + "/People('russellwhyte')/Trips(1003)/PlanItems(5)/ConfirmationCode"; HttpResponse response = httpGET(editUrl, 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems(5)/ConfirmationCode", + assertEquals("../../../$metadata#People('russellwhyte')/Trips(1003)/PlanItems(5)/ConfirmationCode", node.get("@odata.context").asText()); assertEquals("JH58494", node.get("value").asText()); } @@ -692,7 +692,7 @@ public class TripPinServiceTest { String editUrl = baseURL + "/People('russellwhyte')/Trips(1003)/PlanItems"; HttpResponse response = httpGET(editUrl, 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems", + assertEquals("../../$metadata#People('russellwhyte')/Trips(1003)/PlanItems", node.get("@odata.context").asText()); assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Flight", ((ArrayNode) node.get("value")).get(0).get("@odata.type").asText()); @@ -705,7 +705,7 @@ public class TripPinServiceTest { HttpResponse response = httpGET(editUrl, 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems/" + assertEquals("../../../$metadata#People('russellwhyte')/Trips(1003)/PlanItems/" + "Microsoft.OData.SampleService.Models.TripPin.Event", node.get("@odata.context").asText()); @@ -719,7 +719,7 @@ public class TripPinServiceTest { + "Microsoft.OData.SampleService.Models.TripPin.Event"; HttpResponse response = httpGET(editUrl, 200); JsonNode node = getJSONNode(response); - assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems/" + assertEquals("../../../$metadata#People('russellwhyte')/Trips(1003)/PlanItems/" + "Microsoft.OData.SampleService.Models.TripPin.Event/$entity", node.get("@odata.context").asText()); assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Event", node.get("@odata.type").asText()); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java index 39649ab..4fb29dd 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilder.java @@ -30,7 +30,7 @@ import org.apache.olingo.commons.core.Encoder; * protocol specification</a>). */ public final class ContextURLBuilder { - + private ContextURLBuilder() { /* private ctor for helper class */} public static URI create(final ContextURL contextURL) { @@ -68,12 +68,23 @@ public final class ContextURLBuilder { result.append('(').append(contextURL.getKeyPath()).append(')'); } if (contextURL.getNavOrPropertyPath() != null) { + if (contextURL.getServiceRoot() == null || + !contextURL.getServiceRoot().isAbsolute()) { + String[] paths = contextURL.getNavOrPropertyPath().split("/"); + for (String path : paths) { + result.insert(0, "../"); + } + } result.append('/').append(contextURL.getNavOrPropertyPath()); } if (contextURL.getSelectList() != null) { result.append('(').append(contextURL.getSelectList()).append(')'); } if (contextURL.isReference()) { + if (contextURL.getServiceRoot() == null || + !contextURL.getServiceRoot().isAbsolute()) { + result.insert(0, "../"); + } if (contextURL.getEntitySetOrSingletonOrType() != null) { throw new IllegalArgumentException("ContextURL: $ref with Entity Set"); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java index bd28d78..842a0ff 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java @@ -191,7 +191,7 @@ public class ContextURLBuilderTest { @Test public void buildReference() { final ContextURL contextURL = ContextURL.with().suffix(Suffix.REFERENCE).build(); - assertEquals("$metadata#$ref", ContextURLBuilder.create(contextURL).toASCIIString()); + assertEquals("../$metadata#$ref", ContextURLBuilder.create(contextURL).toASCIIString()); } @Test(expected = IllegalArgumentException.class) http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java ---------------------------------------------------------------------- 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 dd7041b..c5256db 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 @@ -122,6 +122,7 @@ public class TechnicalEntityProcessor extends TechnicalProcessor EntityCollection entitySet = new EntityCollection(); entitySet.getEntities().addAll(entitySetInitial.getEntities()); FilterHandler.applyFilterSystemQuery(uriInfo.getFilterOption(), entitySet, uriInfo, serviceMetadata.getEdm()); + SearchHandler.applySearchSystemQueryOption(uriInfo.getSearchOption(), entitySet); int count = entitySet.getEntities().size(); for (SystemQueryOption systemQueryOption : uriInfo.getSystemQueryOptions()) { if (systemQueryOption.getName().contains(DELTATOKEN)) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java index d02b892..253dbde 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java @@ -283,7 +283,11 @@ public class ExpressionVisitorImpl implements ExpressionVisitor<VisitorOperand> @Override public VisitorOperand visitAlias(final String aliasName) throws ExpressionVisitException, ODataApplicationException { - return new UntypedOperand(uriInfo.getValueForAlias(aliasName)); + if (entity.getProperty(uriInfo.getValueForAlias(aliasName)) != null) { + return new UntypedOperand(String.valueOf(entity.getProperty(uriInfo.getValueForAlias(aliasName)).getValue())); + } else { + return new UntypedOperand(uriInfo.getValueForAlias(aliasName)); + } } @Override http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/SearchHandler.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/SearchHandler.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/SearchHandler.java index 78b6a3b..1379b97 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/SearchHandler.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/SearchHandler.java @@ -46,10 +46,7 @@ public class SearchHandler { while (it.hasNext()) { boolean keep = false; Entity entity = it.next(); - ListIterator<Property> properties = entity.getProperties().listIterator(); - while (properties.hasNext() && !keep) { - keep = isTrue(se, properties.next()); - } + keep = isTrue(se, entity); if (!keep) { it.remove(); } @@ -107,6 +104,61 @@ public class SearchHandler { } } + private static boolean isTrue(final SearchBinary binary, final Entity entity) throws ODataApplicationException { + SearchExpression left = binary.getLeftOperand(); + SearchExpression right = binary.getRightOperand(); + if (binary.getOperator() == SearchBinaryOperatorKind.AND) { + if (left.isSearchBinary() && right.isSearchBinary()) { + return isTrue(left, entity) && isTrue(right, entity); + } else if (left.isSearchUnary() && right.isSearchBinary()) { + return isTrue(left, entity) && isTrue(right, entity); + } else if (left.isSearchBinary() && right.isSearchUnary()) { + return isTrue(left, entity) && isTrue(right, entity); + } else if (left.isSearchUnary() && right.isSearchUnary()) { + return isTrue(left, entity) && isTrue(right, entity); + } + ListIterator<Property> properties = entity.getProperties().listIterator(); + boolean leftValid = false; + boolean rightValid = false; + while (properties.hasNext()) { + Property property = properties.next(); + if (!leftValid) { + leftValid = isTrue(left, property); + } + if (!rightValid) { + rightValid = isTrue(right, property); + } + } + return leftValid && rightValid; + } else if (binary.getOperator() == SearchBinaryOperatorKind.OR) { + if (left.isSearchBinary() && right.isSearchBinary()) { + return isTrue(left, entity) || isTrue(right, entity); + } else if (left.isSearchUnary() && right.isSearchBinary()) { + return isTrue(left, entity) || isTrue(right, entity); + } else if (left.isSearchBinary() && right.isSearchUnary()) { + return isTrue(left, entity) || isTrue(right, entity); + } else if (left.isSearchUnary() && right.isSearchUnary()) { + return isTrue(left, entity) || isTrue(right, entity); + } + ListIterator<Property> properties = entity.getProperties().listIterator(); + boolean leftValid = false; + boolean rightValid = false; + while (properties.hasNext()) { + Property property = properties.next(); + if (!leftValid) { + leftValid = isTrue(left, property); + } + if (!rightValid) { + rightValid = isTrue(right, property); + } + } + return leftValid || rightValid; + } else { + throw new ODataApplicationException("Found unknown SearchBinaryOperatorKind: " + binary.getOperator(), + HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT); + } + } + private static boolean isTrue(final SearchBinary binary, final Property property) throws ODataApplicationException { SearchExpression left = binary.getLeftOperand(); SearchExpression right = binary.getRightOperand(); @@ -119,7 +171,28 @@ public class SearchHandler { HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT); } } - + + private static boolean isTrue(final SearchExpression searchExpression, final Entity entity) + throws ODataApplicationException { + if (searchExpression.isSearchBinary()) { + return isTrue(searchExpression.asSearchBinary(), entity); + } else if (searchExpression.isSearchTerm()) { + ListIterator<Property> properties = entity.getProperties().listIterator(); + boolean keep = false; + while (properties.hasNext()) { + Property property = properties.next(); + if (!keep) { + keep = isTrue(searchExpression.asSearchTerm(), property); + } + } + return keep; + } else if (searchExpression.isSearchUnary()) { + return !isTrue(searchExpression.asSearchUnary().getOperand(), entity); + } + throw new ODataApplicationException("Found unknown SearchExpression: " + searchExpression, + HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.ROOT); + } + private static boolean isTrue(final SearchExpression searchExpression, final Property property) throws ODataApplicationException { if (searchExpression.isSearchBinary()) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/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 d6a608c..13a7ed5 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 @@ -1672,7 +1672,7 @@ public class ODataJsonSerializerTest { .build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESAllPrim(32767)/PropertyString\"," + + "\"@odata.context\":\"../$metadata#ESAllPrim(32767)/PropertyString\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":\"First Resource - positive values\"}", resultString); @@ -1705,7 +1705,7 @@ public class ODataJsonSerializerTest { .build()) .getContent()); Assert.assertEquals( - "{\"@odata.context\":\"$metadata#ESAllPrim(32767)/PropertyString\"," + "{\"@odata.context\":\"../$metadata#ESAllPrim(32767)/PropertyString\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":\"First Resource - positive values\"}", resultString); @@ -1738,7 +1738,7 @@ public class ODataJsonSerializerTest { .build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESCollAllPrim(1)/CollPropertyString\"," + + "\"@odata.context\":\"../$metadata#ESCollAllPrim(1)/CollPropertyString\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[\"Employee1@company.example\",\"Employee2@company.example\",\"Employee3@company.example\"]}", resultString); @@ -1769,7 +1769,7 @@ public class ODataJsonSerializerTest { .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()) .build()) .build()).getContent()); - Assert.assertEquals("{\"@odata.context\":\"$metadata#ESCollAllPrim(1)/CollPropertyString\"," + + 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); @@ -1789,7 +1789,7 @@ public class ODataJsonSerializerTest { .build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + + "\"@odata.context\":\"../$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":111,\"PropertyString\":\"TEST A\"}", resultString); @@ -1816,7 +1816,7 @@ public class ODataJsonSerializerTest { .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) .build()).build()).getContent()); - Assert.assertEquals("{\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + + Assert.assertEquals("{\"@odata.context\":\"../$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + "\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":111," + @@ -1838,7 +1838,7 @@ public class ODataJsonSerializerTest { .build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"," + + "\"@odata.context\":\"../$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"}," + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"}," @@ -1873,7 +1873,7 @@ public class ODataJsonSerializerTest { .navOrPropertyPath(edmProperty.getName()).build()) .build()) .getContent()); - final String expectedResult = "{\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"," + 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\"," @@ -1900,7 +1900,7 @@ public class ODataJsonSerializerTest { ReferenceSerializerOptions.with().contextURL(ContextURL.with().suffix(Suffix.REFERENCE).build()).build()); final String resultString = IOUtils.toString(serializerResult.getContent()); - Assert.assertEquals("{\"@odata.context\":\"$metadata#$ref\"," + Assert.assertEquals("{\"@odata.context\":\"../$metadata#$ref\"," + "\"@odata.id\":\"ESAllPrim(32767)\"}", resultString); } @@ -1928,7 +1928,7 @@ public class ODataJsonSerializerTest { final String resultString = IOUtils.toString(serializerResult.getContent()); - Assert.assertEquals("{\"@odata.context\":\"$metadata#Collection($ref)\"," + Assert.assertEquals("{\"@odata.context\":\"../$metadata#Collection($ref)\"," + "\"value\":[{\"@odata.id\":\"ESAllPrim(32767)\"}," + "{\"@odata.id\":\"ESAllPrim(-32768)\"}," + "{\"@odata.id\":\"ESAllPrim(0)\"}]}", @@ -1948,7 +1948,7 @@ public class ODataJsonSerializerTest { final String resultString = IOUtils.toString(serializerResult.getContent()); - Assert.assertEquals("{\"@odata.context\":\"$metadata#Collection($ref)\"," + Assert.assertEquals("{\"@odata.context\":\"../$metadata#Collection($ref)\"," + "\"value\":[]}", resultString); } @@ -2043,7 +2043,7 @@ public class ODataJsonSerializerTest { .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()).build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESCollAllPrim(1)/CollPropertyInt64\"," + + "\"@odata.context\":\"../$metadata#ESCollAllPrim(1)/CollPropertyInt64\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[\"929292929292\",\"333333333333\",\"444444444444\"]}", resultString); @@ -2062,7 +2062,7 @@ public class ODataJsonSerializerTest { .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()).build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESCollAllPrim(1)/CollPropertyDecimal\"," + + "\"@odata.context\":\"../$metadata#ESCollAllPrim(1)/CollPropertyDecimal\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[\"12\",\"-2\",\"1234\"]}", resultString); @@ -2080,7 +2080,7 @@ public class ODataJsonSerializerTest { .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()).build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESAllPrim(32767)/PropertyInt64\"," + + "\"@odata.context\":\"../$metadata#ESAllPrim(32767)/PropertyInt64\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":\"" + Long.MAX_VALUE + "\"}", resultString); @@ -2098,7 +2098,7 @@ public class ODataJsonSerializerTest { .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()).build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESAllPrim(32767)/PropertyDecimal\"," + + "\"@odata.context\":\"../$metadata#ESAllPrim(32767)/PropertyDecimal\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":\"34\"}", resultString); @@ -2150,7 +2150,7 @@ public class ODataJsonSerializerTest { final String resultString = IOUtils.toString(result); Assert.assertThat(resultString, CoreMatchers.startsWith("{" - + "\"@odata.context\":\"$metadata#Collection($ref)\"," + + "\"@odata.context\":\"../$metadata#Collection($ref)\"," + "\"@odata.count\":\"3\",\"value\":[")); Assert.assertThat(resultString, CoreMatchers.endsWith("]," + "\"@odata.nextLink\":\"/next\"}")); @@ -2485,7 +2485,7 @@ public class ODataJsonSerializerTest { + "/olingo.odata.test1.CTBase") .build()) .build()).getContent()); - Assert.assertEquals("{\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/" + Assert.assertEquals("{\"@odata.context\":\"../../$metadata#ESMixPrimCollComp(32767)/" + "PropertyComp/olingo.odata.test1.CTBase\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@odata.type\":\"#olingo.odata.test1.CTBase\"," @@ -2631,7 +2631,7 @@ public class ODataJsonSerializerTest { .navOrPropertyPath("CollPropertyComp") .build()).select(selectOption) .build()).getContent()); - Assert.assertEquals("{\"@odata.context\":\"$metadata#ESKeyNav(1)/CollPropertyComp\"," + Assert.assertEquals("{\"@odata.context\":\"../$metadata#ESKeyNav(1)/CollPropertyComp\"," + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[{\"PropertyInt16\":1},{\"PropertyInt16\":2},{\"PropertyInt16\":3}]}", resultString); @@ -2774,7 +2774,7 @@ public class ODataJsonSerializerTest { .entitySet(edmEntitySet).keyPath("1") .navOrPropertyPath(edmComplexType.getName()+"/"+property.getName()) .build()).build()).getContent()); - Assert.assertEquals("{\"@odata.context\":\"$metadata#ESCompMixPrimCollComp(1)/" + Assert.assertEquals("{\"@odata.context\":\"../../$metadata#ESCompMixPrimCollComp(1)/" + "PropertyMixedPrimCollComp/PropertyComp\",\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + "\"propertyin...@odata.type\":\"#Int16\",\"PropertyInt16\":333," http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerv01Test.java ---------------------------------------------------------------------- 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 bece280..1b8d60f 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 @@ -1678,7 +1678,7 @@ public class ODataJsonSerializerv01Test { .build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESAllPrim(32767)/PropertyString\"," + + "\"@context\":\"../$metadata#ESAllPrim(32767)/PropertyString\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":\"First Resource - positive values\"}", resultString); @@ -1711,7 +1711,7 @@ public class ODataJsonSerializerv01Test { .build()) .getContent()); Assert.assertEquals( - "{\"@context\":\"$metadata#ESAllPrim(32767)/PropertyString\"," + "{\"@context\":\"../$metadata#ESAllPrim(32767)/PropertyString\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":\"First Resource - positive values\"}", resultString); @@ -1744,7 +1744,7 @@ public class ODataJsonSerializerv01Test { .build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESCollAllPrim(1)/CollPropertyString\"," + + "\"@context\":\"../$metadata#ESCollAllPrim(1)/CollPropertyString\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[\"Employee1@company.example\",\"Employee2@company.example\",\"Employee3@company.example\"]}", resultString); @@ -1775,7 +1775,7 @@ public class ODataJsonSerializerv01Test { .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()) .build()) .build()).getContent()); - Assert.assertEquals("{\"@context\":\"$metadata#ESCollAllPrim(1)/CollPropertyString\"," + + Assert.assertEquals("{\"@context\":\"../$metadata#ESCollAllPrim(1)/CollPropertyString\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@type\":\"#Collection(String)\",\"value\":[\"Employee1@company.example\"," + "\"Employee2@company.example\",\"Employee3@company.example\"]}", resultString); @@ -1795,7 +1795,7 @@ public class ODataJsonSerializerv01Test { .build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + + "\"@context\":\"../$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"PropertyInt16\":111,\"PropertyString\":\"TEST A\"}", resultString); @@ -1822,7 +1822,7 @@ public class ODataJsonSerializerv01Test { .contextURL(ContextURL.with() .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) .build()).build()).getContent()); - Assert.assertEquals("{\"@context\":\"$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + + Assert.assertEquals("{\"@context\":\"../$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@type\":\"#olingo.odata.test1.CTTwoPrim\"," + "\"PropertyInt16@type\":\"#Int16\",\"PropertyInt16\":111," + @@ -1844,7 +1844,7 @@ public class ODataJsonSerializerv01Test { .build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"," + + "\"@context\":\"../$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"}," + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"}," @@ -1879,7 +1879,7 @@ public class ODataJsonSerializerv01Test { .navOrPropertyPath(edmProperty.getName()).build()) .build()) .getContent()); - final String expectedResult = "{\"@context\":\"$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"," + final String expectedResult = "{\"@context\":\"../$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@type\":\"#Collection(olingo.odata.test1.CTTwoPrim)\"," + "\"value\":[{\"@type\":\"#olingo.odata.test1.CTTwoPrim\"," @@ -1906,7 +1906,7 @@ public class ODataJsonSerializerv01Test { ReferenceSerializerOptions.with().contextURL(ContextURL.with().suffix(Suffix.REFERENCE).build()).build()); final String resultString = IOUtils.toString(serializerResult.getContent()); - Assert.assertEquals("{\"@context\":\"$metadata#$ref\"," + Assert.assertEquals("{\"@context\":\"../$metadata#$ref\"," + "\"@id\":\"ESAllPrim(32767)\"}", resultString); } @@ -1934,7 +1934,7 @@ public class ODataJsonSerializerv01Test { final String resultString = IOUtils.toString(serializerResult.getContent()); - Assert.assertEquals("{\"@context\":\"$metadata#Collection($ref)\"," + Assert.assertEquals("{\"@context\":\"../$metadata#Collection($ref)\"," + "\"value\":[{\"@id\":\"ESAllPrim(32767)\"}," + "{\"@id\":\"ESAllPrim(-32768)\"}," + "{\"@id\":\"ESAllPrim(0)\"}]}", @@ -1954,7 +1954,7 @@ public class ODataJsonSerializerv01Test { final String resultString = IOUtils.toString(serializerResult.getContent()); - Assert.assertEquals("{\"@context\":\"$metadata#Collection($ref)\"," + Assert.assertEquals("{\"@context\":\"../$metadata#Collection($ref)\"," + "\"value\":[]}", resultString); } @@ -2049,7 +2049,7 @@ public class ODataJsonSerializerv01Test { .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()).build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESCollAllPrim(1)/CollPropertyInt64\"," + + "\"@context\":\"../$metadata#ESCollAllPrim(1)/CollPropertyInt64\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[\"929292929292\",\"333333333333\",\"444444444444\"]}", resultString); @@ -2068,7 +2068,7 @@ public class ODataJsonSerializerv01Test { .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()).build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESCollAllPrim(1)/CollPropertyDecimal\"," + + "\"@context\":\"../$metadata#ESCollAllPrim(1)/CollPropertyDecimal\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[\"12\",\"-2\",\"1234\"]}", resultString); @@ -2086,7 +2086,7 @@ public class ODataJsonSerializerv01Test { .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()).build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESAllPrim(32767)/PropertyInt64\"," + + "\"@context\":\"../$metadata#ESAllPrim(32767)/PropertyInt64\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":\"" + Long.MAX_VALUE + "\"}", resultString); @@ -2104,7 +2104,7 @@ public class ODataJsonSerializerv01Test { .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()).build()) .build()).getContent()); Assert.assertEquals("{" - + "\"@context\":\"$metadata#ESAllPrim(32767)/PropertyDecimal\"," + + "\"@context\":\"../$metadata#ESAllPrim(32767)/PropertyDecimal\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":\"34\"}", resultString); @@ -2156,7 +2156,7 @@ public class ODataJsonSerializerv01Test { final String resultString = IOUtils.toString(result); Assert.assertThat(resultString, CoreMatchers.startsWith("{" - + "\"@context\":\"$metadata#Collection($ref)\"," + + "\"@context\":\"../$metadata#Collection($ref)\"," + "\"@count\":\"3\",\"value\":[")); Assert.assertThat(resultString, CoreMatchers.endsWith("]," + "\"@nextLink\":\"/next\"}")); @@ -2491,7 +2491,7 @@ public class ODataJsonSerializerv01Test { + "/olingo.odata.test1.CTBase") .build()) .build()).getContent()); - Assert.assertEquals("{\"@context\":\"$metadata#ESMixPrimCollComp(32767)/" + Assert.assertEquals("{\"@context\":\"../../$metadata#ESMixPrimCollComp(32767)/" + "PropertyComp/olingo.odata.test1.CTBase\"," + "\"@metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"@type\":\"#olingo.odata.test1.CTBase\"," http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java ---------------------------------------------------------------------- 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 e6ec8e1..1541a3d 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 @@ -271,7 +271,7 @@ public class ContextURLHelperTest { final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .keyPath(ContextURLHelper.buildKeyPredicate(Arrays.asList(key))) .navOrPropertyPath(edmProperty.getName()).build(); - assertEquals("$metadata#ESTwoPrim(42)/PropertyInt16", + assertEquals("../$metadata#ESTwoPrim(42)/PropertyInt16", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -288,7 +288,7 @@ public class ContextURLHelperTest { final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .keyPath(ContextURLHelper.buildKeyPredicate(Arrays.asList(key1, key2))) .navOrPropertyPath(edmProperty.getName()).build(); - assertEquals("$metadata#ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyInt16", + assertEquals("../$metadata#ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyInt16", ContextURLBuilder.create(contextURL).toASCIIString()); } @@ -311,7 +311,7 @@ public class ContextURLHelperTest { final ContextURL contextURL = ContextURL.with().entitySet(entitySet) .keyPath(ContextURLHelper.buildKeyPredicate(Arrays.asList(key1, key2, key3, key4))) .navOrPropertyPath(edmProperty.getName()).build(); - assertEquals("$metadata#ESFourKeyAlias" + assertEquals("../$metadata#ESFourKeyAlias" + "(PropertyInt16=1,KeyAlias1=11,KeyAlias2='Num11',KeyAlias3='Num111')/PropertyComp", ContextURLBuilder.create(contextURL).toASCIIString()); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b07a7cfe/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 f8b4c8c..e217ec0 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 @@ -2642,7 +2642,7 @@ public class ODataXmlSerializerTest { String expected = "<?xml version='1.0' encoding='UTF-8'?>" + "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" " - + "m:context=\"$metadata#ESAllPrim(32767)/PropertyString\" " + + "m:context=\"../$metadata#ESAllPrim(32767)/PropertyString\" " + "m:metadata-etag=\"metadataETag\">" + "First Resource - positive values</m:value>"; Assert.assertEquals(expected, resultString); @@ -2666,7 +2666,7 @@ public class ODataXmlSerializerTest { String expected = "<?xml version='1.0' encoding='UTF-8'?>" + "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" " - + "m:context=\"$metadata#ESAllPrim(32767)/PropertyString\" " + + "m:context=\"../$metadata#ESAllPrim(32767)/PropertyString\" " + "m:metadata-etag=\"metadataETag\">" + "abXXcdXX</m:value>"; Assert.assertEquals(expected, resultString); @@ -2686,7 +2686,7 @@ public class ODataXmlSerializerTest { .build()).getContent()); String expected = "<?xml version='1.0' encoding='UTF-8'?>" + "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" " - + "m:context=\"$metadata#ESAllPrim(4242)/PropertyString\" " + + "m:context=\"../$metadata#ESAllPrim(4242)/PropertyString\" " + "m:metadata-etag=\"metadataETag\" " + "m:null=\"true\"/>"; Assert.assertEquals(expected, response); @@ -2707,7 +2707,7 @@ public class ODataXmlSerializerTest { .build()).getContent()); String expected = "<?xml version='1.0' encoding='UTF-8'?>" + "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" " - + "m:context=\"$metadata#ESCollAllPrim(1)/CollPropertyString\" " + + "m:context=\"../$metadata#ESCollAllPrim(1)/CollPropertyString\" " + "m:metadata-etag=\"metadataETag\" m:type=\"#Collection(String)\">" + "<m:element>Employee1@company.example</m:element>" + "<m:element>Employee2@company.example</m:element>" @@ -2733,7 +2733,7 @@ public class ODataXmlSerializerTest { + "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" " + "xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" " + "m:type=\"#olingo.odata.test1.CTTwoPrim\" " - + "m:context=\"$metadata#ESMixPrimCollComp(32767)/PropertyComp\" " + + "m:context=\"../$metadata#ESMixPrimCollComp(32767)/PropertyComp\" " + "m:metadata-etag=\"metadataETag\">" + "<d:PropertyInt16 m:type=\"Int16\">111</d:PropertyInt16>" + "<d:PropertyString>TEST A</d:PropertyString>" @@ -2758,7 +2758,7 @@ public class ODataXmlSerializerTest { + "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" + " xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:a=\"http://www.w3.org/2005/Atom\" " + "m:type=\"#Collection(olingo.odata.test1.CTTwoPrim)\"\n" + - " m:context=\"$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"\n" + + " m:context=\"../$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"\n" + " m:metadata-etag=\"metadataETag\">\n" + " <m:element>\n" + " <d:PropertyInt16 m:type=\"Int16\">123</d:PropertyInt16>\n" + @@ -2807,7 +2807,7 @@ public class ODataXmlSerializerTest { final String resultString = IOUtils.toString(serializerResult.getContent()); String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<m:ref xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" + - " m:context=\"$metadata#$ref\" id=\"ESAllPrim(32767)\" />"; + " m:context=\"../$metadata#$ref\" id=\"ESAllPrim(32767)\" />"; checkXMLEqual(expected, resultString); } @@ -2827,7 +2827,7 @@ public class ODataXmlSerializerTest { String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\"\n" + " xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" + - " m:context=\"$metadata#Collection($ref)\">\n" + + " m:context=\"../$metadata#Collection($ref)\">\n" + " <m:ref id=\"ESAllPrim(32767)\" />\n" + " <m:ref id=\"ESAllPrim(-32768)\" />\n" + " <m:ref id=\"ESAllPrim(0)\" />\n" + @@ -2852,7 +2852,7 @@ public class ODataXmlSerializerTest { String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\"\n" + " xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" + - " m:context=\"$metadata#Collection($ref)\">\n" + + " m:context=\"../$metadata#Collection($ref)\">\n" + "</a:feed>"; checkXMLEqual(expected, resultString); } @@ -3320,7 +3320,7 @@ public class ODataXmlSerializerTest { + "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" " + "xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" xmlns:a=\"http://www.w3.org/2005/Atom\" " + "m:type=\"#Collection(olingo.odata.test1.CTPrimComp)\" " - + "m:context=\"$metadata#ESKeyNav(1)/CollPropertyComp\" " + + "m:context=\"../$metadata#ESKeyNav(1)/CollPropertyComp\" " + "m:metadata-etag=\"metadataETag\">" + "<m:element><d:PropertyInt16 m:type=\"Int16\">1</d:PropertyInt16>" + "</m:element><m:element><d:PropertyInt16 m:type=\"Int16\">2</d:PropertyInt16>"