From 96c3f8903f33a5536428746096e711d67544e1fd Mon Sep 17 00:00:00 2001 From: Klaus Straubinger Date: Fri, 29 Apr 2016 16:41:07 +0200 Subject: [PATCH] [OLINGO-935] $apply has to be parsed first + further tests Signed-off-by: Christian Amend --- .../server/core/uri/parser/ApplyParser.java | 34 +-- .../olingo/server/core/uri/parser/Parser.java | 7 +- .../server/core/uri/parser/ParserHelper.java | 2 +- .../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 | 155 +++++++------ 10 files changed, 391 insertions(+), 552 deletions(-) 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 9872eb14c..66beb49cf 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 crossjoinEntitySetNames, final Map 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; 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 eb5d67971..82e69ebb5 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 entitySetNames, final Map aliases) throws UriParserException, UriValidationException { if (applyOption != null) { 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 f952c80bb..6ff8f2f5a 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) { 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 87a428199..4286672d2 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; @@ -74,6 +75,13 @@ public class ApplyParserTest { private static final Edm edm = odata.createServiceMetadata( new EdmTechProvider(), Collections. 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)") @@ -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("< gt <2>>"); + .goUpExpandValidator().goFilter().is("< gt <2>>"); parse("ESTwoKeyNav", "expand(NavPropertyETKeyNavMany,expand(NavPropertyETTwoKeyNavMany,filter(PropertyInt16 gt 2)))") - .is(Expand.class).goExpand().goExpand().isFilterSerialized("< gt <2>>"); + .is(Expand.class).goExpand().goExpand().goFilter().is("< 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) 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 21741ab9a..f89a86389 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); 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 a53d11901..8aa3172e1 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("< eq <1>>"); + .goUpExpandValidator().goFilter().is("< 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("< gt <1>>"); + .goFilter().is("< 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("< eq <1>>"); + .goUpExpandValidator().goFilter().is("< 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("< eq <1>>"); + .goUpExpandValidator().goFilter() + .is("< 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("< eq <1>>"); + .goUpExpandValidator().goFilter() + .is("< 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" 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 104b156a6..0c60ee2c1 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()); 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 600a2bd08..c7e9e649a 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 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; - } } diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java index a9d25be4d..90ac68cfa 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java @@ -48,9 +48,6 @@ import org.apache.olingo.server.api.uri.UriResourceNavigation; import org.apache.olingo.server.api.uri.UriResourcePartTyped; import org.apache.olingo.server.api.uri.UriResourcePrimitiveProperty; import org.apache.olingo.server.api.uri.UriResourceSingleton; -import org.apache.olingo.server.api.uri.queryoption.ExpandOption; -import org.apache.olingo.server.api.uri.queryoption.SelectItem; -import org.apache.olingo.server.api.uri.queryoption.SelectOption; import org.apache.olingo.server.core.uri.UriResourceWithKeysImpl; import org.apache.olingo.server.core.uri.parser.Parser; import org.apache.olingo.server.core.uri.validator.UriValidationException; @@ -79,19 +76,19 @@ public class ResourceValidator implements TestValidator { public ResourceValidator setUriInfoPath(final UriInfoResource uriInfoPath) { uriInfo = (UriInfo) uriInfoPath; - last(); + if (!uriInfo.getUriResourceParts().isEmpty()) { + last(); + } return this; } // --- Execution --- public ResourceValidator run(final String path) { - Parser testParser = new Parser(edm, odata); - UriInfo uriInfoTmp = null; uriPathInfo = null; try { - uriInfoTmp = testParser.parseUri(path, null, null); + uriInfoTmp = new Parser(edm, odata).parseUri(path, null, null); } catch (final ODataLibraryException e) { fail("Exception occurred while parsing the URI: " + path + "\n" + " Message: " + e.getMessage()); @@ -104,10 +101,8 @@ public class ResourceValidator implements TestValidator { + " Message: " + e.getMessage()); } - if (uriInfoTmp.getKind() != UriInfoKind.resource) { - fail("Invalid UriInfoKind: " + uriInfoTmp.getKind().toString()); - } uriInfo = uriInfoTmp; + isKind(UriInfoKind.resource); first(); return this; @@ -132,43 +127,21 @@ public class ResourceValidator implements TestValidator { UriResourceFunction function = (UriResourceFunction) uriPathInfo; return new FilterValidator() - .setEdm(edm) - .setExpression(function.getParameters().get(index).getExpression()) - .setValidator(this); + .setEdm(edm) + .setExpression(function.getParameters().get(index).getExpression()) + .setValidator(this); } public FilterValidator goLambdaExpression() { - if (uriPathInfo.getKind() == UriResourceKind.lambdaAll) { - return new FilterValidator() - .setEdm(edm) - .setExpression(((UriResourceLambdaAll) uriPathInfo).getExpression()); - - } else if (uriPathInfo.getKind() == UriResourceKind.lambdaAny) { - return new FilterValidator() - .setEdm(edm) - .setExpression(((UriResourceLambdaAny) uriPathInfo).getExpression()); - } else { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - return null; - } - - public ResourceValidator goSelectItem(final int index) { - final SelectOption select = uriInfo.getSelectOption(); - SelectItem item = select.getSelectItems().get(index); - return new ResourceValidator() - .setUpValidator(this) + assertTrue("invalid resource kind: " + uriPathInfo.getKind().toString(), + uriPathInfo.getKind() == UriResourceKind.lambdaAll + || uriPathInfo.getKind() == UriResourceKind.lambdaAny); + return new FilterValidator() .setEdm(edm) - .setUriInfoPath(item.getResourcePath()); - } - - public ExpandValidator goExpand() { - final ExpandOption expand = uriInfo.getExpandOption(); - if (expand == null) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - return new ExpandValidator().setUpValidator(this).setExpand(expand); + .setExpression(uriPathInfo.getKind() == UriResourceKind.lambdaAll ? + ((UriResourceLambdaAll) uriPathInfo).getExpression() : + ((UriResourceLambdaAny) uriPathInfo).getExpression()) + .setValidator(this); } public ResourceValidator first() { @@ -176,15 +149,7 @@ public class ResourceValidator implements TestValidator { } public ResourceValidator last() { - final List parts = uriInfo.getUriResourceParts(); - if (parts.isEmpty()) { - uriResourceIndex = 0; - fail("not enough segments"); - } else { - uriResourceIndex = parts.size() - 1; - uriPathInfo = parts.get(uriResourceIndex); - } - return this; + return at(uriInfo.getUriResourceParts().size() - 1); } public ResourceValidator n() { @@ -193,11 +158,8 @@ public class ResourceValidator implements TestValidator { public ResourceValidator at(final int index) { uriResourceIndex = index; - if (index < uriInfo.getUriResourceParts().size()) { - uriPathInfo = uriInfo.getUriResourceParts().get(index); - } else { - fail("not enough segments"); - } + assertTrue("not enough segments", index < uriInfo.getUriResourceParts().size()); + uriPathInfo = uriInfo.getUriResourceParts().get(index); return this; } @@ -231,26 +193,20 @@ public class ResourceValidator implements TestValidator { actualType = ((UriResourceSingleton) uriPathInfo).getEntityTypeFilter(); } - if (actualType == null) { - fail("type information not set"); - } - + assertNotNull("type information not set", actualType); assertEquals(expectedType, actualType.getFullQualifiedName()); return this; } public ResourceValidator isType(final FullQualifiedName type) { - if (!(uriPathInfo instanceof UriResourcePartTyped)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } + assertTrue("invalid resource kind: " + + (uriPathInfo.getKind() == null ? "null" : uriPathInfo.getKind().toString()), + uriPathInfo instanceof UriResourcePartTyped); UriResourcePartTyped uriPathInfoTyped = (UriResourcePartTyped) uriPathInfo; EdmType actualType = uriPathInfoTyped.getType(); - if (actualType == null) { - fail("type information not set"); - } + assertNotNull("type information not set", actualType); assertEquals(type, actualType.getFullQualifiedName()); - return this; } @@ -261,10 +217,8 @@ public class ResourceValidator implements TestValidator { } public ResourceValidator isTypeFilterOnEntry(final FullQualifiedName type) { - if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - + assertTrue("invalid resource kind: " + uriPathInfo.getKind().toString(), + uriPathInfo instanceof UriResourceWithKeysImpl); UriResourceWithKeysImpl uriPathInfoKeyPred = (UriResourceWithKeysImpl) uriPathInfo; // input parameter type may be null in order to assert that the singleTypeFilter is not set @@ -275,9 +229,8 @@ public class ResourceValidator implements TestValidator { } public ResourceValidator isTypeFilterOnCollection(final FullQualifiedName expectedType) { - if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } + assertTrue("invalid resource kind: " + uriPathInfo.getKind().toString(), + uriPathInfo instanceof UriResourceWithKeysImpl); UriResourceWithKeysImpl uriPathInfoKeyPred = (UriResourceWithKeysImpl) uriPathInfo; // input parameter type may be null in order to assert that the collectionTypeFilter is not set @@ -289,23 +242,19 @@ public class ResourceValidator implements TestValidator { } // other functions - public ResourceValidator isKeyPredicateRef(final int index, final String name, final String refencedProperty) { - if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - + public ResourceValidator isKeyPredicateRef(final int index, final String name, final String referencedProperty) { + assertTrue("invalid resource kind: " + uriPathInfo.getKind().toString(), + uriPathInfo instanceof UriResourceWithKeysImpl); UriResourceWithKeysImpl info = (UriResourceWithKeysImpl) uriPathInfo; List keyPredicates = info.getKeyPredicates(); assertEquals(name, keyPredicates.get(index).getName()); - assertEquals(refencedProperty, keyPredicates.get(index).getReferencedProperty()); + assertEquals(referencedProperty, keyPredicates.get(index).getReferencedProperty()); return this; } public ResourceValidator isKeyPredicateAlias(final int index, final String name, final String alias) { - if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - + assertTrue("invalid resource kind: " + uriPathInfo.getKind().toString(), + uriPathInfo instanceof UriResourceWithKeysImpl); UriResourceWithKeysImpl info = (UriResourceWithKeysImpl) uriPathInfo; List keyPredicates = info.getKeyPredicates(); assertEquals(name, keyPredicates.get(index).getName()); @@ -315,10 +264,8 @@ public class ResourceValidator implements TestValidator { } public ResourceValidator isKeyPredicate(final int index, final String name, final String text) { - if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - + assertTrue("invalid resource kind: " + uriPathInfo.getKind().toString(), + uriPathInfo instanceof UriResourceWithKeysImpl); UriResourceWithKeysImpl info = (UriResourceWithKeysImpl) uriPathInfo; List keyPredicates = info.getKeyPredicates(); assertEquals(name, keyPredicates.get(index).getName()); @@ -328,10 +275,8 @@ public class ResourceValidator implements TestValidator { } public ResourceValidator isParameter(final int index, final String name, final String text) { - if (!(uriPathInfo instanceof UriResourceFunction)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - + assertTrue("invalid resource kind: " + uriPathInfo.getKind().toString(), + uriPathInfo instanceof UriResourceFunction); UriResourceFunction info = (UriResourceFunction) uriPathInfo; List keyPredicates = info.getParameters(); assertEquals(name, keyPredicates.get(index).getName()); @@ -341,10 +286,8 @@ public class ResourceValidator implements TestValidator { } public ResourceValidator isParameterAlias(final int index, final String name, final String alias) { - if (!(uriPathInfo instanceof UriResourceFunction)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - + assertTrue("invalid resource kind: " + uriPathInfo.getKind().toString(), + uriPathInfo instanceof UriResourceFunction); UriResourceFunction info = (UriResourceFunction) uriPathInfo; List keyPredicates = info.getParameters(); assertEquals(name, keyPredicates.get(index).getName()); @@ -354,16 +297,15 @@ public class ResourceValidator implements TestValidator { } public ResourceValidator isKind(final UriInfoKind kind) { - assertEquals(kind, uriInfo.getKind()); + assertEquals("Invalid UriInfoKind: " + uriInfo.getKind().toString(), + kind, uriInfo.getKind()); return this; } public ResourceValidator isPrimitiveProperty(final String name, final FullQualifiedName type, final boolean isCollection) { - if (!(uriPathInfo instanceof UriResourcePrimitiveProperty)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - + assertTrue("invalid resource kind: " + uriPathInfo.getKind().toString(), + uriPathInfo instanceof UriResourcePrimitiveProperty); UriResourcePrimitiveProperty uriPathInfoProp = (UriResourcePrimitiveProperty) uriPathInfo; EdmElement property = uriPathInfoProp.getProperty(); @@ -376,10 +318,8 @@ public class ResourceValidator implements TestValidator { public ResourceValidator isComplexProperty(final String name, final FullQualifiedName type, final boolean isCollection) { - if (!(uriPathInfo instanceof UriResourceComplexProperty)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - + assertTrue("invalid resource kind: " + uriPathInfo.getKind().toString(), + uriPathInfo instanceof UriResourceComplexProperty); UriResourceComplexProperty uriPathInfoProp = (UriResourceComplexProperty) uriPathInfo; EdmElement property = uriPathInfoProp.getProperty(); @@ -391,10 +331,8 @@ public class ResourceValidator implements TestValidator { } public ResourceValidator isNavProperty(final String name, final FullQualifiedName type, final boolean isCollection) { - if (!(uriPathInfo instanceof UriResourceNavigation)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - + assertTrue("invalid resource kind: " + uriPathInfo.getKind().toString(), + uriPathInfo instanceof UriResourceNavigation); UriResourceNavigation uriPathInfoProp = (UriResourceNavigation) uriPathInfo; EdmElement property = uriPathInfoProp.getProperty(); @@ -468,57 +406,4 @@ public class ResourceValidator implements TestValidator { public ResourceValidator isIt() { return isUriPathInfoKind(UriResourceKind.it); } - - public ResourceValidator isTopText(final String topText) { - assertEquals(topText, uriInfo.getTopOption().getText()); - return this; - } - - public ResourceValidator isFormatText(final String formatText) { - assertEquals(formatText, uriInfo.getFormatOption().getText()); - return this; - } - - public ResourceValidator isInlineCountText(final String inlineCountText) { - assertEquals(inlineCountText, uriInfo.getCountOption().getText()); - return this; - } - - public ResourceValidator isSkipText(final String skipText) { - assertEquals(skipText, uriInfo.getSkipOption().getText()); - return this; - } - - public ResourceValidator isSkipTokenText(final String skipTokenText) { - assertEquals(skipTokenText, uriInfo.getSkipTokenOption().getText()); - return this; - } - - public ResourceValidator isSelectItemStar(final int index) { - final SelectOption select = uriInfo.getSelectOption(); - SelectItem item = select.getSelectItems().get(index); - assertTrue(item.isStar()); - return this; - } - - public ResourceValidator isSelectItemAllOp(final int index, final FullQualifiedName fqn) { - final SelectOption select = uriInfo.getSelectOption(); - SelectItem item = select.getSelectItems().get(index); - assertEquals(fqn, item.getAllOperationsInSchemaNameSpace()); - return this; - } - - public ResourceValidator isSelectStartType(final int index, final FullQualifiedName fullName) { - final SelectOption select = uriInfo.getSelectOption(); - SelectItem item = select.getSelectItems().get(index); - EdmType actualType = item.getStartTypeFilter(); - assertEquals(fullName, actualType.getFullQualifiedName()); - return this; - } - - public ResourceValidator isInAliasToValueMap(final String alias, final String value) { - String valueForAlias = uriInfo.getValueForAlias(alias); - assertEquals(value, valueForAlias); - return this; - } } diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java index bee3401f0..d869cb190 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java @@ -19,6 +19,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.assertTrue; import static org.junit.Assert.fail; @@ -59,14 +60,12 @@ public class TestUriValidator implements TestValidator { // Execution public TestUriValidator run(final String path) throws UriParserException, UriValidationException { - return run(path, null); + return run(path, null, null); } public TestUriValidator run(final String path, final String query) throws UriParserException, UriValidationException { - uriInfo = new Parser(edm, odata).parseUri(path, query, null); - new UriValidator().validate(uriInfo, HttpMethod.GET); - return this; + return run(path, query, null); } public TestUriValidator run(final String path, final String query, final String fragment) @@ -83,8 +82,7 @@ public class TestUriValidator implements TestValidator { public TestUriValidator runEx(final String path, final String query) { uriInfo = null; try { - uriInfo = new Parser(edm, odata).parseUri(path, query, null); - new UriValidator().validate(uriInfo, HttpMethod.GET); + run(path, query, null); fail("Exception expected"); } catch (UriParserException e) { exception = e; @@ -96,10 +94,12 @@ public class TestUriValidator implements TestValidator { // Navigation public ResourceValidator goPath() { - if (uriInfo.getKind() != UriInfoKind.resource) { - fail("invalid resource kind: " + uriInfo.getKind().toString()); - } - + assertNotNull(uriInfo); + assertNotNull(uriInfo.getKind()); + assertTrue("invalid resource kind: " + uriInfo.getKind().toString(), + uriInfo.getKind() == UriInfoKind.resource + || uriInfo.getKind() == UriInfoKind.all + || uriInfo.getKind() == UriInfoKind.crossjoin); return new ResourceValidator() .setUpValidator(this) .setEdm(edm) @@ -108,23 +108,19 @@ public class TestUriValidator implements TestValidator { public FilterValidator goFilter() { final FilterOption filter = uriInfo.getFilterOption(); - if (filter == null) { - fail("no filter found"); - } - return new FilterValidator().setUriValidator(this).setFilter(filter); + assertNotNull("no filter found", filter); + return new FilterValidator().setValidator(this).setFilter(filter); } public ExpandValidator goExpand() { final ExpandOption expand = uriInfo.getExpandOption(); - if (expand == null) { - fail("invalid resource kind: " + uriInfo.getKind().toString()); - } - + assertNotNull("no expand found", expand); return new ExpandValidator().setUpValidator(this).setExpand(expand); } public ResourceValidator goSelectItemPath(final int index) { final SelectOption select = uriInfo.getSelectOption(); + assertNotNull("no select found", select); SelectItem item = select.getSelectItems().get(index); return new ResourceValidator() .setUpValidator(this) @@ -134,6 +130,7 @@ public class TestUriValidator implements TestValidator { public TestUriValidator isSelectStartType(final int index, final FullQualifiedName fullName) { final SelectOption select = uriInfo.getSelectOption(); + assertNotNull("no select found", select); SelectItem item = select.getSelectItems().get(index); EdmType actualType = item.getStartTypeFilter(); assertEquals(fullName, actualType.getFullQualifiedName()); @@ -142,6 +139,7 @@ public class TestUriValidator implements TestValidator { public TestUriValidator isSelectItemStar(final int index) { final SelectOption select = uriInfo.getSelectOption(); + assertNotNull("no select found", select); SelectItem item = select.getSelectItems().get(index); assertTrue(item.isStar()); return this; @@ -149,6 +147,7 @@ public class TestUriValidator implements TestValidator { public TestUriValidator isSelectItemAllOp(final int index, final FullQualifiedName fqn) { final SelectOption select = uriInfo.getSelectOption(); + assertNotNull("no select found", select); SelectItem item = select.getSelectItems().get(index); assertEquals(fqn, item.getAllOperationsInSchemaNameSpace()); return this; @@ -156,19 +155,53 @@ public class TestUriValidator implements TestValidator { // Validation public TestUriValidator isKind(final UriInfoKind kind) { - assertEquals(kind, uriInfo.getKind()); + assertNotNull(uriInfo); + assertNotNull(uriInfo.getKind()); + assertEquals("invalid resource kind: " + uriInfo.getKind().toString(), kind, uriInfo.getKind()); + return this; + } + + public TestUriValidator isFormatText(final String text) { + assertEquals(text, uriInfo.getFormatOption().getText()); + return this; + } + + public TestUriValidator isTopText(final String topText) { + assertEquals(topText, uriInfo.getTopOption().getText()); + return this; + } + + public TestUriValidator isInlineCountText(final String inlineCountText) { + assertEquals(inlineCountText, uriInfo.getCountOption().getText()); + return this; + } + + public TestUriValidator isSkipText(final String skipText) { + assertEquals(skipText, uriInfo.getSkipOption().getText()); + return this; + } + + public TestUriValidator isSkipTokenText(final String skipTokenText) { + assertEquals(skipTokenText, uriInfo.getSkipTokenOption().getText()); + return this; + } + + public TestUriValidator isSearchSerialized(final String serialized) { + assertNotNull("no search found", uriInfo.getSearchOption()); + assertEquals(serialized, uriInfo.getSearchOption().getSearchExpression().toString()); + return this; + } + + public TestUriValidator isInAliasToValueMap(final String alias, final String value) { + assertEquals(value, uriInfo.getValueForAlias(alias)); return this; } public TestUriValidator isCustomParameter(final int index, final String name, final String value) { - if (uriInfo == null) { - fail("hasQueryParameter: uriInfo == null"); - } + assertNotNull(uriInfo); - List list = uriInfo.getCustomQueryOptions(); - if (list.size() <= index) { - fail("not enough queryParameters"); - } + final List list = uriInfo.getCustomQueryOptions(); + assertTrue("not enough queryParameters", list.size() > index); CustomQueryOption option = list.get(index); assertEquals(name, option.getName()); @@ -176,16 +209,27 @@ public class TestUriValidator implements TestValidator { return this; } - public void isCrossJoinEntityList(final List entitySets) { - if (uriInfo.getKind() != UriInfoKind.crossjoin) { - fail("invalid resource kind: " + uriInfo.getKind().toString()); - } + public TestUriValidator isCrossJoinEntityList(final List entitySets) { + isKind(UriInfoKind.crossjoin); + assertEquals(entitySets, uriInfo.getEntitySetNames()); + return this; + } - int i = 0; - for (String entitySet : entitySets) { - assertEquals(entitySet, uriInfo.getEntitySetNames().get(i)); - i++; - } + public TestUriValidator isEntityType(final FullQualifiedName fullName) { + isKind(UriInfoKind.entityId); + assertEquals(fullName, uriInfo.getEntityTypeCast().getFullQualifiedName()); + return this; + } + + public TestUriValidator isIdText(final String text) { + assertEquals(text, uriInfo.getIdOption().getText()); + return this; + } + + public TestUriValidator isFragmentText(final String text) { + isKind(UriInfoKind.metadata); + assertEquals(text, uriInfo.getFragment()); + return this; } public TestUriValidator isExceptionMessage(final ODataLibraryException.MessageKey messageKey) { @@ -195,51 +239,16 @@ public class TestUriValidator implements TestValidator { public TestUriValidator isExSyntax(final UriParserSyntaxException.MessageKeys messageKey) { assertEquals(UriParserSyntaxException.class, exception.getClass()); - assertEquals(messageKey, exception.getMessageKey()); - return this; + return isExceptionMessage(messageKey); } public TestUriValidator isExSemantic(final UriParserSemanticException.MessageKeys messageKey) { assertEquals(UriParserSemanticException.class, exception.getClass()); - assertEquals(messageKey, exception.getMessageKey()); - return this; + return isExceptionMessage(messageKey); } public TestUriValidator isExValidation(final UriValidationException.MessageKeys messageKey) { assertEquals(UriValidationException.class, exception.getClass()); - assertEquals(messageKey, exception.getMessageKey()); - return this; - } - - public TestUriValidator isIdText(final String text) { - assertEquals(text, uriInfo.getIdOption().getText()); - return this; - } - - public TestUriValidator isFormatText(final String text) { - assertEquals(text, uriInfo.getFormatOption().getText()); - return this; - } - - public TestUriValidator isFragmentText(final String text) { - if (uriInfo.getKind() != UriInfoKind.metadata) { - fail("invalid resource kind: " + uriInfo.getKind().toString()); - } - - assertEquals(text, uriInfo.getFragment()); - return this; - } - - public TestUriValidator isEntityType(final FullQualifiedName fullName) { - if (uriInfo.getKind() != UriInfoKind.entityId) { - fail("invalid resource kind: " + uriInfo.getKind().toString()); - } - - assertEquals(fullName, uriInfo.getEntityTypeCast().getFullQualifiedName()); - return this; - } - - public UriInfo getUriInfoRoot() { - return uriInfo; + return isExceptionMessage(messageKey); } }