[OLINGO-206] validation

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

Branch: refs/heads/master
Commit: e02f098a8983a39e0ae1f05884e8e74aa35d5da8
Parents: 907ab20
Author: Stephan Klevenz <[email protected]>
Authored: Tue Apr 29 12:01:08 2014 +0200
Committer: Stephan Klevenz <[email protected]>
Committed: Tue Apr 29 17:17:46 2014 +0200

----------------------------------------------------------------------
 .../core/edm/provider/EdmProviderImpl.java      |  30 ++-
 .../server/core/uri/validator/UriValidator.java | 132 ++++++++--
 .../techprovider/EntityTypeProvider.java        |  20 +-
 .../core/uri/antlr/TestFullResourcePath.java    |  10 +-
 .../core/uri/antlr/TestUriParserImpl.java       |  71 +++--
 .../core/uri/testutil/ExpandValidator.java      |   6 +-
 .../core/uri/testutil/FilterValidator.java      |   8 +-
 .../core/uri/testutil/ResourceValidator.java    |  10 +-
 .../core/uri/testutil/TestUriValidator.java     | 258 +++++++++++++++++++
 .../server/core/uri/testutil/TestValidator.java |  23 ++
 .../server/core/uri/testutil/UriValidator.java  | 257 ------------------
 .../server/core/uri/testutil/Validator.java     |  23 --
 .../core/uri/validator/UriValidatorTest.java    |  31 ++-
 13 files changed, 508 insertions(+), 371 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java
index b7191a6..8f3674c 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmProviderImpl.java
@@ -129,7 +129,7 @@ public class EdmProviderImpl extends AbstractEdm {
 
   @Override
   public EdmAction createBoundAction(final FullQualifiedName actionName,
-          final FullQualifiedName bindingParameterTypeName, final Boolean 
isBindingParameterCollection) {
+      final FullQualifiedName bindingParameterTypeName, final Boolean 
isBindingParameterCollection) {
 
     try {
       List<Action> actions = actionsMap.get(actionName);
@@ -147,7 +147,7 @@ public class EdmProviderImpl extends AbstractEdm {
           final List<Parameter> parameters = action.getParameters();
           final Parameter parameter = parameters.get(0);
           if (bindingParameterTypeName.equals(parameter.getType())
-                  && isBindingParameterCollection.booleanValue() == 
parameter.isCollection()) {
+              && isBindingParameterCollection.booleanValue() == 
parameter.isCollection()) {
 
             return EdmActionImpl.getInstance(this, actionName, action);
           }
@@ -162,8 +162,8 @@ public class EdmProviderImpl extends AbstractEdm {
 
   @Override
   public EdmFunction createBoundFunction(final FullQualifiedName functionName,
-          final FullQualifiedName bindingParameterTypeName, final Boolean 
isBindingParameterCollection,
-          final List<String> parameterNames) {
+      final FullQualifiedName bindingParameterTypeName, final Boolean 
isBindingParameterCollection,
+      final List<String> parameterNames) {
 
     try {
       List<Function> functions = functionsMap.get(functionName);
@@ -175,8 +175,8 @@ public class EdmProviderImpl extends AbstractEdm {
           functionsMap.put(functionName, functions);
         }
       }
-      final List<String> parameterNamesCopy
-              = parameterNames == null ? Collections.<String>emptyList() : 
parameterNames;
+      final List<String> parameterNamesCopy =
+          parameterNames == null ? Collections.<String> emptyList() : 
parameterNames;
       for (Function function : functions) {
         if (function.isBound()) {
           List<Parameter> providerParameters = function.getParameters();
@@ -185,7 +185,7 @@ public class EdmProviderImpl extends AbstractEdm {
           }
           final Parameter bindingParameter = providerParameters.get(0);
           if (bindingParameterTypeName.equals(bindingParameter.getType())
-                  && isBindingParameterCollection.booleanValue() == 
bindingParameter.isCollection()) {
+              && isBindingParameterCollection.booleanValue() == 
bindingParameter.isCollection()) {
 
             if (parameterNamesCopy.size() == providerParameters.size() - 1) {
               final List<String> providerParameterNames = new 
ArrayList<String>();
@@ -260,11 +260,12 @@ public class EdmProviderImpl extends AbstractEdm {
         functions = provider.getFunctions(functionName);
         if (functions != null) {
           functionsMap.put(functionName, functions);
-
-          for (Function function : functions) {
-            if (!function.isBound()) {
-              result.add(EdmFunctionImpl.getInstance(this, functionName, 
function));
-            }
+        }
+      }
+      if (functions != null) {
+        for (Function function : functions) {
+          if (!function.isBound()) {
+            result.add(EdmFunctionImpl.getInstance(this, functionName, 
function));
           }
         }
       }
@@ -287,8 +288,9 @@ public class EdmProviderImpl extends AbstractEdm {
           functionsMap.put(functionName, functions);
         }
       }
-      final List<String> parameterNamesCopy
-              = parameterNames == null ? Collections.<String>emptyList() : 
parameterNames;
+
+      final List<String> parameterNamesCopy =
+          parameterNames == null ? Collections.<String> emptyList() : 
parameterNames;
       for (Function function : functions) {
         if (!function.isBound()) {
           List<Parameter> providerParameters = function.getParameters();

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
index 4ddff49..6618560 100644
--- 
a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
+++ 
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
@@ -21,14 +21,18 @@ package org.apache.olingo.server.core.uri.validator;
 import java.util.HashMap;
 import java.util.List;
 
-import org.apache.olingo.commons.api.ODataRuntimeException;
-import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmActionImport;
 import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmFunctionImport;
 import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
 import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
 import org.apache.olingo.commons.api.edm.EdmReturnType;
+import org.apache.olingo.commons.api.edm.EdmSingleton;
 import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
 import org.apache.olingo.server.api.uri.UriInfo;
 import org.apache.olingo.server.api.uri.UriParameter;
 import org.apache.olingo.server.api.uri.UriResource;
@@ -38,6 +42,7 @@ import org.apache.olingo.server.api.uri.UriResourceFunction;
 import org.apache.olingo.server.api.uri.UriResourceKind;
 import org.apache.olingo.server.api.uri.UriResourceNavigation;
 import org.apache.olingo.server.api.uri.UriResourcePartTyped;
+import org.apache.olingo.server.api.uri.UriResourceSingleton;
 import org.apache.olingo.server.api.uri.queryoption.SystemQueryOption;
 import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
 
@@ -80,7 +85,7 @@ public class UriValidator {
         /*                            PATCH  0 */ { false ,  false ,  false ,  
false,   false ,  false ,   false ,  false ,  false ,  false ,     false ,   
false },
         /*                            MERGE  0 */ { false ,  false ,  false ,  
false,   false ,  false ,   false ,  false ,  false ,  false ,     false ,   
false },
     };
-  
+
   //CHECKSTYLE:ON
   //@formatter:on
 
@@ -163,15 +168,17 @@ public class UriValidator {
 
   }
 
-  public void validate(final UriInfo uriInfo, final Edm edm, String 
httpMethod) throws UriValidationException {
+  public UriValidator() {
+    super();
+  }
 
+  public void validate(final UriInfo uriInfo, String httpMethod) throws 
UriValidationException {
     validateForHttpMethod(uriInfo, httpMethod);
-    validateQueryOptions(uriInfo, edm);
-    validateKeyPredicateTypes(uriInfo, edm);
-
+    validateQueryOptions(uriInfo);
+    validateKeyPredicateTypes(uriInfo);
   }
 
-  private ColumnIndex colIndex(SystemQueryOptionKind queryOptionKind) {
+  private ColumnIndex colIndex(SystemQueryOptionKind queryOptionKind) throws 
UriValidationException {
     ColumnIndex idx;
     switch (queryOptionKind) {
     case FILTER:
@@ -211,13 +218,13 @@ public class UriValidator {
       idx = ColumnIndex.top;
       break;
     default:
-      throw new ODataRuntimeException("Unsupported option: " + 
queryOptionKind);
+      throw new UriValidationException("Unsupported option: " + 
queryOptionKind);
     }
 
     return idx;
   }
 
-  private RowIndexForUriType rowIndexForUriType(final UriInfo uriInfo, Edm 
edm) throws UriValidationException {
+  private RowIndexForUriType rowIndexForUriType(final UriInfo uriInfo) throws 
UriValidationException {
     RowIndexForUriType idx;
 
     switch (uriInfo.getKind()) {
@@ -237,19 +244,19 @@ public class UriValidator {
       idx = RowIndexForUriType.metadata;
       break;
     case resource:
-      idx = rowIndexForResourceKind(uriInfo, edm);
+      idx = rowIndexForResourceKind(uriInfo);
       break;
     case service:
       idx = RowIndexForUriType.service;
       break;
     default:
-      throw new ODataRuntimeException("Unsupported uriInfo kind: " + 
uriInfo.getKind());
+      throw new UriValidationException("Unsupported uriInfo kind: " + 
uriInfo.getKind());
     }
 
     return idx;
   }
 
-  private RowIndexForUriType rowIndexForResourceKind(UriInfo uriInfo, Edm edm) 
throws UriValidationException {
+  private RowIndexForUriType rowIndexForResourceKind(UriInfo uriInfo) throws 
UriValidationException {
     RowIndexForUriType idx;
 
     int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1;
@@ -292,7 +299,7 @@ public class UriValidator {
       idx = rowIndexForValue(uriInfo);
       break;
     default:
-      throw new ODataRuntimeException("Unsupported uriResource kind: " + 
lastPathSegment.getKind());
+      throw new UriValidationException("Unsupported uriResource kind: " + 
lastPathSegment.getKind());
     }
 
     return idx;
@@ -302,6 +309,7 @@ public class UriValidator {
     RowIndexForUriType idx;
     int secondLastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 2;
     UriResource secondLastPathSegment = 
uriInfo.getUriResourceParts().get(secondLastPathSegmentIndex);
+
     switch (secondLastPathSegment.getKind()) {
     case primitiveProperty:
       idx = RowIndexForUriType.propertyPrimitiveValue;
@@ -309,10 +317,77 @@ public class UriValidator {
     case entitySet:
       idx = RowIndexForUriType.mediaStream;
       break;
+    case function:
+      UriResourceFunction uriFunction = (UriResourceFunction) 
secondLastPathSegment;
+
+      EdmFunction function;
+      EdmFunctionImport functionImport = uriFunction.getFunctionImport();
+      if (functionImport != null) {
+        List<EdmFunction> functions = functionImport.getUnboundFunctions();
+        function = functions.get(0);
+      } else {
+        function = uriFunction.getFunction();
+      }
+
+      EdmTypeKind functionReturnTypeKind = 
function.getReturnType().getType().getKind();
+      boolean isFunctionCollection = function.getReturnType().isCollection();
+      idx = determineReturnType(functionReturnTypeKind, isFunctionCollection);
+      break;
+    case action:
+      UriResourceAction uriAction = (UriResourceAction) secondLastPathSegment;
+      EdmActionImport actionImport = uriAction.getActionImport();
+
+      EdmAction action;
+      if (actionImport != null) {
+        action = actionImport.getUnboundAction();
+      } else {
+        action = uriAction.getAction();
+      }
+
+      EdmTypeKind actionReturnTypeKind = 
action.getReturnType().getType().getKind();
+      boolean isActionCollection = action.getReturnType().isCollection();
+      idx = determineReturnType(actionReturnTypeKind, isActionCollection);
+
+      break;
+    case navigationProperty:
+      UriResourceNavigation uriNavigation = (UriResourceNavigation) 
secondLastPathSegment;
+
+      if (uriNavigation.isCollection()) {
+        idx = RowIndexForUriType.entitySet;
+      } else {
+        idx = RowIndexForUriType.entity;
+      }
+      break;
+    case singleton:
+      UriResourceSingleton uriSingleton = (UriResourceSingleton) 
secondLastPathSegment;
+      EdmSingleton singleton = uriSingleton.getSingleton();
+      EdmTypeKind singletonReturnTypeKind = 
singleton.getEntityType().getKind();
+      idx = determineReturnType(singletonReturnTypeKind, false);
+      break;
     default:
       throw new UriValidationException("Unexpected kind in path segment before 
$value: "
           + secondLastPathSegment.getKind());
+    }
+    return idx;
+  }
 
+  private RowIndexForUriType determineReturnType(EdmTypeKind 
functionReturnTypeKind,
+      boolean isCollection) throws UriValidationException {
+    RowIndexForUriType idx;
+    switch (functionReturnTypeKind) {
+    case COMPLEX:
+      idx = isCollection ? RowIndexForUriType.propertyComplexCollection : 
RowIndexForUriType.propertyComplex;
+      break;
+    case ENTITY:
+      idx = isCollection ? RowIndexForUriType.entitySet : 
RowIndexForUriType.entity;
+      break;
+    case PRIMITIVE:
+    case ENUM:
+    case DEFINITION:
+      idx = isCollection ? RowIndexForUriType.propertyPrimitiveCollection : 
RowIndexForUriType.propertyPrimitive;
+      break;
+    default:
+      throw new UriValidationException("Unsupported function return type: " + 
functionReturnTypeKind);
     }
     return idx;
   }
@@ -441,15 +516,32 @@ public class UriValidator {
     case primitiveProperty:
       idx = RowIndexForUriType.propertyPrimitiveCollectionCount;
       break;
+    case function:
+      UriResourceFunction uriFunction = (UriResourceFunction) 
secondLastPathSegment;
+
+      EdmFunction function;
+      List<EdmFunction> functions;
+      EdmFunctionImport functionImport = uriFunction.getFunctionImport();
+      if (functionImport != null) {
+        functions = functionImport.getUnboundFunctions();
+        function = functions.get(0);
+      } else {
+        function = uriFunction.getFunction();
+      }
+
+      EdmTypeKind functionReturnTypeKind = 
function.getReturnType().getType().getKind();
+      boolean isCollection = function.getReturnType().isCollection();
+      idx = determineReturnType(functionReturnTypeKind, isCollection);
+      break;
     default:
-      throw new UriValidationException("Illegal path part kind: " + 
lastPathSegment.getKind());
+      throw new UriValidationException("Illegal path part kind: " + 
secondLastPathSegment.getKind());
     }
 
     return idx;
   }
 
-  private void validateQueryOptions(final UriInfo uriInfo, Edm edm) throws 
UriValidationException {
-    RowIndexForUriType row = rowIndexForUriType(uriInfo, edm);
+  private void validateQueryOptions(final UriInfo uriInfo) throws 
UriValidationException {
+    RowIndexForUriType row = rowIndexForUriType(uriInfo);
 
     for (SystemQueryOption option : uriInfo.getSystemQueryOptions()) {
       ColumnIndex col = colIndex(option.getKind());
@@ -496,7 +588,7 @@ public class UriValidator {
     return idx;
   }
 
-  private void validateKeyPredicateTypes(final UriInfo uriInfo, final Edm edm) 
throws UriValidationException {
+  private void validateKeyPredicateTypes(final UriInfo uriInfo) throws 
UriValidationException {
     try {
       for (UriResource pathSegment : uriInfo.getUriResourceParts()) {
         if (pathSegment.getKind() == UriResourceKind.entitySet) {
@@ -511,6 +603,10 @@ public class UriValidator {
             HashMap<String, EdmKeyPropertyRef> edmKeys = new HashMap<String, 
EdmKeyPropertyRef>();
             for (EdmKeyPropertyRef key : keys) {
               edmKeys.put(key.getKeyPropertyName(), key);
+              String alias = key.getAlias();
+              if (null != alias) {
+                edmKeys.put(alias, key);
+              }
             }
 
             for (UriParameter keyPredicate : keyPredicates) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/test/java/org/apache/olingo/server/core/testutil/techprovider/EntityTypeProvider.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/testutil/techprovider/EntityTypeProvider.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/testutil/techprovider/EntityTypeProvider.java
index 291d893..9072234 100644
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/testutil/techprovider/EntityTypeProvider.java
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/testutil/techprovider/EntityTypeProvider.java
@@ -381,17 +381,15 @@ public class EntityTypeProvider {
     } else if (entityTypeName.equals(nameETFourKeyAlias)) {
       return new EntityType()
           .setName("ETFourKeyAlias")
-          .setKey(Arrays.asList(
-              new PropertyRef()
-                  .setPropertyName("PropertyInt16"),
-              new PropertyRef()
-                  
.setPropertyName("PropertyComplex/PropertyInt16").setAlias("KeyAlias1"),
-              new PropertyRef()
-                  
.setPropertyName("PropertyComplex/PropertyString").setAlias("KeyAlias2"),
-              new PropertyRef()
-                  
.setPropertyName("PropertyComplexComplex/PropertyComplex/PropertyString")
-                  .setAlias("KeyAlias3")))
-          .setProperties(
+          .setKey(
+              Arrays.asList(
+                  new PropertyRef().setPropertyName("PropertyInt16"),
+                  new 
PropertyRef().setPath("PropertyComplex/PropertyInt16").setPropertyName("PropertyInt16").setAlias(
+                      "KeyAlias1"),
+                  new 
PropertyRef().setPath("PropertyComplex/PropertyString").setPropertyName("PropertyString")
+                      .setAlias("KeyAlias2"),
+                  new 
PropertyRef().setPath("PropertyComplexComplex/PropertyComplex/PropertyString").setPropertyName(
+                      "PropertyString").setAlias("KeyAlias3"))).setProperties(
               Arrays.asList(PropertyProvider.propertyInt16_NotNullable, 
PropertyProvider.propertyComplex_CTTwoPrim,
                   PropertyProvider.propertyComplexComplex_CTCompComp));
     } else if (entityTypeName.equals(nameETCompMixPrimCollComp)) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index ec78def..702d559 100644
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -38,18 +38,18 @@ import 
org.apache.olingo.server.core.testutil.techprovider.PropertyProvider;
 import org.apache.olingo.server.core.uri.parser.UriParserException;
 import org.apache.olingo.server.core.uri.testutil.FilterValidator;
 import org.apache.olingo.server.core.uri.testutil.ResourceValidator;
-import org.apache.olingo.server.core.uri.testutil.UriValidator;
+import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
 import org.junit.Test;
 
 public class TestFullResourcePath {
   Edm edm = null;
-  UriValidator testUri = null;
+  TestUriValidator testUri = null;
   ResourceValidator testRes = null;
   FilterValidator testFilter = null;
 
   public TestFullResourcePath() {
     edm = new EdmProviderImpl(new EdmTechTestProvider());
-    testUri = new UriValidator().setEdm(edm);
+    testUri = new TestUriValidator().setEdm(edm);
     testRes = new ResourceValidator().setEdm(edm);
     testFilter = new FilterValidator().setEdm(edm);
   }
@@ -817,7 +817,7 @@ public class TestFullResourcePath {
         .isType(PropertyProvider.nameString);
 
     // on complex
-    testUri.run("ESTwoKeyNav(ParameterInt16=1,PropertyString='ABC')"
+    testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='ABC')"
         + "/PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTESTwoKeyNav()")
         .goPath()
         .at(0)
@@ -840,7 +840,7 @@ public class TestFullResourcePath {
         .isType(EntityTypeProvider.nameETAllPrim);
 
     // on entity
-    testUri.run("ESTwoKeyNav(ParameterInt16=1,PropertyString='ABC')"
+    testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='ABC')"
         + "/com.sap.odata.test1.BFCETTwoKeyNavRTESTwoKeyNav()")
         .goPath()
         .at(0)

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
index 50b7a5d..06dfccc 100644
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
@@ -35,7 +35,8 @@ import 
org.apache.olingo.server.core.testutil.techprovider.PropertyProvider;
 import org.apache.olingo.server.core.uri.parser.UriParserException;
 import org.apache.olingo.server.core.uri.testutil.FilterValidator;
 import org.apache.olingo.server.core.uri.testutil.ResourceValidator;
-import org.apache.olingo.server.core.uri.testutil.UriValidator;
+import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
+import org.apache.olingo.server.core.uri.validator.UriValidationException;
 import org.junit.Test;
 
 public class TestUriParserImpl {
@@ -59,13 +60,13 @@ public class TestUriParserImpl {
       + "," + PropertySByte + "," + PropertyInt32 + "," + PropertyInt64 + "," 
+ PropertyDecimal + "," + PropertyDate
       + "," + PropertyDateTimeOffset + "," + PropertyDuration + "," + 
PropertyGuid + "," + PropertyTimeOfDay;
 
-  UriValidator testUri = null;
+  TestUriValidator testUri = null;
   ResourceValidator testRes = null;
   FilterValidator testFilter = null;
 
   public TestUriParserImpl() {
     edm = new EdmProviderImpl(new EdmTechTestProvider());
-    testUri = new UriValidator().setEdm(edm);
+    testUri = new TestUriValidator().setEdm(edm);
     testRes = new ResourceValidator().setEdm(edm);
     testFilter = new FilterValidator().setEdm(edm);
   }
@@ -234,6 +235,26 @@ public class TestUriParserImpl {
         .isCrossJoinEntityList(Arrays.asList("ESAllKey", "ESTwoPrim"));
   }
 
+  @Test(expected = Exception.class)
+  public void testEntityFailOnValidation1() {
+    // simple entity set; with qualifiedentityTypeName; with filter
+    testUri.run("$entity/com.sap.odata.test1.ETTwoPrim?$filter=PropertyInt16 
eq 123&$id=ESAllKey")
+        .isIdText("ESAllKey")
+        .goFilter().is("<<PropertyInt16> eq <123>>");
+  }
+
+  @Test(expected = Exception.class)
+  public void testEntityFailOnValidation2() {
+    // simple entity set; with qualifiedentityTypeName; with 2xformat(before 
and after), expand, filter
+    testUri.run("$entity/com.sap.odata.test1.ETTwoPrim?"
+        + 
"$format=xml&$expand=*&abc=123&$id=ESBase&xyz=987&$filter=PropertyInt16 eq 
123&$format=atom&$select=*")
+        .isFormatText("atom")
+        .isCustomParameter(0, "abc", "123")
+        .isIdText("ESBase")
+        .isCustomParameter(1, "xyz", "987")
+        .isSelectItemStar(0);
+  }
+
   @Test
   public void testEntity() {
 
@@ -274,11 +295,6 @@ public class TestUriParserImpl {
         .isEntityType(EntityTypeProvider.nameETTwoPrim)
         .isIdText("ESBase");
 
-    // simple entity set; with qualifiedentityTypeName; with filter
-    testUri.run("$entity/com.sap.odata.test1.ETTwoPrim?$filter=PropertyInt16 
eq 123&$id=ESAllKey")
-        .isIdText("ESAllKey")
-        .goFilter().is("<<PropertyInt16> eq <123>>");
-
     // simple entity set; with qualifiedentityTypeName;
     testUri.run("$entity/com.sap.odata.test1.ETBase?$id=ESTwoPrim")
         .isEntityType(EntityTypeProvider.nameETBase)
@@ -307,14 +323,6 @@ public class TestUriParserImpl {
         .isExpandText("*")
         .goExpand().first().isSegmentStar(0);
 
-    // simple entity set; with qualifiedentityTypeName; with 2xformat(before 
and after), expand, filter
-    testUri.run("$entity/com.sap.odata.test1.ETTwoPrim?"
-        + 
"$format=xml&$expand=*&abc=123&$id=ESBase&xyz=987&$filter=PropertyInt16 eq 
123&$format=atom&$select=*")
-        .isFormatText("atom")
-        .isCustomParameter(0, "abc", "123")
-        .isIdText("ESBase")
-        .isCustomParameter(1, "xyz", "987")
-        .isSelectItemStar(0);
   }
 
   @Test
@@ -986,8 +994,8 @@ public class TestUriParserImpl {
     testUri.run("ESAllPrim(1)/PropertyString/$value");
   }
 
-  @Test
-  public void testMemberStartingWithCast() {
+  @Test(expected = Exception.class)
+  public void testMemberStartingWithCastFailOnValidation1() {
     // on EntityType entry
     testUri.run("ESTwoKeyNav(ParameterInt16=1,PropertyString='ABC')?"
         + "$filter=com.sap.odata.test1.ETBaseTwoKeyNav/PropertyDate")
@@ -998,17 +1006,10 @@ public class TestUriParserImpl {
         // .isType(EntityTypeProvider.nameETTwoKeyNav, false)
         // .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
         .at(0).isType(PropertyProvider.nameDate);
+  }
 
-    // on EntityType collection
-    
testUri.run("ESTwoKeyNav?$filter=com.sap.odata.test1.ETBaseTwoKeyNav/PropertyDate")
-        .goFilter().root().isMember()
-        .isMemberStartType(EntityTypeProvider.nameETBaseTwoKeyNav).goPath()
-        // .at(0)
-        // .isUriPathInfoKind(UriResourceKind.startingTypeFilter)
-        // .isType(EntityTypeProvider.nameETTwoKeyNav, true)
-        // .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
-        .at(0).isType(PropertyProvider.nameDate);
-
+  @Test(expected = Exception.class)
+  public void testMemberStartingWithCastFailOnValidation2() {
     testUri.run("FICRTCTTwoPrimParam(ParameterInt16=1,ParameterString='2')?"
         + "$filter=com.sap.odata.test1.CTBase/AdditionalPropString")
         .goFilter().root().isMember()
@@ -1018,6 +1019,20 @@ public class TestUriParserImpl {
         // .isType(ComplexTypeProvider.nameCTTwoPrim, false)
         // .isTypeFilterOnEntry(ComplexTypeProvider.nameCTBase)
         .at(0).isType(PropertyProvider.nameString);
+  }
+
+  @Test
+  public void testMemberStartingWithCast() {
+
+    // on EntityType collection
+    
testUri.run("ESTwoKeyNav?$filter=com.sap.odata.test1.ETBaseTwoKeyNav/PropertyDate")
+        .goFilter().root().isMember()
+        .isMemberStartType(EntityTypeProvider.nameETBaseTwoKeyNav).goPath()
+        // .at(0)
+        // .isUriPathInfoKind(UriResourceKind.startingTypeFilter)
+        // .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+        // .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+        .at(0).isType(PropertyProvider.nameDate);
 
     // on Complex collection
     
testUri.run("FICRTCollCTTwoPrimParam(ParameterInt16=1,ParameterString='2')?"

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java
index 98cbce6..fde13c8 100644
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java
@@ -36,9 +36,9 @@ import 
org.apache.olingo.server.core.uri.queryoption.OrderByOptionImpl;
 import org.apache.olingo.server.core.uri.queryoption.QueryOptionImpl;
 import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
 
-public class ExpandValidator implements Validator {
+public class ExpandValidator implements TestValidator {
   private Edm edm;
-  private Validator invokedByValidator;
+  private TestValidator invokedByValidator;
 
   private int expandItemIndex;
   private ExpandOptionImpl expandOption;
@@ -46,7 +46,7 @@ public class ExpandValidator implements Validator {
 
   // --- Setup ---
 
-  public ExpandValidator setUpValidator(final Validator validator) {
+  public ExpandValidator setUpValidator(final TestValidator validator) {
     invokedByValidator = validator;
     return this;
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
index 2ee92f7..58e429f 100644
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
@@ -48,10 +48,10 @@ import 
org.apache.olingo.server.core.uri.queryoption.expression.MemberImpl;
 import org.apache.olingo.server.core.uri.queryoption.expression.MethodImpl;
 import 
org.apache.olingo.server.core.uri.queryoption.expression.TypeLiteralImpl;
 
-public class FilterValidator implements Validator {
+public class FilterValidator implements TestValidator {
   private Edm edm;
 
-  private Validator invokedByValidator;
+  private TestValidator invokedByValidator;
   private FilterOptionImpl filter;
 
   private Expression curExpression;
@@ -67,12 +67,12 @@ public class FilterValidator implements Validator {
     return this;
   }
 
-  public FilterValidator setUriValidator(final UriValidator uriValidator) {
+  public FilterValidator setUriValidator(final TestUriValidator uriValidator) {
     invokedByValidator = uriValidator;
     return this;
   }
 
-  public FilterValidator setValidator(final Validator uriValidator) {
+  public FilterValidator setValidator(final TestValidator uriValidator) {
     invokedByValidator = uriValidator;
     return this;
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
index 039cebd..072de08 100644
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
@@ -55,9 +55,9 @@ import 
org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
 import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
 import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl;
 
-public class ResourceValidator implements Validator {
+public class ResourceValidator implements TestValidator {
   private Edm edm;
-  private Validator invokedBy;
+  private TestValidator invokedBy;
   private UriInfo uriInfo = null;
 
   private UriResourceImpl uriPathInfo = null;
@@ -65,7 +65,7 @@ public class ResourceValidator implements Validator {
 
   // --- Setup ---
 
-  public ResourceValidator setUpValidator(final Validator uriValidator) {
+  public ResourceValidator setUpValidator(final TestValidator uriValidator) {
     invokedBy = uriValidator;
     return this;
   }
@@ -106,8 +106,8 @@ public class ResourceValidator implements Validator {
 
   // --- Navigation ---
 
-  public UriValidator goUpUriValidator() {
-    return (UriValidator) invokedBy;
+  public TestUriValidator goUpUriValidator() {
+    return (TestUriValidator) invokedBy;
   }
 
   public ExpandValidator goUpExpandValidator() {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
new file mode 100644
index 0000000..35687f6
--- /dev/null
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
@@ -0,0 +1,258 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.server.api.uri.UriInfoKind;
+import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption;
+import org.apache.olingo.server.api.uri.queryoption.SelectItem;
+import org.apache.olingo.server.core.uri.UriInfoImpl;
+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.CustomQueryOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.FilterOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
+import org.apache.olingo.server.core.uri.validator.UriValidator;
+
+public class TestUriValidator implements TestValidator {
+  private Edm edm;
+
+  private UriInfoImpl uriInfo;
+  private Exception exception;
+
+  // Setup
+  public TestUriValidator setEdm(final Edm edm) {
+    this.edm = edm;
+    return this;
+  }
+
+  // Execution
+  public TestUriValidator run(final String uri) {
+    Parser parser = new Parser();
+    UriValidator validator = new UriValidator();
+
+    uriInfo = null;
+    try {
+      uriInfo = (UriInfoImpl) parser.parseUri(uri, edm);
+      validator.validate(uriInfo, "GET");
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+
+    return this;
+  }
+
+  public TestUriValidator runEx(final String uri) {
+    Parser parser = new Parser();
+    uriInfo = null;
+    try {
+      uriInfo = (UriInfoImpl) parser.parseUri(uri, edm);
+      fail("Exception expected");
+    } catch (UriParserException e) {
+      exception = e;
+    }
+
+    return this;
+  }
+
+  public TestUriValidator log(final String uri) {
+    ParserWithLogging parserTest = new ParserWithLogging();
+    parserTest.setLogLevel(1);
+    uriInfo = null;
+    try {
+      // uriInfoTmp = new UriParserImpl(edm).ParseUri(uri);
+      uriInfo = (UriInfoImpl) parserTest.parseUri(uri, edm);
+    } catch (UriParserException e) {
+      fail("Exception occured while parsing the URI: " + uri + "\n"
+          + " Exception: " + e.getMessage());
+    }
+
+    return this;
+  }
+
+  // Navigation
+  public ResourceValidator goPath() {
+    if (uriInfo.getKind() != UriInfoKind.resource) {
+      fail("invalid resource kind: " + uriInfo.getKind().toString());
+    }
+
+    return new ResourceValidator()
+        .setUpValidator(this)
+        .setEdm(edm)
+        .setUriInfoImplPath(uriInfo);
+  }
+
+  public FilterValidator goFilter() {
+    FilterOptionImpl filter = (FilterOptionImpl) uriInfo.getFilterOption();
+    if (filter == null) {
+      fail("no filter found");
+    }
+    return new FilterValidator().setUriValidator(this).setFilter(filter);
+
+  }
+
+  public ExpandValidator goExpand() {
+    ExpandOptionImpl expand = (ExpandOptionImpl) uriInfo.getExpandOption();
+    if (expand == null) {
+      fail("invalid resource kind: " + uriInfo.getKind().toString());
+    }
+
+    return new ExpandValidator().setUpValidator(this).setExpand(expand);
+  }
+
+  public ResourceValidator goSelectItemPath(final int index) {
+    SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
+
+    SelectItem item = select.getSelectItems().get(index);
+    UriInfoImpl uriInfo1 = (UriInfoImpl) item.getResourcePath();
+
+    return new ResourceValidator()
+        .setUpValidator(this)
+        .setEdm(edm)
+        .setUriInfoImplPath(uriInfo1);
+
+  }
+
+  public TestUriValidator isSelectStartType(final int index, final 
FullQualifiedName fullName) {
+    SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
+    SelectItem item = select.getSelectItems().get(index);
+    EdmType actualType = item.getStartTypeFilter();
+
+    FullQualifiedName actualName = new 
FullQualifiedName(actualType.getNamespace(), actualType.getName());
+    assertEquals(fullName, actualName);
+    return this;
+
+  }
+
+  // Validation
+  public TestUriValidator isKind(final UriInfoKind kind) {
+    assertEquals(kind, uriInfo.getKind());
+    return this;
+  }
+
+  public TestUriValidator isCustomParameter(final int index, final String 
name, final String value) {
+    if (uriInfo == null) {
+      fail("hasQueryParameter: uriInfo == null");
+    }
+
+    List<CustomQueryOption> list = uriInfo.getCustomQueryOptions();
+    if (list.size() <= index) {
+      fail("not enought queryParameters");
+    }
+
+    CustomQueryOptionImpl option = (CustomQueryOptionImpl) list.get(index);
+    assertEquals(name, option.getName());
+    assertEquals(value, option.getText());
+    return this;
+  }
+
+  public void isCrossJoinEntityList(final List<String> entitySets) {
+    if (uriInfo.getKind() != UriInfoKind.crossjoin) {
+      fail("invalid resource kind: " + uriInfo.getKind().toString());
+    }
+
+    int i = 0;
+    for (String entitySet : entitySets) {
+      assertEquals(entitySet, uriInfo.getEntitySetNames().get(i));
+      i++;
+    }
+
+  }
+
+  public TestUriValidator isExSyntax(final long errorID) {
+    assertEquals(UriParserSyntaxException.class, exception.getClass());
+    return this;
+  }
+
+  public TestUriValidator isExSemantic(final long errorID) {
+    assertEquals(UriParserSemanticException.class, exception.getClass());
+    return this;
+  }
+
+  public TestUriValidator isIdText(final String text) {
+    assertEquals(text, uriInfo.getIdOption().getText());
+    return this;
+  }
+
+  public TestUriValidator isExpandText(final String text) {
+    assertEquals(text, uriInfo.getExpandOption().getText());
+    return this;
+  }
+
+  public TestUriValidator isSelectText(final String text) {
+    assertEquals(text, uriInfo.getSelectOption().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.toString(), fullName(uriInfo.getEntityTypeCast()));
+    return this;
+  }
+
+  private String fullName(final EdmEntityType type) {
+    return type.getNamespace() + "." + type.getName();
+  }
+
+  public TestUriValidator isSelectItemStar(final int index) {
+    SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
+
+    SelectItem item = select.getSelectItems().get(index);
+    assertEquals(true, item.isStar());
+    return this;
+  }
+
+  public TestUriValidator isSelectItemAllOp(final int index, final 
FullQualifiedName fqn) {
+    SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
+
+    SelectItem item = select.getSelectItems().get(index);
+    assertEquals(fqn.toString(), 
item.getAllOperationsInSchemaNameSpace().toString());
+    return this;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/TestValidator.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/TestValidator.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/TestValidator.java
new file mode 100644
index 0000000..7e64f86
--- /dev/null
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/TestValidator.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+public interface TestValidator {
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/UriValidator.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/UriValidator.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/UriValidator.java
deleted file mode 100644
index e098f4c..0000000
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/UriValidator.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.uri.testutil;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.util.List;
-
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.EdmType;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.server.api.uri.UriInfoKind;
-import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption;
-import org.apache.olingo.server.api.uri.queryoption.SelectItem;
-import org.apache.olingo.server.core.uri.UriInfoImpl;
-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.CustomQueryOptionImpl;
-import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
-import org.apache.olingo.server.core.uri.queryoption.FilterOptionImpl;
-import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
-
-public class UriValidator implements Validator {
-  private Edm edm;
-
-  private UriInfoImpl uriInfo;
-  private Exception exception;
-
-  // Setup
-  public UriValidator setEdm(final Edm edm) {
-    this.edm = edm;
-    return this;
-  }
-
-  // Execution
-  public UriValidator run(final String uri) {
-    Parser parser = new Parser();
-    uriInfo = null;
-    try {
-      // uriInfoTmp = new UriParserImpl(edm).ParseUri(uri);
-      uriInfo = (UriInfoImpl) parser.parseUri(uri, edm);
-    } catch (UriParserException e) {
-      fail("Exception occured while parsing the URI: " + uri + "\n"
-          + " Exception: " + e.getMessage());
-    }
-
-    return this;
-  }
-
-  public UriValidator runEx(final String uri) {
-    Parser parser = new Parser();
-    uriInfo = null;
-    try {
-      // uriInfoTmp = new UriParserImpl(edm).ParseUri(uri);
-      uriInfo = (UriInfoImpl) parser.parseUri(uri, edm);
-      fail("Exception expected");
-    } catch (UriParserException e) {
-      exception = e;
-    }
-
-    return this;
-  }
-
-  public UriValidator log(final String uri) {
-    ParserWithLogging parserTest = new ParserWithLogging();
-    parserTest.setLogLevel(1);
-    uriInfo = null;
-    try {
-      // uriInfoTmp = new UriParserImpl(edm).ParseUri(uri);
-      uriInfo = (UriInfoImpl) parserTest.parseUri(uri, edm);
-    } catch (UriParserException e) {
-      fail("Exception occured while parsing the URI: " + uri + "\n"
-          + " Exception: " + e.getMessage());
-    }
-
-    return this;
-  }
-
-  // Navigation
-  public ResourceValidator goPath() {
-    if (uriInfo.getKind() != UriInfoKind.resource) {
-      fail("invalid resource kind: " + uriInfo.getKind().toString());
-    }
-
-    return new ResourceValidator()
-        .setUpValidator(this)
-        .setEdm(edm)
-        .setUriInfoImplPath(uriInfo);
-  }
-
-  public FilterValidator goFilter() {
-    FilterOptionImpl filter = (FilterOptionImpl) uriInfo.getFilterOption();
-    if (filter == null) {
-      fail("no filter found");
-    }
-    return new FilterValidator().setUriValidator(this).setFilter(filter);
-
-  }
-
-  public ExpandValidator goExpand() {
-    ExpandOptionImpl expand = (ExpandOptionImpl) uriInfo.getExpandOption();
-    if (expand == null) {
-      fail("invalid resource kind: " + uriInfo.getKind().toString());
-    }
-
-    return new ExpandValidator().setUpValidator(this).setExpand(expand);
-  }
-
-  public ResourceValidator goSelectItemPath(final int index) {
-    SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
-
-    SelectItem item = select.getSelectItems().get(index);
-    UriInfoImpl uriInfo1 = (UriInfoImpl) item.getResourcePath();
-
-    return new ResourceValidator()
-        .setUpValidator(this)
-        .setEdm(edm)
-        .setUriInfoImplPath(uriInfo1);
-
-  }
-
-  public UriValidator isSelectStartType(final int index, final 
FullQualifiedName fullName) {
-    SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
-    SelectItem item = select.getSelectItems().get(index);
-    EdmType actualType = item.getStartTypeFilter();
-
-    FullQualifiedName actualName = new 
FullQualifiedName(actualType.getNamespace(), actualType.getName());
-    assertEquals(fullName, actualName);
-    return this;
-
-  }
-
-  // Validation
-  public UriValidator isKind(final UriInfoKind kind) {
-    assertEquals(kind, uriInfo.getKind());
-    return this;
-  }
-
-  public UriValidator isCustomParameter(final int index, final String name, 
final String value) {
-    if (uriInfo == null) {
-      fail("hasQueryParameter: uriInfo == null");
-    }
-
-    List<CustomQueryOption> list = uriInfo.getCustomQueryOptions();
-    if (list.size() <= index) {
-      fail("not enought queryParameters");
-    }
-
-    CustomQueryOptionImpl option = (CustomQueryOptionImpl) list.get(index);
-    assertEquals(name, option.getName());
-    assertEquals(value, option.getText());
-    return this;
-  }
-
-  public void isCrossJoinEntityList(final List<String> entitySets) {
-    if (uriInfo.getKind() != UriInfoKind.crossjoin) {
-      fail("invalid resource kind: " + uriInfo.getKind().toString());
-    }
-
-    int i = 0;
-    for (String entitySet : entitySets) {
-      assertEquals(entitySet, uriInfo.getEntitySetNames().get(i));
-      i++;
-    }
-
-  }
-
-  public UriValidator isExSyntax(final long errorID) {
-    assertEquals(UriParserSyntaxException.class, exception.getClass());
-    return this;
-  }
-
-  public UriValidator isExSemantic(final long errorID) {
-    assertEquals(UriParserSemanticException.class, exception.getClass());
-    return this;
-  }
-
-  public UriValidator isIdText(final String text) {
-    assertEquals(text, uriInfo.getIdOption().getText());
-    return this;
-  }
-
-  public UriValidator isExpandText(final String text) {
-    assertEquals(text, uriInfo.getExpandOption().getText());
-    return this;
-  }
-
-  public UriValidator isSelectText(final String text) {
-    assertEquals(text, uriInfo.getSelectOption().getText());
-    return this;
-  }
-
-  public UriValidator isFormatText(final String text) {
-    assertEquals(text, uriInfo.getFormatOption().getText());
-    return this;
-  }
-
-  public UriValidator isFragmentText(final String text) {
-    if (uriInfo.getKind() != UriInfoKind.metadata) {
-      fail("invalid resource kind: " + uriInfo.getKind().toString());
-    }
-
-    assertEquals(text, uriInfo.getFragment());
-
-    return this;
-  }
-
-  public UriValidator isEntityType(final FullQualifiedName fullName) {
-    if (uriInfo.getKind() != UriInfoKind.entityId) {
-      fail("invalid resource kind: " + uriInfo.getKind().toString());
-    }
-
-    assertEquals(fullName.toString(), fullName(uriInfo.getEntityTypeCast()));
-    return this;
-  }
-
-  private String fullName(final EdmEntityType type) {
-    return type.getNamespace() + "." + type.getName();
-  }
-
-  public UriValidator isSelectItemStar(final int index) {
-    SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
-
-    SelectItem item = select.getSelectItems().get(index);
-    assertEquals(true, item.isStar());
-    return this;
-  }
-
-  public UriValidator isSelectItemAllOp(final int index, final 
FullQualifiedName fqn) {
-    SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
-
-    SelectItem item = select.getSelectItems().get(index);
-    assertEquals(fqn.toString(), 
item.getAllOperationsInSchemaNameSpace().toString());
-    return this;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/Validator.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/Validator.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/Validator.java
deleted file mode 100644
index caccc78..0000000
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/testutil/Validator.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.uri.testutil;
-
-public interface Validator {
-
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e02f098a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
index bc9d3e6..8d7380b 100644
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
@@ -30,6 +30,7 @@ import org.apache.olingo.server.core.testutil.EdmTechProvider;
 import org.apache.olingo.server.core.uri.parser.Parser;
 import org.apache.olingo.server.core.uri.parser.UriParserException;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class UriValidatorTest {
@@ -116,8 +117,8 @@ public class UriValidatorTest {
       { URI_PROPERTY_COMPLEX_COLLECTION, QO_SKIP }, { 
URI_PROPERTY_COMPLEX_COLLECTION, QO_SKIPTOKEN },
       { URI_PROPERTY_COMPLEX_COLLECTION, QO_LEVELS }, { 
URI_PROPERTY_COMPLEX_COLLECTION, QO_TOP },
 
-      { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_FILTER }, /*{ 
URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SEARCH }, */
-      
+      { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_FILTER }, /* { 
URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SEARCH }, */
+
       { URI_PROPERTY_PRIMITIVE, QO_FORMAT },
 
       { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_FILTER }, { 
URI_PROPERTY_PRIMITIVE_COLLECTION, QO_FORMAT },
@@ -263,6 +264,30 @@ public class UriValidatorTest {
     edm = new EdmProviderImpl(new EdmTechProvider());
   }
 
+  @Test
+  public void validateSelect() throws Exception {
+    String[] uris = { "/ESAllPrim(1)?$select=PropertyString" };
+    for (String uri : uris) {
+      parseAndValidate(uri);
+    }
+  }
+
+  @Test
+//  @Ignore("uri parser doen't support orderby yet")
+  public void validateOrderBy() throws Exception {
+    String[] uris = { "/ESAllPrim?$orderby=PropertyString" };
+    for (String uri : uris) {
+      parseAndValidate(uri);
+    }
+  }
+
+  @Test(expected = UriValidationException.class)
+  @Ignore("uri parser doen't support orderby yet")
+  public void validateOrderByInvalid() throws Exception {
+    String uri = "/ESAllPrim(1)?$orderBy=XXXX";
+    parseAndValidate(uri);
+  }
+
   @Test(expected = UriValidationException.class)
   public void validateKeyPredicatesWrongKey() throws Exception {
     String uri = "ESTwoKeyNav(xxx=1, yyy='abc')";
@@ -330,7 +355,7 @@ public class UriValidatorTest {
     UriInfo uriInfo = parser.parseUri(uri.trim(), edm);
     UriValidator validator = new UriValidator();
 
-    validator.validate(uriInfo, edm, "GET");
+    validator.validate(uriInfo, "GET");
   }
 
 }

Reply via email to