olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sklev...@apache.org
Subject [01/21] git commit: [OLINGO-206] TDD setup for URI Validator
Date Fri, 04 Apr 2014 05:50:55 GMT
Repository: olingo-odata4
Updated Branches:
  refs/heads/master 8a0d51977 -> 7dae5ef33


[OLINGO-206] TDD setup for URI Validator


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

Branch: refs/heads/master
Commit: df675e15af95bc82a15ed4982bf02c0d4614a625
Parents: ec39fd6
Author: Stephan Klevenz <stephan.klevenz@sap.com>
Authored: Fri Mar 14 15:56:13 2014 +0100
Committer: Stephan Klevenz <stephan.klevenz@sap.com>
Committed: Fri Mar 14 15:56:13 2014 +0100

----------------------------------------------------------------------
 .../uri/validator/UriValidationException.java   |  25 ++++
 .../server/core/uri/validator/Validator.java    |  37 ++++++
 .../core/uri/validator/UriEdmValidatorTest.java | 130 +++++++++++++++++++
 3 files changed, 192 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/df675e15/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidationException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidationException.java
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidationException.java
new file mode 100644
index 0000000..d0f4b8c
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidationException.java
@@ -0,0 +1,25 @@
+/*
+ * 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.validator;
+
+public class UriValidationException extends Exception {
+
+  private static final long serialVersionUID = -3179078078053564742L;
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/df675e15/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/Validator.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/Validator.java
b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/Validator.java
new file mode 100644
index 0000000..0442563
--- /dev/null
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/Validator.java
@@ -0,0 +1,37 @@
+/*
+ * 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.validator;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.server.api.uri.UriInfo;
+
+public class Validator {
+
+  public void validate(UriInfo uriInfo, Edm edm) throws UriValidationException {
+    switch (uriInfo.getKind()) {
+    case metadata:
+      if (uriInfo.getTopOption() != null) {
+        throw new UriValidationException();
+      }
+      break;
+      default:
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/df675e15/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriEdmValidatorTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriEdmValidatorTest.java
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriEdmValidatorTest.java
new file mode 100644
index 0000000..106b4ce
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/validator/UriEdmValidatorTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.validator;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.*;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
+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.RawUri;
+import org.apache.olingo.server.core.uri.parser.UriDecoder;
+import org.apache.olingo.server.core.uri.parser.UriParserException;
+import org.junit.Test;
+
+public class UriEdmValidatorTest {
+
+  private Edm edm = new EdmProviderImpl(new EdmTechProvider());
+
+  String[] uris = {
+      "$crossjoin(ESKeyNav, ESTwoKeyNav)/invalid                                        
                           ",
+      "$crossjoin(invalidEntitySet)                                                     
                           ",
+      "$entity                                                                          
                           ",
+      "$entity?$idfalse=ESKeyNav(1)                                                     
                           ",
+      "ESAllPrim(PropertyInt16='1')                                                     
                           ",
+      "ESCollAllPrim(null)                                                              
                           ",
+      "ESTwoPrim(1)/com.sap.odata.test1.ETBase(1)                                       
                           ",
+      "ESTwoPrim/com.sap.odata.test1.ETBase(1)/com.sap.odata.test1.ETTwoBase(1)         
                           ",
+      "ESTwoPrim/com.sap.odata.test1.ETBase(1)/com.sap.odata.test1.ETTwoBase(1)         
                           ",
+      "FICRTCollCTTwoPrimParam(ParameterInt16='1',ParameterString='2')                  
                           ",
+      "FICRTESTwoKeyNavParam(ParameterInt16=@invalidAlias)?@validAlias=1                
                           ",
+      "FINRTESMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='2')/PropertyComplex
                        ",
+      "FINRTESMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='2')/$count      
                           ",
+      "ESKeyNav(1)?$expand=NavPropertyETKeyNavOne/$ref                                  
                           ",
+      "ESKeyNav(1)?$expand=NavPropertyETKeyNavOne/$count                                
                           ",
+      "ESKeyNav?$top=-3                                                                 
                           ",
+      "ESAllPrim?$count=foo                                                             
                           ",
+      "ESAllPrim?$skip=-3                                                               
                           "
+  };
+
+  @Test
+  public void foo() throws Exception {
+    for (String uri : uris) {
+      Parser parser = new Parser();
+      System.out.println(uri);
+      UriInfo uriInfo = parser.parseUri(uri.trim(), edm);
+      assertNotNull(uriInfo);
+    }
+  }
+
+  @Test
+  public void keyPredicateValidTypes() throws Exception {
+    String[] uris = { "/ESAllPrim" };
+
+    for (String uri : uris) {
+      parseAndValidate(uri);
+    }
+
+  }
+
+  @Test
+  public void keyPredicateInvalidTypes() throws UriParserException {
+    String[] uris = {};
+
+    for (String uri : uris) {
+
+      try {
+        parseAndValidate(uri);
+        fail("Validation Exception not thrown: " + uri);
+      } catch (UriValidationException e) {
+        assertTrue(e instanceof UriValidationException);
+      }
+    }
+  }
+
+  @Test
+  public void systemQueryOptionValid() throws Exception {
+    String[] uris = {
+        "/$metadata",
+        "/$metadata?$format=json"
+    };
+
+    for (String uri : uris) {
+      parseAndValidate(uri);
+    }
+
+  }
+
+  @Test
+  public void systemQueryOptionInvalid() throws Exception {
+    String[] uris = {
+        "/$metadata?$format=json&$top=3"
+    };
+
+    for (String uri : uris) {
+
+      try {
+        parseAndValidate(uri);
+        fail("Validation Exception not thrown: " + uri);
+      } catch (UriValidationException e) {
+        assertTrue(e instanceof UriValidationException);
+      }
+    }
+  }
+
+  private void parseAndValidate(String uri) throws UriParserException, UriValidationException
{
+    UriInfo uriInfo = new Parser().parseUri(uri.trim(), edm);
+    Validator validator = new Validator();
+    validator.validate(uriInfo, edm);
+  }
+}


Mime
View raw message