Repository: olingo-odata4 Updated Branches: refs/heads/master 42043f464 -> cf032b690
"bad request" for not existing properties in expressions Change-Id: I4061e0d4dd9de3c6fe1419eb5a7a0fdee88c62c2 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/cf032b69 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/cf032b69 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/cf032b69 Branch: refs/heads/master Commit: cf032b690c111797203dd239c08a5342ad4dff10 Parents: 42043f4 Author: Klaus Straubinger <[email protected]> Authored: Wed Oct 8 15:54:56 2014 +0200 Committer: Christian Amend <[email protected]> Committed: Fri Oct 10 11:13:58 2014 +0200 ---------------------------------------------------------------------- .../core/uri/parser/UriParseTreeVisitor.java | 8 ++--- .../uri/parser/UriParserSemanticException.java | 3 +- .../server-core-exceptions-i18n.properties | 1 + .../core/uri/antlr/TestFullResourcePath.java | 36 +++++++++++++------- .../core/uri/antlr/TestUriParserImpl.java | 18 ++++++++-- .../core/uri/testutil/FilterValidator.java | 1 + 6 files changed, 48 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cf032b69/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java index 2c3d87c..63d8fb9 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java @@ -87,7 +87,6 @@ import org.apache.olingo.server.core.uri.antlr.UriParserParser.BatchEOFContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.BooleanNonCaseContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.CastExprContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.CeilingMethodCallExprContext; -import org.apache.olingo.server.core.uri.antlr.UriParserParser.CommonExprContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.ConcatMethodCallExprContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.ConstSegmentContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.ContainsMethodCallExprContext; @@ -157,7 +156,6 @@ import org.apache.olingo.server.core.uri.antlr.UriParserParser.TopContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.TotalOffsetMinutesMethodCallExprContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.TotalsecondsMethodCallExprContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.TrimMethodCallExprContext; -import org.apache.olingo.server.core.uri.antlr.UriParserParser.UnaryContext; import org.apache.olingo.server.core.uri.antlr.UriParserParser.YearMethodCallExprContext; import org.apache.olingo.server.core.uri.queryoption.CountOptionImpl; import org.apache.olingo.server.core.uri.queryoption.ExpandItemImpl; @@ -409,7 +407,9 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> { if (property == null) { throw wrap(new UriParserSemanticException("Property '" + odi + "' not found in type '" + structType.getNamespace() + "." + structType.getName() + "'", - UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE, + ctx.depth() > 2 ? // resource path or path evaluation inside an expression? + UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE : + UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE, structType.getFullQualifiedName().toString(), odi)); } @@ -1872,7 +1872,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> { EdmElement element = structType.getProperty(odi); if (element == null) { throw wrap(new UriParserSemanticException("Previous select item has not property: " + odi, - UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE, structType.getName(), odi)); + UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE, structType.getName(), odi)); } // create new segment http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cf032b69/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java index b41fbbf..6471566 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java @@ -28,6 +28,7 @@ public class UriParserSemanticException extends UriParserException { /** parameter: resource part */ RESOURCE_PART_ONLY_FOR_TYPED_PARTS, /** parameter: resource part */ RESOURCE_PART_MUST_BE_PRECEDED_BY_STRUCTURAL_TYPE, /** parameters: type name, property name */ PROPERTY_NOT_IN_TYPE, + /** parameters: type name, property name */ EXPRESSION_PROPERTY_NOT_IN_TYPE, /** parameter: property name */ UNKNOWN_PROPERTY_TYPE, /** parameter: type filter */ INCOMPATIBLE_TYPE_FILTER, /** parameters: previous type filter, last type filter */ TYPE_FILTER_NOT_CHAINABLE, @@ -50,7 +51,7 @@ public class UriParserSemanticException extends UriParserException { COMPLEX_PROPERTY_OF_ENTITY_TYPE_EXPECTED, NOT_FOR_ENTITY_TYPE, PREVIOUS_PART_TYPED, - /** parameter: resource_name */RESOURCE_NOT_FOUND; + /** parameter: resource_name */ RESOURCE_NOT_FOUND; @Override public String getKey() { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cf032b69/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties index 621f4eb..87d08f8 100644 --- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties +++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties @@ -37,6 +37,7 @@ UriParserSemanticException.FUNCTION_NOT_FOUND=The function import '%1$s' has no UriParserSemanticException.RESOURCE_PART_ONLY_FOR_TYPED_PARTS='%1$s' is only allowed for typed parts. UriParserSemanticException.RESOURCE_PART_MUST_BE_PRECEDED_BY_STRUCTURAL_TYPE=The resource part '%1$s' must be preceded by a structural type. UriParserSemanticException.PROPERTY_NOT_IN_TYPE=The type '%1$s' has no property '%2$s'. +UriParserSemanticException.EXPRESSION_PROPERTY_NOT_IN_TYPE=The property '%2$s', used in a query expression, is not defined in type '%1$s'. UriParserSemanticException.UNKNOWN_PROPERTY_TYPE=The type of the property '%1$s' is unknown. UriParserSemanticException.INCOMPATIBLE_TYPE_FILTER=The type filter '%1$s' is incompatible. UriParserSemanticException.TYPE_FILTER_NOT_CHAINABLE=The type filter '%2$s' can not be chained with '%1$s'. http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cf032b69/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java index 2108216..bbb9e45 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java @@ -2505,6 +2505,11 @@ public class TestFullResourcePath { .isType(EntityTypeProvider.nameETKeyNav) .goUpExpandValidator() .isSelectText("PropertyComp/PropertyInt16"); + + testUri.runEx("ESKeyNav", "$expand=undefined") + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); + testUri.runEx("ESTwoKeyNav", "$expand=PropertyCompNav/undefined") + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); } @Test @@ -2940,20 +2945,22 @@ public class TestFullResourcePath { .isLiteral("'SomeString'"); testFilter.runOnETTwoKeyNavEx("invalid") - .isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE); + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); + testFilter.runOnETTwoKeyNavEx("PropertyComp") + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); testFilter.runOnETTwoKeyNavEx("PropertyComp/invalid") - .isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE); + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); testFilter.runOnETTwoKeyNavEx("concat('a','b')/invalid").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); testFilter.runOnETTwoKeyNavEx("PropertyComp/concat('a','b')") .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); - testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyInt16 eq '1'") - .isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE); - testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyDate eq 1") - .isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE); - testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyString eq 1") - .isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE); - testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyDate eq 1") - .isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE); + testFilter.runOnETTwoKeyNavEx("PropertyComp/PropertyInt16 eq '1'") + .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); + testFilter.runOnETTwoKeyNavEx("PropertyComp/PropertyComp/PropertyDate eq 1") + .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); + testFilter.runOnETTwoKeyNavEx("PropertyComp/PropertyComp/PropertyString eq 1") + .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); + testFilter.runOnETTwoKeyNavEx("PropertyComp/PropertyInt64 eq 1") + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); testFilter.runOnETAllPrim("PropertySByte eq PropertySByte") .is("<<PropertySByte> eq <PropertySByte>>") @@ -4152,10 +4159,9 @@ public class TestFullResourcePath { .goParameter(1).isTypedLiteral(EntityTypeProvider.nameETKeyPrimNav); testFilter.runOnETKeyNavEx("cast(NavPropertyETKeyPrimNavOne,olingo.odata.test1.ETKeyNav)") - .isExSemantic(UriParserSemanticException.MessageKeys.PROPERTY_NOT_IN_TYPE); + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); testFilter.runOnETKeyNav("any()") .isMember().goPath().first().isUriPathInfoKind(UriResourceKind.lambdaAny); - } @Test @@ -5073,6 +5079,12 @@ public class TestFullResourcePath { .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 asc, PropertyInt32 PropertyDuration desc") .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); + testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 asc desc") + .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); + testFilter.runOrderByOnETTwoKeyNavEx("undefined") + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); + testFilter.runOrderByOnETTwoKeyNavEx("PropertyComp/undefined") + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); } @Test http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cf032b69/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java index 1dce3df..9fdbbdd 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java @@ -596,7 +596,6 @@ public class TestUriParserImpl { testFilter.runESabc("1 div 2 add 3 div 4").isCompr("<< <1> div <2>> add <<3> div <4>>>"); testFilter.runESabc("1 div 2 div 3 add 4").isCompr("<<< <1> div <2>> div <3>> add <4>>"); testFilter.runESabc("1 div 2 div 3 div 4").isCompr("<<< <1> div <2>> div <3>> div <4>>"); - } @Test @@ -622,7 +621,7 @@ public class TestUriParserImpl { } @Test - public void testFunctionImport_VarRetruning() { + public void testFunctionImport_VarReturning() { // returning primitive testRes.run("FINRTInt16()") .isFunctionImport("FINRTInt16") @@ -1145,6 +1144,21 @@ public class TestUriParserImpl { .isComplexProperty("PropertyCompNav", ComplexTypeProvider.nameCTBasePrimCompNav, false) .n() .isTypeFilterOnCollection(ComplexTypeProvider.nameCTTwoBasePrimCompNav); + + testUri.run("ESAllPrim", "$select=PropertyTimeOfDay,PropertyDate,PropertyTimeOfDay") + .isKind(UriInfoKind.resource) + .goSelectItemPath(0).first().isPrimitiveProperty("PropertyTimeOfDay", PropertyProvider.nameTimeOfDay, false) + .goUpUriValidator() + .goSelectItemPath(1).first().isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false); + + testUri.runEx("ESMixPrimCollComp", "$select=wrong") + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); + testUri.runEx("ESMixPrimCollComp", "$select=PropertyComp/wrong") + .isExSemantic(UriParserSemanticException.MessageKeys.EXPRESSION_PROPERTY_NOT_IN_TYPE); + testUri.runEx("ESMixPrimCollComp", "$select=PropertyComp///PropertyInt16") + .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); + testUri.runEx("ESMixPrimCollComp", "$select=/PropertyInt16") + .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); } public static String encode(final String decoded) throws UnsupportedEncodingException { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/cf032b69/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 eaf509c..21d8935 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 @@ -224,6 +224,7 @@ public class FilterValidator implements TestValidator { try { uriInfo = parser.parseUri(path, query, null, edm); + fail("Expected exception not thrown."); } catch (UriParserException e) { exception = e; return this;
