[OLINGO-935] $apply has to be parsed first + further tests Signed-off-by: Christian Amend <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/96c3f890 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/96c3f890 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/96c3f890 Branch: refs/heads/master Commit: 96c3f8903f33a5536428746096e711d67544e1fd Parents: 9a96ec4 Author: Klaus Straubinger <[email protected]> Authored: Fri Apr 29 16:41:07 2016 +0200 Committer: Christian Amend <[email protected]> Committed: Mon May 2 13:50:15 2016 +0200 ---------------------------------------------------------------------- .../server/core/uri/parser/ApplyParser.java | 34 ++- .../olingo/server/core/uri/parser/Parser.java | 7 +- .../server/core/uri/parser/ParserHelper.java | 2 +- .../server/core/uri/parser/ApplyParserTest.java | 78 ++++++- .../server/core/uri/parser/ParserTest.java | 4 +- .../core/uri/parser/TestFullResourcePath.java | 208 +++++++++--------- .../core/uri/testutil/ExpandValidator.java | 32 +-- .../core/uri/testutil/FilterValidator.java | 212 +++++-------------- .../core/uri/testutil/ResourceValidator.java | 211 +++++------------- .../core/uri/testutil/TestUriValidator.java | 143 +++++++------ 10 files changed, 385 insertions(+), 546 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96c3f890/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ApplyParser.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ApplyParser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ApplyParser.java index 9872eb1..66beb49 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ApplyParser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ApplyParser.java @@ -40,7 +40,6 @@ import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.uri.UriInfo; import org.apache.olingo.server.api.uri.UriParameter; import org.apache.olingo.server.api.uri.UriResource; -import org.apache.olingo.server.api.uri.UriResourceKind; import org.apache.olingo.server.api.uri.UriResourcePartTyped; import org.apache.olingo.server.api.uri.queryoption.AliasQueryOption; import org.apache.olingo.server.api.uri.queryoption.ApplyItem; @@ -63,6 +62,7 @@ import org.apache.olingo.server.core.uri.UriResourceComplexPropertyImpl; import org.apache.olingo.server.core.uri.UriResourceCountImpl; import org.apache.olingo.server.core.uri.UriResourceNavigationPropertyImpl; import org.apache.olingo.server.core.uri.UriResourcePrimitivePropertyImpl; +import org.apache.olingo.server.core.uri.UriResourceStartingTypeFilterImpl; import org.apache.olingo.server.core.uri.parser.UriTokenizer.TokenKind; import org.apache.olingo.server.core.uri.queryoption.ApplyOptionImpl; import org.apache.olingo.server.core.uri.queryoption.ExpandItemImpl; @@ -122,16 +122,14 @@ public class ApplyParser { this.odata = odata; } - public ApplyOption parse(UriTokenizer tokenizer, final EdmStructuredType referencedType, + public ApplyOption parse(UriTokenizer tokenizer, EdmStructuredType referencedType, final Collection<String> crossjoinEntitySetNames, final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException { this.tokenizer = tokenizer; this.crossjoinEntitySetNames = crossjoinEntitySetNames; this.aliases = aliases; - // TODO: Check when to create a new dynamic type and how it can be returned. - DynamicStructuredType type = new DynamicStructuredType(referencedType); - return parseApply(type); + return parseApply(referencedType); } private ApplyOption parseApply(EdmStructuredType referencedType) @@ -325,21 +323,19 @@ public class ApplyParser { return name == null ? null : new DynamicProperty(name, type); } - private Compute parseComputeTrafo(final EdmStructuredType referencedType) + private Compute parseComputeTrafo(EdmStructuredType referencedType) throws UriParserException, UriValidationException { ComputeImpl compute = new ComputeImpl(); - // TODO: Check when to create a new dynamic type and how it can be returned. - DynamicStructuredType type = new DynamicStructuredType(referencedType); do { final Expression expression = new ExpressionParser(edm, odata) - .parse(tokenizer, type, crossjoinEntitySetNames, aliases); + .parse(tokenizer, referencedType, crossjoinEntitySetNames, aliases); final EdmType expressionType = ExpressionParser.getType(expression); if (expressionType.getKind() != EdmTypeKind.PRIMITIVE) { throw new UriParserSemanticException("Compute expressions must return primitive values.", UriParserSemanticException.MessageKeys.ONLY_FOR_PRIMITIVE_TYPES, "compute"); } - final String alias = parseAsAlias(type, true); - type.addProperty(createDynamicProperty(alias, expressionType)); + final String alias = parseAsAlias(referencedType, true); + ((DynamicStructuredType) referencedType).addProperty(createDynamicProperty(alias, expressionType)); compute.addExpression(new ComputeExpressionImpl() .setExpression(expression) .setAlias(alias)); @@ -348,10 +344,12 @@ public class ApplyParser { return compute; } - private Concat parseConcatTrafo(final EdmStructuredType referencedType) + private Concat parseConcatTrafo(EdmStructuredType referencedType) throws UriParserException, UriValidationException { ConcatImpl concat = new ConcatImpl(); - // TODO: Check when to create a new dynamic type and how it can be returned. + // A common type is used for all sub-transformations. + // If one sub-transformation aggregates properties away, + // this could have unintended consequences for subsequent sub-transformations. concat.addApplyOption(parseApply(referencedType)); ParserHelper.requireNext(tokenizer, TokenKind.COMMA); do { @@ -453,15 +451,6 @@ public class ApplyParser { .getType().getFullQualifiedName().getFullQualifiedNameAsString() : ""); } - if (uriInfo.getLastResourcePart() != null - && uriInfo.getLastResourcePart().getKind() == UriResourceKind.navigationProperty) { - if (tokenizer.next(TokenKind.SLASH)) { - UriResourceNavigationPropertyImpl lastPart = (UriResourceNavigationPropertyImpl) uriInfo.getLastResourcePart(); - final EdmStructuredType typeCast = ParserHelper.parseTypeCast(tokenizer, edm, - (EdmStructuredType) lastPart.getType()); - lastPart.setCollectionTypeFilter(typeCast); - } - } return uriInfo; } @@ -473,6 +462,7 @@ public class ApplyParser { throws UriParserException { final EdmStructuredType typeCast = ParserHelper.parseTypeCast(tokenizer, edm, referencedType); if (typeCast != null) { + uriInfo.addResourcePart(new UriResourceStartingTypeFilterImpl(typeCast, true)); ParserHelper.requireNext(tokenizer, TokenKind.SLASH); } EdmStructuredType type = typeCast == null ? referencedType : typeCast; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96c3f890/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java index eb5d679..82e69eb 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java @@ -68,6 +68,7 @@ import org.apache.olingo.server.core.uri.queryoption.SkipOptionImpl; import org.apache.olingo.server.core.uri.queryoption.SkipTokenOptionImpl; import org.apache.olingo.server.core.uri.queryoption.SystemQueryOptionImpl; import org.apache.olingo.server.core.uri.queryoption.TopOptionImpl; +import org.apache.olingo.server.core.uri.queryoption.apply.DynamicStructuredType; import org.apache.olingo.server.core.uri.validator.UriValidationException; public class Parser { @@ -209,6 +210,10 @@ public class Parser { } // Post-process system query options that need context information from the resource path. + if (contextType instanceof EdmStructuredType && contextUriInfo.getApplyOption() != null) { + // Data aggregation may change the structure of the result. + contextType = new DynamicStructuredType((EdmStructuredType) contextType); + } parseApplyOption(contextUriInfo.getApplyOption(), contextType, contextUriInfo.getEntitySetNames(), contextUriInfo.getAliasMap()); parseFilterOption(contextUriInfo.getFilterOption(), contextType, @@ -385,7 +390,7 @@ public class Parser { } } - private void parseApplyOption(ApplyOption applyOption, final EdmType contextType, + private void parseApplyOption(ApplyOption applyOption, EdmType contextType, final List<String> entitySetNames, final Map<String, AliasQueryOption> aliases) throws UriParserException, UriValidationException { if (applyOption != null) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96c3f890/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java index f952c80..6ff8f2f 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ParserHelper.java @@ -537,7 +537,7 @@ public class ParserHelper { final EdmStructuredType referencedType) throws UriParserException { if (tokenizer.next(TokenKind.QualifiedName)) { final FullQualifiedName qualifiedName = new FullQualifiedName(tokenizer.getText()); - final EdmStructuredType type = referencedType instanceof EdmEntityType ? + final EdmStructuredType type = referencedType.getKind() == EdmTypeKind.ENTITY ? edm.getEntityType(qualifiedName) : edm.getComplexType(qualifiedName); if (type == null) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96c3f890/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ApplyParserTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ApplyParserTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ApplyParserTest.java index 87a4281..4286672 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ApplyParserTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ApplyParserTest.java @@ -54,6 +54,7 @@ import org.apache.olingo.server.api.uri.queryoption.apply.Search; import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind; import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind; import org.apache.olingo.server.core.uri.UriInfoImpl; +import org.apache.olingo.server.core.uri.parser.search.SearchParserException; import org.apache.olingo.server.core.uri.testutil.ExpandValidator; import org.apache.olingo.server.core.uri.testutil.FilterValidator; import org.apache.olingo.server.core.uri.testutil.ResourceValidator; @@ -75,6 +76,13 @@ public class ApplyParserTest { new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm(); @Test + public void basic() throws Exception { + parseEx("ESTwoKeyNav", "").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); + parseEx("ESAllPrim(0)/PropertyInt16", "identity") + .isExValidation(UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED); + } + + @Test public void aggregate() throws Exception { parse("ESTwoKeyNav", "aggregate(PropertyInt16 with sum as s)") .is(Aggregate.class) @@ -91,6 +99,9 @@ public class ApplyParserTest { parse("ESTwoKeyNav", "aggregate(PropertyInt16 with custom.aggregate as c)") .is(Aggregate.class) .goAggregate(0).isCustomMethod(new FullQualifiedName("custom", "aggregate")).isAlias("c"); + parse("ESTwoKeyNav", "aggregate(PropertyInt16 with min as min,PropertyInt16 with max as max)") + .goAggregate(0).isStandardMethod(StandardMethod.MIN).isAlias("min").goUp() + .goAggregate(1).isStandardMethod(StandardMethod.MAX).isAlias("max"); parseEx("ESTwoKeyNav", "aggregate()") .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); @@ -104,6 +115,8 @@ public class ApplyParserTest { .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); parseEx("ESTwoKeyNav", "aggregate(PropertyString with countdistinct as PropertyInt16)") .isExSemantic(UriParserSemanticException.MessageKeys.IS_PROPERTY); + parseEx("ESTwoKeyNav", "aggregate(PropertyInt16 with min as m,PropertyInt16 with max as m)") + .isExSemantic(UriParserSemanticException.MessageKeys.IS_PROPERTY); } @Test @@ -163,6 +176,9 @@ public class ApplyParserTest { @Test public void identity() throws Exception { parse("ESTwoKeyNav", "identity").is(Identity.class); + + parseEx("ESTwoKeyNav", "identity()") + .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION); } @Test @@ -189,6 +205,8 @@ public class ApplyParserTest { .goConcat(0).goBottomTop().isMethod(Method.TOP_COUNT) .goUp().goUp() .goConcat(1).goBottomTop().isMethod(Method.BOTTOM_COUNT).goNumber().isLiteral("2"); + + parseEx("ESTwoKeyNav", "concat(identity)").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); } @Test @@ -196,20 +214,26 @@ public class ApplyParserTest { parse("ESTwoKeyNav", "expand(NavPropertyETKeyNavMany,filter(PropertyInt16 gt 2))") .is(Expand.class).goExpand() .goPath().first().isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator().isFilterSerialized("<<PropertyInt16> gt <2>>"); + .goUpExpandValidator().goFilter().is("<<PropertyInt16> gt <2>>"); parse("ESTwoKeyNav", "expand(NavPropertyETKeyNavMany,expand(NavPropertyETTwoKeyNavMany,filter(PropertyInt16 gt 2)))") - .is(Expand.class).goExpand().goExpand().isFilterSerialized("<<PropertyInt16> gt <2>>"); + .is(Expand.class).goExpand().goExpand().goFilter().is("<<PropertyInt16> gt <2>>"); parse("ESTwoKeyNav", "expand(NavPropertyETKeyNavMany,expand(NavPropertyETTwoKeyNavMany,filter(PropertyInt16 gt 2))," + "expand(NavPropertyETTwoKeyNavOne,expand(NavPropertyETKeyNavMany)))") .is(Expand.class).goExpand().goExpand().next().goExpand() .goPath().first().isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); + + parseEx("ESTwoKeyNav", "expand()") + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); } @Test public void search() throws Exception { parse("ESTwoKeyNav", "search(String)").isSearch("'String'"); + + parseEx("ESTwoKeyNav", "search()") + .isExceptionMessage(SearchParserException.MessageKeys.EXPECTED_DIFFERENT_TOKEN); } @Test @@ -218,6 +242,8 @@ public class ApplyParserTest { .is(Filter.class) .goFilter().isBinary(BinaryOperatorKind.GT) .left().isMember().goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); + + parseEx("ESTwoKeyNav", "filter()").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); } @Test @@ -274,6 +300,25 @@ public class ApplyParserTest { parse("ESTwoKeyNav", "groupby((NavPropertyETKeyNavOne/PropertyInt16,NavPropertyETKeyNavOne/PropertyString,PropertyString))") .goGroupBy(2).goPath().first().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); + + parse("ESTwoKeyNav", "groupby((Namespace1_Alias.ETBaseTwoKeyNav/NavPropertyETBaseTwoKeyNavOne/PropertyInt16))") + .is(GroupBy.class) + .goGroupBy(0).goPath().first().isType(EntityTypeProvider.nameETBaseTwoKeyNav) + .n().isNavProperty("NavPropertyETBaseTwoKeyNavOne", EntityTypeProvider.nameETBaseTwoKeyNav, false) + .n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); + parse("ESTwoKeyNav", "groupby((NavPropertyETTwoKeyNavOne/Namespace1_Alias.ETBaseTwoKeyNav/PropertyInt16))") + .is(GroupBy.class) + .goGroupBy(0).goPath() + .first().isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) + .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) + .n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); + + parseEx("ESTwoKeyNav", "groupby((wrongProperty))") + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); + parseEx("ESTwoKeyNav", "groupby((Namespace1_Alias.ETBaseTwoKeyNav))") + .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); + parseEx("ESTwoKeyNav", "groupby((NavPropertyETTwoKeyNavOne/Namespace1_Alias.ETBaseTwoKeyNav))") + .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); } @Test @@ -311,6 +356,9 @@ public class ApplyParserTest { .goGroupByOption() .at(0).goBottomTop().isMethod(Method.TOP_COUNT) .goUp().at(1).goAggregate(0).isStandardMethod(StandardMethod.SUM); + + parseEx("ESTwoKeyNav", "groupby((PropertyInt16),identity,identity)") + .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); } @Test @@ -332,6 +380,9 @@ public class ApplyParserTest { .goGroupBy(0).isRollupAll().goUp().goGroupByOption().goAggregate(0).goFrom(1) .isStandardMethod(StandardMethod.AVERAGE).goExpression().goPath().at(1) .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); + + parseEx("ESTwoKeyNav", "groupby((rollup($all)))") + .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); } @Test @@ -420,6 +471,29 @@ public class ApplyParserTest { .at(0).is(Filter.class) .at(1).is(Expand.class) .at(2).is(GroupBy.class); + + parseEx("ESTwoKeyNav", "identity/").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); + } + + @Test + public void otherQueryOptions() throws Exception { + new TestUriValidator().setEdm(edm).run("ESTwoKeyNav", + "$apply=aggregate(PropertyInt16 with sum as s)&$filter=s gt 3&$select=s") + .goSelectItemPath(0).first().isPrimitiveProperty("s", PropertyProvider.nameDecimal, false) + .goUpUriValidator() + .goFilter().left().goPath().first().isPrimitiveProperty("s", PropertyProvider.nameDecimal, false); + + new FilterValidator().setEdm(edm).runUriOrderBy("ESTwoKeyNav", + "$apply=aggregate(PropertyInt16 with sum as s)&$orderby=s") + .goOrder(0).goPath().first().isPrimitiveProperty("s", PropertyProvider.nameDecimal, false); + } + + @Test + public void onCount() throws Exception { + parse("ESTwoKeyNav/$count", "aggregate(PropertyInt16 with sum as s)") + .goAggregate(0).isStandardMethod(StandardMethod.SUM).isAlias("s") + .goExpression().goPath().first() + .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); } private ApplyValidator parse(final String path, final String apply) http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96c3f890/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ParserTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ParserTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ParserTest.java index 21741ab..f89a863 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ParserTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/ParserTest.java @@ -143,7 +143,7 @@ public class ParserTest { // test and verify testUri.setEdm(mockEdm) .run("Category", "$expand=Products") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("Products", nameProducts, false) @@ -189,7 +189,7 @@ public class ParserTest { // test and verify testUri.setEdm(mockEdm) .run("Products", "$expand=Category") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isType(new FullQualifiedName("NS", "Category"), false); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96c3f890/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestFullResourcePath.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestFullResourcePath.java index a53d119..8aa3172 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestFullResourcePath.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/TestFullResourcePath.java @@ -18,8 +18,6 @@ */ package org.apache.olingo.server.core.uri.parser; -import static org.junit.Assert.assertNotNull; - import java.util.Arrays; import java.util.Collections; @@ -29,8 +27,6 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.edmx.EdmxReference; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.server.api.OData; -import org.apache.olingo.server.api.uri.UriInfoAll; -import org.apache.olingo.server.api.uri.UriInfoCrossjoin; import org.apache.olingo.server.api.uri.UriInfoKind; import org.apache.olingo.server.api.uri.UriResourceKind; import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind; @@ -62,31 +58,33 @@ public class TestFullResourcePath { @Test public void allowedSystemQueryOptionsOnAll() throws Exception { - UriInfoAll uriInfoAll = testUri.run("$all", "$count=true&$format=json&$search=abc&$skip=5&$top=5&$skiptoken=abc") - .getUriInfoRoot().asUriInfoAll(); - assertNotNull(uriInfoAll.getCountOption()); - assertNotNull(uriInfoAll.getFormatOption()); - assertNotNull(uriInfoAll.getSearchOption()); - assertNotNull(uriInfoAll.getSkipOption()); - assertNotNull(uriInfoAll.getTopOption()); - assertNotNull(uriInfoAll.getSkipTokenOption()); + testUri.run("$all", "$count=true&$format=json&$search=abc&$skip=5&$top=5&$skiptoken=abc") + .isKind(UriInfoKind.all) + .isInlineCountText("true") + .isFormatText("json") + .isSearchSerialized("'abc'") + .isSkipText("5") + .isTopText("5") + .isSkipTokenText("abc"); } @Test public void allowedSystemQueryOptionsOnCrossjoin() throws Exception { - UriInfoCrossjoin uriInfoCrossjoin = - testUri.run("$crossjoin(ESAllPrim,ESTwoPrim)", "$count=true&$expand=ESAllPrim" - + "&$filter=ESAllPrim/PropertyInt16 eq 2&$format=json&$orderby=ESAllPrim/PropertyInt16" - + "&$search=abc&$skip=5&$top=5&$skiptoken=abc").getUriInfoRoot().asUriInfoCrossjoin(); - assertNotNull(uriInfoCrossjoin.getCountOption()); - assertNotNull(uriInfoCrossjoin.getExpandOption()); - assertNotNull(uriInfoCrossjoin.getFilterOption()); - assertNotNull(uriInfoCrossjoin.getFormatOption()); - assertNotNull(uriInfoCrossjoin.getOrderByOption()); - assertNotNull(uriInfoCrossjoin.getSearchOption()); - assertNotNull(uriInfoCrossjoin.getSkipOption()); - assertNotNull(uriInfoCrossjoin.getTopOption()); - assertNotNull(uriInfoCrossjoin.getSkipTokenOption()); + testUri.run("$crossjoin(ESAllPrim,ESTwoPrim)", "$count=true&$expand=ESAllPrim" + + "&$filter=ESAllPrim/PropertyInt16 eq 2&$format=json&$orderby=ESAllPrim/PropertyInt16" + + "&$search=abc&$skip=5&$top=5&$skiptoken=abc") + .isKind(UriInfoKind.crossjoin) + .isInlineCountText("true") + .goExpand().goPath().isEntitySet("ESAllPrim") + .goUpExpandValidator().goUpToUriValidator() + .goFilter().left().goPath().first().isEntitySet("ESAllPrim") + .n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false) + .goUpFilterValidator().goUpToUriValidator() + .isFormatText("json") + .isSearchSerialized("'abc'") + .isSkipText("5") + .isTopText("5") + .isSkipTokenText("abc"); } @Test @@ -2355,18 +2353,18 @@ public class TestFullResourcePath { @Test public void expandStar() throws Exception { testUri.run("ESKeyNav(1)", "$expand=*") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .isSegmentStar(); testUri.run("ESKeyNav(1)", "$expand=*/$ref") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .isSegmentStar() .isSegmentRef(); testUri.run("ESKeyNav(1)", "$expand=*/$ref,NavPropertyETKeyNavMany") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .isSegmentStar().isSegmentRef() .next() @@ -2374,13 +2372,13 @@ public class TestFullResourcePath { .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); testUri.run("ESKeyNav(1)", "$expand=*($levels=3)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .isSegmentStar() .isLevelText("3"); testUri.run("ESKeyNav(1)", "$expand=*($levels=max)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .isSegmentStar() .isLevelText("max"); @@ -2389,7 +2387,7 @@ public class TestFullResourcePath { @Test public void expandNavigationRef() throws Exception { testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2397,7 +2395,7 @@ public class TestFullResourcePath { .n().isRef(); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavOne/$ref") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) @@ -2405,16 +2403,16 @@ public class TestFullResourcePath { .n().isRef(); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($filter=PropertyInt16 eq 1)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) .isType(EntityTypeProvider.nameETKeyNav, true) .n().isRef() - .goUpExpandValidator().isFilterSerialized("<<PropertyInt16> eq <1>>"); + .goUpExpandValidator().goFilter().is("<<PropertyInt16> eq <1>>"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($orderby=PropertyInt16)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2425,7 +2423,7 @@ public class TestFullResourcePath { .goOrder(0).goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($skip=1)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2435,7 +2433,7 @@ public class TestFullResourcePath { .isSkipText("1"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($top=2)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2445,7 +2443,7 @@ public class TestFullResourcePath { .isTopText("2"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($count=true)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2455,7 +2453,7 @@ public class TestFullResourcePath { .isInlineCountText("true"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($skip=1;$top=3)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2466,7 +2464,7 @@ public class TestFullResourcePath { .isTopText("3"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($skip=1%3b$top=3)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2480,7 +2478,7 @@ public class TestFullResourcePath { @Test public void expandNavigationCount() throws Exception { testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$count") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2488,7 +2486,7 @@ public class TestFullResourcePath { .n().isCount(); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavOne/$count") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) @@ -2496,29 +2494,28 @@ public class TestFullResourcePath { .n().isCount(); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$count($filter=PropertyInt16 gt 1)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) .isType(EntityTypeProvider.nameETKeyNav, true) .n().isCount() .goUpExpandValidator() - .isFilterSerialized("<<PropertyInt16> gt <1>>"); + .goFilter().is("<<PropertyInt16> gt <1>>"); } @Test public void expandNavigationOptions() throws Exception { testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($filter=PropertyInt16 eq 1)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) .isType(EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator() - .isFilterSerialized("<<PropertyInt16> eq <1>>"); + .goUpExpandValidator().goFilter().is("<<PropertyInt16> eq <1>>"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($orderby=PropertyInt16)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2528,7 +2525,7 @@ public class TestFullResourcePath { .goOrder(0).goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($skip=1)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2537,7 +2534,7 @@ public class TestFullResourcePath { .isSkipText("1"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($top=2)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2546,7 +2543,7 @@ public class TestFullResourcePath { .isTopText("2"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($count=true)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2555,7 +2552,7 @@ public class TestFullResourcePath { .isInlineCountText("true"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($select=PropertyString)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2564,7 +2561,7 @@ public class TestFullResourcePath { .goSelectItem(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($expand=NavPropertyETTwoKeyNavOne)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2575,7 +2572,7 @@ public class TestFullResourcePath { .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($expand=NavPropertyETKeyNavMany)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2586,7 +2583,7 @@ public class TestFullResourcePath { .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavOne($levels=5)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) @@ -2595,7 +2592,7 @@ public class TestFullResourcePath { .isLevelText("5"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($select=PropertyString)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2604,7 +2601,7 @@ public class TestFullResourcePath { .goSelectItem(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavOne($levels=max)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) @@ -2613,7 +2610,7 @@ public class TestFullResourcePath { .isLevelText("max"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($skip=1;$top=2)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2623,7 +2620,7 @@ public class TestFullResourcePath { .isTopText("2"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($skip=1%3b$top=2)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2633,7 +2630,7 @@ public class TestFullResourcePath { .isTopText("2"); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($search=Country AND Western)") - .isKind(UriInfoKind.resource).goPath().goExpand() + .isKind(UriInfoKind.resource).goExpand() .first().goPath().first().isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) .goUpExpandValidator() .isSearchSerialized("{'Country' AND 'Western'}"); @@ -2643,7 +2640,7 @@ public class TestFullResourcePath { .first() .isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(1, "PropertyString", "'Hugo'") - .goExpand() + .goUpUriValidator().goExpand() .first() .goPath().first() .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) @@ -2653,7 +2650,7 @@ public class TestFullResourcePath { @Test public void expandTypeCasts() throws Exception { testUri.run("ESTwoKeyNav", "$expand=olingo.odata.test1.ETBaseTwoKeyNav/NavPropertyETKeyNavMany") - .isKind(UriInfoKind.resource).goPath().first() + .isKind(UriInfoKind.resource) .goExpand().first() .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) .goPath().first() @@ -2664,7 +2661,7 @@ public class TestFullResourcePath { .isKind(UriInfoKind.resource).goPath().first() .isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(1, "PropertyString", "'Hugo'") - .goExpand().first() + .goUpUriValidator().goExpand().first() .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) .goPath().first() .isType(EntityTypeProvider.nameETKeyNav) @@ -2675,7 +2672,7 @@ public class TestFullResourcePath { .isKind(UriInfoKind.resource).goPath().first() .isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(1, "PropertyString", "'2'") - .goExpand().first() + .goUpUriValidator().goExpand().first() .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) .goPath().first() .isType(EntityTypeProvider.nameETTwoKeyNav) @@ -2686,14 +2683,14 @@ public class TestFullResourcePath { .isKind(UriInfoKind.resource).goPath().first() .isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(1, "PropertyString", "'2'") - .goExpand().first() + .goUpUriValidator().goExpand().first() .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) .goPath().first() .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBaseTwoKeyNav); testUri.run("ESTwoKeyNav", "$expand=olingo.odata.test1.ETBaseTwoKeyNav/PropertyCompNav/NavPropertyETTwoKeyNavOne") - .isKind(UriInfoKind.resource).goPath().first() + .isKind(UriInfoKind.resource) .goExpand().first() .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) .goPath().first() @@ -2702,7 +2699,7 @@ public class TestFullResourcePath { .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false); testUri.run("ESTwoKeyNav", "$expand=olingo.odata.test1.ETBaseTwoKeyNav/PropertyCompNav/*") - .isKind(UriInfoKind.resource).goPath().first() + .isKind(UriInfoKind.resource) .goExpand().first() .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) .isSegmentStar() @@ -2710,7 +2707,7 @@ public class TestFullResourcePath { testUri.run("ESTwoKeyNav", "$expand=olingo.odata.test1.ETBaseTwoKeyNav/PropertyCompNav" + "/olingo.odata.test1.CTTwoBasePrimCompNav/NavPropertyETTwoKeyNavOne") - .isKind(UriInfoKind.resource).goPath().first() + .isKind(UriInfoKind.resource) .goExpand().first() .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) .goPath().first() @@ -2720,7 +2717,7 @@ public class TestFullResourcePath { .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false); testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref,NavPropertyETTwoKeyNavMany($skip=2;$top=1)") - .isKind(UriInfoKind.resource).goPath().first() + .isKind(UriInfoKind.resource) .goExpand().first() .goPath() .first() @@ -2740,7 +2737,7 @@ public class TestFullResourcePath { .first() .isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(1, "PropertyString", "'2'") - .goExpand().first() + .goUpUriValidator().goExpand().first() .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) .goPath().first() .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) @@ -2752,7 +2749,6 @@ public class TestFullResourcePath { testUri.run("ESKeyNav", "$expand=NavPropertyETKeyNavOne($expand=NavPropertyETKeyNavMany(" + "$expand=NavPropertyETKeyNavOne))") .isKind(UriInfoKind.resource) - .goPath().first() .goExpand().first() .goPath().first() .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) @@ -2770,7 +2766,6 @@ public class TestFullResourcePath { testUri.run("ESKeyNav", "$expand=NavPropertyETKeyNavOne($select=PropertyInt16)") .isKind(UriInfoKind.resource) - .goPath().first() .goExpand().first() .goPath().first() .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) @@ -2780,7 +2775,6 @@ public class TestFullResourcePath { testUri.run("ESKeyNav", "$expand=NavPropertyETKeyNavOne($select=PropertyCompNav/PropertyInt16)") .isKind(UriInfoKind.resource) - .goPath().first() .goExpand().first() .goPath().first() .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) @@ -2886,8 +2880,9 @@ public class TestFullResourcePath { .first() .isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(1, "PropertyString", "'2'") + .goUpUriValidator() .isSelectStartType(0, EntityTypeProvider.nameETBaseTwoKeyNav) - .goSelectItem(0) + .goSelectItemPath(0) .first() .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); @@ -2960,14 +2955,14 @@ public class TestFullResourcePath { @Test public void top() throws Exception { testUri.run("ESKeyNav", "$top=1") - .isKind(UriInfoKind.resource).goPath() - .isEntitySet("ESKeyNav") - .isTopText("1"); + .isKind(UriInfoKind.resource) + .goPath().isEntitySet("ESKeyNav") + .goUpUriValidator().isTopText("1"); testUri.run("ESKeyNav", "$top=0") - .isKind(UriInfoKind.resource).goPath() - .isEntitySet("ESKeyNav") - .isTopText("0"); + .isKind(UriInfoKind.resource) + .goPath().isEntitySet("ESKeyNav") + .goUpUriValidator().isTopText("0"); testUri.runEx("ESKeyNav", "$top=undefined") .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION); @@ -2980,22 +2975,22 @@ public class TestFullResourcePath { @Test public void format() throws Exception { testUri.run("ESKeyNav(1)", "$format=atom") - .isKind(UriInfoKind.resource).goPath() + .isKind(UriInfoKind.resource) .isFormatText("atom"); testUri.run("ESKeyNav(1)", "$format=json") - .isKind(UriInfoKind.resource).goPath() + .isKind(UriInfoKind.resource) .isFormatText("json"); testUri.run("ESKeyNav(1)", "$format=xml") - .isKind(UriInfoKind.resource).goPath() + .isKind(UriInfoKind.resource) .isFormatText("xml"); testUri.run("ESKeyNav(1)", "$format=IANA_content_type/must_contain_a_slash") - .isKind(UriInfoKind.resource).goPath() + .isKind(UriInfoKind.resource) .isFormatText("IANA_content_type/must_contain_a_slash"); testUri.run("ESKeyNav(1)", "$format=Test_all_valid_signsSpecified_for_format_signs%26-._~$@%27/Aa123%26-._~$@%27") - .isKind(UriInfoKind.resource).goPath() + .isKind(UriInfoKind.resource) .isFormatText("Test_all_valid_signsSpecified_for_format_signs&-._~$@'/Aa123&-._~$@'"); testUri.run("ESKeyNav(1)", "$format=" + ContentType.APPLICATION_ATOM_XML_ENTRY_UTF8) - .isKind(UriInfoKind.resource).goPath() + .isKind(UriInfoKind.resource) .isFormatText(ContentType.APPLICATION_ATOM_XML_ENTRY_UTF8.toContentTypeString()); testUri.runEx("ESKeyNav(1)", "$format=noSlash") .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT); @@ -3012,10 +3007,10 @@ public class TestFullResourcePath { @Test public void count() throws Exception { testUri.run("ESAllPrim", "$count=true") - .isKind(UriInfoKind.resource).goPath() + .isKind(UriInfoKind.resource) .isInlineCountText("true"); testUri.run("ESAllPrim", "$count=false") - .isKind(UriInfoKind.resource).goPath() + .isKind(UriInfoKind.resource) .isInlineCountText("false"); testUri.runEx("ESAllPrim", "$count=undefined") .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION); @@ -3026,10 +3021,10 @@ public class TestFullResourcePath { @Test public void skip() throws Exception { testUri.run("ESAllPrim", "$skip=3") - .isKind(UriInfoKind.resource).goPath() + .isKind(UriInfoKind.resource) .isSkipText("3"); testUri.run("ESAllPrim", "$skip=0") - .isKind(UriInfoKind.resource).goPath() + .isKind(UriInfoKind.resource) .isSkipText("0"); testUri.runEx("ESAllPrim", "$skip=F") @@ -3043,7 +3038,7 @@ public class TestFullResourcePath { @Test public void skiptoken() throws Exception { testUri.run("ESAllPrim", "$skiptoken=foo") - .isKind(UriInfoKind.resource).goPath() + .isKind(UriInfoKind.resource) .isSkipTokenText("foo"); testUri.runEx("ESAllPrim", "$skiptoken=") @@ -5640,22 +5635,22 @@ public class TestFullResourcePath { @Test public void keyPredicatesInExpandFilter() throws Exception { testUri.run("ESKeyNav(0)", "$expand=NavPropertyETTwoKeyNavMany($filter=NavPropertyETTwoKeyNavMany" - + "(PropertyInt16=1,PropertyString='2')/PropertyInt16 eq 1)").goPath().goExpand() + + "(PropertyInt16=1,PropertyString='2')/PropertyInt16 eq 1)").goExpand() .first().goPath().isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) - .goUpExpandValidator() - .isFilterSerialized("<<NavPropertyETTwoKeyNavMany/PropertyInt16> eq <1>>"); + .goUpExpandValidator().goFilter() + .is("<<NavPropertyETTwoKeyNavMany/PropertyInt16> eq <1>>"); } @Test public void keyPredicatesInDoubleExpandedFilter() throws Exception { testUri.run("ESKeyNav(0)", "$expand=NavPropertyETTwoKeyNavMany($expand=NavPropertyETTwoKeyNavMany" + "($filter=NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='2')/PropertyInt16 eq 1))") - .goPath().goExpand() + .goExpand() .first().goPath().isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) .goUpExpandValidator().goExpand() .first().goPath().isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) - .goUpExpandValidator() - .isFilterSerialized("<<NavPropertyETTwoKeyNavMany/PropertyInt16> eq <1>>"); + .goUpExpandValidator().goFilter() + .is("<<NavPropertyETTwoKeyNavMany/PropertyInt16> eq <1>>"); } @Test @@ -5740,7 +5735,7 @@ public class TestFullResourcePath { testFilter.runOnETAllPrim("null eq 42.1") .isBinary(BinaryOperatorKind.EQ) - .left().isLiteral("null").isNullLiteralType() + .left().isLiteral("null").isLiteralType(null) .root() .right().isLiteral("42.1").isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Decimal)); @@ -5776,7 +5771,7 @@ public class TestFullResourcePath { testFilter.runOnETAllPrim("null eq 2012-12-03T07:16:23Z") .isBinary(BinaryOperatorKind.EQ) .left().isLiteral("null") - .isNullLiteralType() + .isLiteralType(null) .root() .right().isLiteral("2012-12-03T07:16:23Z") .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.DateTimeOffset)); @@ -5786,11 +5781,11 @@ public class TestFullResourcePath { .left().isLiteral("07:59:59.999") .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.TimeOfDay)) .root() - .right().isLiteral("null").isNullLiteralType(); + .right().isLiteral("null").isLiteralType(null); testFilter.runOnETAllPrim("null eq 01234567-89ab-cdef-0123-456789abcdef") .isBinary(BinaryOperatorKind.EQ) - .left().isLiteral("null").isNullLiteralType() + .left().isLiteral("null").isLiteralType(null) .root() .right().isLiteral("01234567-89ab-cdef-0123-456789abcdef") .isLiteralType(oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Guid)); @@ -5800,7 +5795,7 @@ public class TestFullResourcePath { .left().isLiteral("binary'VGVzdA=='").isLiteralType( oData.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Binary)) .root() - .right().isLiteral("null").isNullLiteralType(); + .right().isLiteral("null").isLiteralType(null); testFilter.runOnETAllPrim(Short.MIN_VALUE + " eq " + Short.MAX_VALUE) .isBinary(BinaryOperatorKind.EQ) @@ -5832,13 +5827,13 @@ public class TestFullResourcePath { testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString=@A)", "@A='2'").goPath() .isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicateAlias(1, "PropertyString", "@A") - .isInAliasToValueMap("@A", "'2'"); + .goUpUriValidator().isInAliasToValueMap("@A", "'2'"); testUri.run("ESAllPrim(PropertyInt16=@p1)", "@p1=1").goPath() .isKeyPredicateAlias(0, "PropertyInt16", "@p1") - .isInAliasToValueMap("@p1", "1"); + .goUpUriValidator().isInAliasToValueMap("@p1", "1"); testUri.run("ESAllPrim(@p1)", "@p1=-2").goPath() .isKeyPredicateAlias(0, "PropertyInt16", "@p1") - .isInAliasToValueMap("@p1", "-2"); + .goUpUriValidator().isInAliasToValueMap("@p1", "-2"); testFilter.runOnETAllPrim("PropertyInt16 gt @alias&@alias=1") .right().isAlias("@alias"); @@ -5873,7 +5868,7 @@ public class TestFullResourcePath { .goPath() .at(0).isEntitySet("ESTwoKeyNav") .at(1).isFunction("BFCESTwoKeyNavRTStringParam").isParameterAlias(0, "ParameterComp", "@p1") - .isInAliasToValueMap("@p1", "{\"PropertyInt16\":1,\"PropertyString\":\"1\"}"); + .goUpUriValidator().isInAliasToValueMap("@p1", "{\"PropertyInt16\":1,\"PropertyString\":\"1\"}"); // Test JSON String lexer rule =\"3,Int16=abc},\\\nabc&test%test\b\f\r\t\u0022\\}\\{\\)\\(\\]\\[} final String stringValueEncoded = "=\\\"3,Int16=abc},\\\\\\nabc%26test%25test\\b\\f\\r\\t\\u0022\\\\}\\\\{\\\\)" @@ -5886,6 +5881,7 @@ public class TestFullResourcePath { .goPath() .at(0).isEntitySet("ESTwoKeyNav") .at(1).isFunction("BFCESTwoKeyNavRTStringParam").isParameterAlias(0, "ParameterComp", "@p1") + .goUpUriValidator() .isInAliasToValueMap("@p1", "{\"PropertyInt16\":1,\"PropertyString\":\"" + stringValueDecoded + "\"}"); testFilter.runOnETTwoKeyNav("olingo.odata.test1.BFCESTwoKeyNavRTStringParam" http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96c3f890/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java index 104b156..0c60ee2 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java @@ -21,19 +21,15 @@ package org.apache.olingo.server.core.uri.testutil; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.uri.queryoption.ExpandItem; import org.apache.olingo.server.api.uri.queryoption.ExpandOption; -import org.apache.olingo.server.api.uri.queryoption.FilterOption; import org.apache.olingo.server.api.uri.queryoption.OrderByOption; import org.apache.olingo.server.api.uri.queryoption.QueryOption; import org.apache.olingo.server.api.uri.queryoption.SelectItem; import org.apache.olingo.server.api.uri.queryoption.SelectOption; -import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; public class ExpandValidator implements TestValidator { private Edm edm; @@ -67,8 +63,8 @@ public class ExpandValidator implements TestValidator { return (ExpandValidator) invokedByValidator; } - public ResourceValidator goUpToUriResourceValidator() { - return (ResourceValidator) invokedByValidator; + public TestUriValidator goUpToUriValidator() { + return (TestUriValidator) invokedByValidator; } public ResourceValidator goPath() { @@ -95,6 +91,13 @@ public class ExpandValidator implements TestValidator { .setUriInfoPath(item.getResourcePath()); } + public FilterValidator goFilter() { + return new FilterValidator() + .setEdm(edm) + .setFilter(expandItem.getFilterOption()) + .setValidator(this); + } + public ExpandValidator goExpand() { return new ExpandValidator() .setExpand(expandItem.getExpandOption()) @@ -162,23 +165,6 @@ public class ExpandValidator implements TestValidator { return this; } - public ExpandValidator isFilterSerialized(final String serialized) { - FilterOption filter = expandItem.getFilterOption(); - - try { - String tmp = FilterTreeToText.Serialize(filter); - assertEquals(serialized, tmp); - } catch (ExpressionVisitException e) { - fail("Exception occurred while converting the filterTree into text" + "\n" - + " Exception: " + e.getMessage()); - } catch (ODataApplicationException e) { - fail("Exception occurred while converting the filterTree into text" + "\n" - + " Exception: " + e.getMessage()); - } - - return this; - } - public ExpandValidator isSortOrder(final int index, final boolean descending) { OrderByOption orderBy = expandItem.getOrderByOption(); assertEquals(descending, orderBy.getOrders().get(index).isDescending()); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/96c3f890/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java index 600a2bd..c7e9e64 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java @@ -20,7 +20,7 @@ package org.apache.olingo.server.core.uri.testutil; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.List; @@ -28,9 +28,9 @@ import java.util.List; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.api.ex.ODataException; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ODataApplicationException; -import org.apache.olingo.server.api.ODataLibraryException; import org.apache.olingo.server.api.uri.UriInfo; import org.apache.olingo.server.api.uri.UriInfoKind; import org.apache.olingo.server.api.uri.UriResource; @@ -51,8 +51,6 @@ import org.apache.olingo.server.api.uri.queryoption.expression.Unary; import org.apache.olingo.server.core.uri.UriResourceFunctionImpl; import org.apache.olingo.server.core.uri.parser.Parser; import org.apache.olingo.server.core.uri.parser.UriParserException; -import org.apache.olingo.server.core.uri.parser.UriParserSemanticException; -import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException; import org.apache.olingo.server.core.uri.queryoption.expression.BinaryImpl; import org.apache.olingo.server.core.uri.queryoption.expression.MemberImpl; import org.apache.olingo.server.core.uri.queryoption.expression.MethodImpl; @@ -70,19 +68,7 @@ public class FilterValidator implements TestValidator { private Expression curExpression; private Expression rootExpression; - private ODataLibraryException exception; - // --- Setup --- - public FilterValidator setUriResourcePathValidator(final ResourceValidator uriResourcePathValidator) { - invokedByValidator = uriResourcePathValidator; - return this; - } - - public FilterValidator setUriValidator(final TestUriValidator uriValidator) { - invokedByValidator = uriValidator; - return this; - } - public FilterValidator setValidator(final TestValidator uriValidator) { invokedByValidator = uriValidator; return this; @@ -95,10 +81,7 @@ public class FilterValidator implements TestValidator { public FilterValidator setFilter(final FilterOption filter) { this.filter = filter; - - if (filter.getExpression() == null) { - fail("FilterValidator: no filter found"); - } + assertNotNull("FilterValidator: no filter found", filter.getExpression()); setExpression(filter.getExpression()); return this; } @@ -112,130 +95,110 @@ public class FilterValidator implements TestValidator { public FilterValidator runOrderByOnETAllPrim(final String orderBy) throws UriParserException, UriValidationException { - return runUriOrderBy("ESAllPrim", "$orderby=" + orderBy.trim()); + return runUriOrderBy("ESAllPrim", "$orderby=" + orderBy); } public FilterValidator runOrderByOnETTwoKeyNav(final String orderBy) throws UriParserException, UriValidationException { - return runUriOrderBy("ESTwoKeyNav", "$orderby=" + orderBy.trim()); + return runUriOrderBy("ESTwoKeyNav", "$orderby=" + orderBy); } public FilterValidator runOrderByOnETMixEnumDefCollComp(final String orderBy) throws UriParserException, UriValidationException { - return runUriOrderBy("ESMixEnumDefCollComp", "$orderby=" + orderBy.trim()); + return runUriOrderBy("ESMixEnumDefCollComp", "$orderby=" + orderBy); } - public FilterValidator runOrderByOnETTwoKeyNavEx(final String orderBy) throws UriParserException { - return runUriEx("ESTwoKeyNav", "$orderby=" + orderBy.trim()); + public TestUriValidator runOrderByOnETTwoKeyNavEx(final String orderBy) { + return runUriEx("ESTwoKeyNav", "$orderby=" + orderBy); } public FilterValidator runOnETTwoKeyNav(final String filter) throws UriParserException, UriValidationException { - return runUri("ESTwoKeyNav", "$filter=" + filter.trim()); + return runUri("ESTwoKeyNav", "$filter=" + filter); } public FilterValidator runOnETMixEnumDefCollComp(final String filter) throws UriParserException, UriValidationException { - return runUri("ESMixEnumDefCollComp", "$filter=" + filter.trim()); + return runUri("ESMixEnumDefCollComp", "$filter=" + filter); } public FilterValidator runOnETTwoKeyNavSingle(final String filter) throws UriParserException, UriValidationException { - return runUri("SINav", "$filter=" + filter.trim()); + return runUri("SINav", "$filter=" + filter); } - public FilterValidator runOnETTwoKeyNavEx(final String filter) throws UriParserException { - return runUriEx("ESTwoKeyNav", "$filter=" + filter.trim()); + public TestUriValidator runOnETTwoKeyNavEx(final String filter) { + return runUriEx("ESTwoKeyNav", "$filter=" + filter); } public FilterValidator runOnETAllPrim(final String filter) throws UriParserException, UriValidationException { - return runUri("ESAllPrim(1)", "$filter=" + filter.trim()); + return runUri("ESAllPrim(1)", "$filter=" + filter); } public FilterValidator runOnETKeyNav(final String filter) throws UriParserException, UriValidationException { - return runUri("ESKeyNav(1)", "$filter=" + filter.trim()); + return runUri("ESKeyNav(1)", "$filter=" + filter); } - public FilterValidator runOnETKeyNavEx(final String filter) throws UriParserException { - return runUriEx("ESKeyNav(1)", "$filter=" + filter.trim()); + public TestUriValidator runOnETKeyNavEx(final String filter) { + return runUriEx("ESKeyNav(1)", "$filter=" + filter); } public FilterValidator runOnCTTwoPrim(final String filter) throws UriParserException, UriValidationException { - return runUri("SINav/PropertyCompTwoPrim", "$filter=" + filter.trim()); + return runUri("SINav/PropertyCompTwoPrim", "$filter=" + filter); } public FilterValidator runOnString(final String filter) throws UriParserException, UriValidationException { - return runUri("SINav/PropertyString", "$filter=" + filter.trim()); + return runUri("SINav/PropertyString", "$filter=" + filter); } public FilterValidator runOnInt32(final String filter) throws UriParserException, UriValidationException { - return runUri("ESCollAllPrim(1)/CollPropertyInt32", "$filter=" + filter.trim()); + return runUri("ESCollAllPrim(1)/CollPropertyInt32", "$filter=" + filter); } public FilterValidator runOnDateTimeOffset(final String filter) throws UriParserException, UriValidationException { - return runUri("ESCollAllPrim(1)/CollPropertyDateTimeOffset", "$filter=" + filter.trim()); + return runUri("ESCollAllPrim(1)/CollPropertyDateTimeOffset", "$filter=" + filter); } public FilterValidator runOnDuration(final String filter) throws UriParserException, UriValidationException { - return runUri("ESCollAllPrim(1)/CollPropertyDuration", "$filter=" + filter.trim()); + return runUri("ESCollAllPrim(1)/CollPropertyDuration", "$filter=" + filter); } public FilterValidator runOnTimeOfDay(final String filter) throws UriParserException, UriValidationException { - return runUri("ESCollAllPrim(1)/CollPropertyTimeOfDay", "$filter=" + filter.trim()); + return runUri("ESCollAllPrim(1)/CollPropertyTimeOfDay", "$filter=" + filter); } public FilterValidator runUri(final String path, final String query) throws UriParserException, UriValidationException { final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, query, null); - - if (uriInfo.getKind() != UriInfoKind.resource) { - fail("Filtervalidator can only be used on resourcePaths"); - } - + assertTrue("Filtervalidator can only be used on resourcePaths", uriInfo.getKind() == UriInfoKind.resource); setFilter(uriInfo.getFilterOption()); curExpression = filter.getExpression(); return this; } - public FilterValidator runUriEx(final String path, final String query) { - exception = null; - try { - new Parser(edm, odata).parseUri(path, query, null); - fail("Expected exception not thrown."); - } catch (final UriParserException e) { - exception = e; - } catch (final UriValidationException e) { - exception = e; - } - return this; + public TestUriValidator runUriEx(final String path, final String query) { + return new TestUriValidator().setEdm(edm).runEx(path, query); } public FilterValidator runUriOrderBy(final String path, final String query) throws UriParserException, UriValidationException { final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, query, null); - - if (uriInfo.getKind() != UriInfoKind.resource) { - fail("Filtervalidator can only be used on resourcePaths"); - } - + assertTrue("Filtervalidator can only be used on resourcePaths", uriInfo.getKind() == UriInfoKind.resource); orderBy = uriInfo.getOrderByOption(); return this; } // --- Navigation --- - public ExpandValidator goUpToExpandValidator() { - return (ExpandValidator) invokedByValidator; - } - public ResourceValidator goUpToResourceValidator() { return (ResourceValidator) invokedByValidator; } - public ResourceValidator goPath() { - if (!(curExpression instanceof Member)) { - fail("Current expression not a member"); - } + public TestUriValidator goUpToUriValidator() { + return (TestUriValidator) invokedByValidator; + } + public ResourceValidator goPath() { + isMember(); Member member = (Member) curExpression; return new ResourceValidator() @@ -245,12 +208,9 @@ public class FilterValidator implements TestValidator { } public FilterValidator goParameter(final int parameterIndex) { - if (curExpression instanceof Method) { - Method methodCall = (Method) curExpression; - curExpression = methodCall.getParameters().get(parameterIndex); - } else { - fail("Current expression not a methodCall"); - } + assertTrue("Current expression not a methodCall", curExpression instanceof Method); + Method methodCall = (Method) curExpression; + curExpression = methodCall.getParameters().get(parameterIndex); return this; } @@ -268,12 +228,8 @@ public class FilterValidator implements TestValidator { public FilterValidator is(final String expectedFilterAsString) { try { - String actualFilterAsText = FilterTreeToText.Serialize(filter); - assertEquals(expectedFilterAsString, actualFilterAsText); - } catch (ExpressionVisitException e) { - fail("Exception occurred while converting the filterTree into text" + "\n" - + " Exception: " + e.getMessage()); - } catch (ODataApplicationException e) { + assertEquals(expectedFilterAsString, FilterTreeToText.Serialize(filter)); + } catch (final ODataException e) { fail("Exception occurred while converting the filterTree into text" + "\n" + " Exception: " + e.getMessage()); } @@ -283,10 +239,9 @@ public class FilterValidator implements TestValidator { // --- Helper --- private String compress(final String expected) { - String ret = expected.replaceAll("\\s+", " "); - ret = ret.replaceAll("< ", "<"); - ret = ret.replaceAll(" >", ">"); - return ret; + return expected.replaceAll("\\s+", " ") + .replaceAll("< ", "<") + .replaceAll(" >", ">"); } public FilterValidator isType(final FullQualifiedName fullName) { @@ -308,10 +263,7 @@ public class FilterValidator implements TestValidator { actualType = ((MethodImpl) curExpression).getType(); } - if (actualType == null) { - fail("Current expression not typed"); - } - + assertNotNull("Current expression not typed", actualType); assertEquals(fullName, actualType.getFullQualifiedName()); return this; } @@ -322,59 +274,33 @@ public class FilterValidator implements TestValidator { } public FilterValidator left() { - if (!(curExpression instanceof Binary)) { - fail("Current expression not a binary operator"); - } - + assertTrue("Current expression not a binary operator", curExpression instanceof Binary); curExpression = ((Binary) curExpression).getLeftOperand(); return this; } public FilterValidator right() { - if (!(curExpression instanceof Binary)) { - fail("Current expression is not a binary operator"); - } - + assertTrue("Current expression not a binary operator", curExpression instanceof Binary); curExpression = ((Binary) curExpression).getRightOperand(); return this; } public FilterValidator isLiteral(final String literalText) { - if (!(curExpression instanceof Literal)) { - fail("Current expression is not a literal"); - } - + assertTrue("Current expression is not a literal", curExpression instanceof Literal); String actualLiteralText = ((Literal) curExpression).getText(); assertEquals(literalText, actualLiteralText); return this; } public FilterValidator isLiteralType(final EdmType edmType) { - if (!(curExpression instanceof Literal)) { - fail("Current expression is not a literal"); - } - + assertTrue("Current expression is not a literal", curExpression instanceof Literal); final EdmType type = ((Literal) curExpression).getType(); - assertNotNull(type); assertEquals(edmType, type); return this; } - public FilterValidator isNullLiteralType() { - if (!(curExpression instanceof Literal)) { - fail("Current expression is not a literal"); - } - - final EdmType type = ((Literal) curExpression).getType(); - assertNull(type); - return this; - } - public FilterValidator isMethod(final MethodKind methodKind, final int parameterCount) { - if (!(curExpression instanceof Method)) { - fail("Current expression is not a methodCall"); - } - + assertTrue("Current expression is not a methodCall", curExpression instanceof Method); Method methodCall = (Method) curExpression; assertEquals(methodKind, methodCall.getMethod()); assertEquals(parameterCount, methodCall.getParameters().size()); @@ -408,28 +334,20 @@ public class FilterValidator implements TestValidator { } public FilterValidator isBinary(final BinaryOperatorKind binaryOperator) { - if (!(curExpression instanceof Binary)) { - fail("Current expression is not a binary operator"); - } - + assertTrue("Current expression not a binary operator", curExpression instanceof Binary); Binary binary = (Binary) curExpression; assertEquals(binaryOperator, binary.getOperator()); return this; } public FilterValidator isTypedLiteral(final FullQualifiedName fullName) { - if (!(curExpression instanceof TypeLiteral)) { - fail("Current expression not a typeLiteral"); - } - + assertTrue("Current expression not a typeLiteral", curExpression instanceof TypeLiteral); isType(fullName); return this; } public FilterValidator isMember() { - if (!(curExpression instanceof Member)) { - fail("Current expression not a member"); - } + assertTrue("Current expression not a member", curExpression instanceof Member); return this; } @@ -442,10 +360,7 @@ public class FilterValidator implements TestValidator { } public FilterValidator isEnum(final FullQualifiedName name, final List<String> enumValues) { - if (!(curExpression instanceof Enumeration)) { - fail("Current expression not a enumeration"); - } - + assertTrue("Current expression not an enumeration", curExpression instanceof Enumeration); Enumeration enumeration = (Enumeration) curExpression; // check name @@ -458,12 +373,9 @@ public class FilterValidator implements TestValidator { } public FilterValidator isAlias(final String name) { - if (curExpression instanceof Alias) { - final Alias alias = (Alias) curExpression; - assertEquals(name, alias.getParameterName()); - } else { - fail("Current expression is not an alias."); - } + assertTrue("Current expression not an alias", curExpression instanceof Alias); + final Alias alias = (Alias) curExpression; + assertEquals(name, alias.getParameterName()); return this; } @@ -476,22 +388,4 @@ public class FilterValidator implements TestValidator { curExpression = orderBy.getOrders().get(index).getExpression(); return this; } - - public FilterValidator isExSyntax(final UriParserSyntaxException.MessageKeys messageKey) { - assertEquals(UriParserSyntaxException.class, exception.getClass()); - assertEquals(messageKey, exception.getMessageKey()); - return this; - } - - public FilterValidator isExSemantic(final UriParserSemanticException.MessageKeys messageKey) { - assertEquals(UriParserSemanticException.class, exception.getClass()); - assertEquals(messageKey, exception.getMessageKey()); - return this; - } - - public FilterValidator isExValidation(final UriValidationException.MessageKeys messageKey) { - assertEquals(UriValidationException.class, exception.getClass()); - assertEquals(messageKey, exception.getMessageKey()); - return this; - } }
