[OLINGO-792] Improve URI parser error message

Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/d0b225bf
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/d0b225bf
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/d0b225bf

Branch: refs/heads/olingo786
Commit: d0b225bf18a8ed06a090f92fd5f55dee7767a7cc
Parents: 26c923b
Author: Christian Holzer <[email protected]>
Authored: Tue Oct 6 16:41:09 2015 +0200
Committer: Christian Holzer <[email protected]>
Committed: Tue Oct 6 16:41:09 2015 +0200

----------------------------------------------------------------------
 .../server/core/uri/parser/UriParseTreeVisitor.java       |  5 ++---
 .../core/uri/parser/UriParserSemanticException.java       |  2 ++
 .../main/resources/server-core-exceptions-i18n.properties |  1 +
 .../server/core/uri/antlr/TestFullResourcePath.java       | 10 ++++++++--
 4 files changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d0b225bf/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 edd6058..f61c6ee 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
@@ -662,9 +662,8 @@ public class UriParseTreeVisitor extends 
UriParserBaseVisitor<Object> {
 
       // do a check for bound functions (which requires a parameter list)
       if (ctx.vlNVO.size() == 0) {
-        throw wrap(new UriParserSemanticException("Expected function 
parameters for '" + fullBindingTypeName.toString()
-            + "'",
-            
UriParserSemanticException.MessageKeys.FUNCTION_PARAMETERS_EXPECTED, 
fullBindingTypeName.toString()));
+        throw wrap(new UriParserSemanticException("Unknown type for type cast 
" + fullFilterName.toString() 
+        + " not found", UriParserSemanticException.MessageKeys.UNKNOWN_TYPE , 
fullFilterName.toString()));
       }
 
       context.contextReadingFunctionParameters = true;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d0b225bf/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 75744c9..672d093 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
@@ -48,6 +48,8 @@ public class UriParserSemanticException extends 
UriParserException {
     FUNCTION_PARAMETERS_EXPECTED,
     /** parameter: resource part */
     UNKNOWN_PART,
+    /** parameter: type */
+    UNKNOWN_TYPE,
     /** parameter: expression */
     ONLY_FOR_TYPED_PARTS,
     /** parameter: entity type name */

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d0b225bf/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 de14eb0..3484ab3 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
@@ -50,6 +50,7 @@ 
UriParserSemanticException.FUNCTION_PARAMETERS_EXPECTED=Function parameters expe
 UriParserSemanticException.UNKNOWN_PART=The part '%1$s' is not defined.
 UriParserSemanticException.ONLY_FOR_TYPED_PARTS='%1$s' is only allowed for 
typed parts.
 UriParserSemanticException.UNKNOWN_ENTITY_TYPE=The entity type '%1$s' is not 
defined.
+UriParserSemanticException.UNKNOWN_TYPE=The type of the type cast '%1$s' is 
not defined.
 UriParserSemanticException.ONLY_FOR_COLLECTIONS='%1$s' is only allowed for 
collections.
 UriParserSemanticException.ONLY_FOR_ENTITY_TYPES='%1$s' is only allowed for 
entity types.
 UriParserSemanticException.ONLY_FOR_STRUCTURAL_TYPES='%1$s' is only allowed 
for structural types.

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d0b225bf/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 5c06e2c..3b2ff14 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
@@ -5442,7 +5442,7 @@ public class TestFullResourcePath {
         
.isExSemantic(UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
 
     testUri.runEx("ESTwoKeyNav/olingo.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav")
-    
.isExSemantic(UriParserSemanticException.MessageKeys.FUNCTION_PARAMETERS_EXPECTED);
+    .isExSemantic(UriParserSemanticException.MessageKeys.UNKNOWN_TYPE);
 
     // $ref
     
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim/$ref")
@@ -5563,7 +5563,13 @@ public class TestFullResourcePath {
     
testUri.runEx("AIRTESAllPrimParam/FICRTString()").isExSemantic(MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
     
testUri.runEx("AIRTESAllPrimParam/AIRTString").isExSemantic(MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
   }
-
+  
+  @Test
+  public void invalidTypeCast() {
+    
testUri.runEx("ESAllPrim/namespace.Invalid").isExSemantic(MessageKeys.UNKNOWN_TYPE);
+    
testUri.runEx("ESAllPrim(0)/namespace.Invalid").isExSemantic(MessageKeys.UNKNOWN_TYPE);
+  }
+  
   @Test
   public void navPropertySameNameAsEntitySet() throws Exception {
     testUri.run("ESNavProp(1)/ESNavProp(2)/ESNavProp(3)/ESNavProp")

Reply via email to