Repository: olingo-odata4
Updated Branches:
  refs/heads/master 6f3565143 -> dacc31852


[OLINGO-568] Added tests and activated unicode tests


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

Branch: refs/heads/master
Commit: dacc318523a58b2f10c9f7d8e026352a62706601
Parents: 6f35651
Author: Michael Bolz <[email protected]>
Authored: Wed Dec 2 12:06:22 2015 +0100
Committer: Michael Bolz <[email protected]>
Committed: Wed Dec 2 12:06:22 2015 +0100

----------------------------------------------------------------------
 .../tecsvc/client/SystemQueryOptionITCase.java  | 16 +++-
 .../search/SearchParserAndTokenizerTest.java    | 87 ++++++++++++++++++++
 .../uri/parser/search/SearchTokenizerTest.java  | 43 ----------
 .../core/uri/antlr/TestFullResourcePath.java    | 85 +++++++++++++++++++
 4 files changed, 185 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dacc3185/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java
 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java
index 7ffa8a9..3d0df10 100644
--- 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java
+++ 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/SystemQueryOptionITCase.java
@@ -311,11 +311,23 @@ public class SystemQueryOptionITCase extends 
AbstractParamTecSvcITCase {
             .build());
     setCookieHeader(request);
     final ODataRetrieveResponse<ClientEntitySet> response = request.execute();
-    saveCookieHeader(response);
     assertEquals(1, response.getBody().getEntities().size());
   }
 
   @Test
+  public void basicSearchPhrase() {
+    ODataEntitySetRequest<ClientEntitySet> request = 
getClient().getRetrieveRequestFactory()
+        .getEntitySetRequest(getClient().newURIBuilder(SERVICE_URI)
+            .appendEntitySetSegment(ES_ALL_PRIM)
+            .search("\"This is a \\\"$imple\\\"\\\\Phras~\" AND "
+                + 
"AnUnicodeWordLl\u01E3Lm\u02B5Lo\u1BE4Lt\u01F2Lu\u03D3Nl\u216F")
+            .build());
+    setCookieHeader(request);
+    final ODataRetrieveResponse<ClientEntitySet> response = request.execute();
+    assertTrue(response.getBody().getEntities().isEmpty());
+  }
+
+  @Test
   public void andSearch() {
     ODataEntitySetRequest<ClientEntitySet> request = 
getClient().getRetrieveRequestFactory()
         .getEntitySetRequest(getClient().newURIBuilder(SERVICE_URI)
@@ -324,7 +336,6 @@ public class SystemQueryOptionITCase extends 
AbstractParamTecSvcITCase {
             .build());
     setCookieHeader(request);
     final ODataRetrieveResponse<ClientEntitySet> response = request.execute();
-    saveCookieHeader(response);
     assertTrue(response.getBody().getEntities().isEmpty());
   }
 
@@ -337,7 +348,6 @@ public class SystemQueryOptionITCase extends 
AbstractParamTecSvcITCase {
             .build());
     setCookieHeader(request);
     ODataRetrieveResponse<ClientEntitySet> response = request.execute();
-    saveCookieHeader(response);
     assertEquals(2, response.getBody().getEntities().size());
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dacc3185/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserAndTokenizerTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserAndTokenizerTest.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserAndTokenizerTest.java
index b341b0e..e028cfe 100644
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserAndTokenizerTest.java
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserAndTokenizerTest.java
@@ -108,6 +108,93 @@ public class SearchParserAndTokenizerTest {
     assertQuery("NOT 
(a)").resultsIn(SearchParserException.MessageKeys.TOKENIZER_EXCEPTION);
   }
 
+  /**
+   * Test all test cases from:
+   * 
https://tools.oasis-open.org/version-control/browse/wsvn/odata/trunk/spec/ABNF/odata-abnf-testcases.xml
+   *
+   * However the parser prerequisites that the search query is already percent 
decoded.
+   * Hence all "%xx" values are replaced by their decoded value.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void searchQueryPhraseAbnfTestcases() throws Exception {
+    //    <TestCase Name="5.1.7 Search - simple phrase" Rule="queryOptions">
+    assertQuery("\"blue green\"").resultsIn("'blue green'");
+    //    <TestCase Name="5.1.7 Search - simple phrase" Rule="queryOptions">
+    assertQuery("\"blue green\"").resultsIn("'blue green'");
+    //    <TestCase Name="5.1.7 Search - phrase with escaped double-quote" 
Rule="queryOptions">
+    //    <Input>$search="blue\"green"</Input>
+    assertQuery("\"blue\\\"green\"").resultsIn("'blue\"green'");
+
+    //    <TestCase Name="5.1.7 Search - phrase with escaped backslash" 
Rule="queryOptions">
+    //    <Input>$search="blue\\green"</Input>
+    assertQuery("\"blue\\\\green\"").resultsIn("'blue\\green'");
+    //    <TestCase Name="5.1.7 Search - phrase with unescaped double-quote" 
Rule="queryOptions" FailAt="14">
+    
assertQuery("\"blue\"green\"").resultsIn(SearchParserException.MessageKeys.TOKENIZER_EXCEPTION);
+    //    <TestCase Name="5.1.7 Search - phrase with unescaped double-quote" 
Rule="queryOptions" FailAt="16">
+    
assertQuery("\"blue\"green\"").resultsIn(SearchParserException.MessageKeys.TOKENIZER_EXCEPTION);
+
+    //    <TestCase Name="5.1.7 Search - implicit AND" Rule="queryOptions">
+    //    <Input>$search=blue green</Input>
+    assertQuery("blue green").resultsIn("{'blue' AND 'green'}");
+    //    <TestCase Name="5.1.7 Search - implicit AND, encoced" 
Rule="queryOptions">
+    assertQuery("blue green").resultsIn("{'blue' AND 'green'}");
+
+    //    <TestCase Name="5.1.7 Search - AND" Rule="queryOptions">
+    //    <Input>$search=blue AND green</Input>
+    assertQuery("blue AND green").resultsIn("{'blue' AND 'green'}");
+
+    //    <TestCase Name="5.1.7 Search - OR" Rule="queryOptions">
+    //    <Input>$search=blue OR green</Input>
+    assertQuery("blue OR green").resultsIn("{'blue' OR 'green'}");
+
+    //    <TestCase Name="5.1.7 Search - NOT" Rule="queryOptions">
+    //    <Input>$search=blue NOT green</Input>
+    assertQuery("blue NOT green").resultsIn("{'blue' AND {NOT 'green'}}");
+
+    //    <TestCase Name="5.1.7 Search - only NOT" Rule="queryOptions">
+    //    <Input>$search=NOT blue</Input>
+    assertQuery("NOT blue").resultsIn("{NOT 'blue'}");
+
+    //    <TestCase Name="5.1.7 Search - multiple" Rule="queryOptions">
+    //    <Input>$search=foo AND bar OR foo AND baz OR that AND bar OR that 
AND baz</Input>
+    assertQuery("foo AND bar OR foo AND baz OR that AND bar OR that AND baz")
+        .resultsIn("{{{{'foo' AND 'bar'} OR {'foo' AND 'baz'}} OR {'that' AND 
'bar'}} OR {'that' AND 'baz'}}");
+
+    //    <TestCase Name="5.1.7 Search - multiple" Rule="queryOptions">
+    //    <Input>$search=(foo OR that) AND (bar OR baz)</Input>
+    assertQuery("(foo OR that) AND (bar OR baz)").resultsIn("{{'foo' OR 
'that'} AND {'bar' OR 'baz'}}");
+
+    //    <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions">
+    //    <Input>$search=foo AND (bar OR baz)</Input>
+    assertQuery("foo AND (bar OR baz)").resultsIn("{'foo' AND {'bar' OR 
'baz'}}");
+
+    //    <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions">
+    //    <Input>$search=(foo AND bar) OR baz</Input>
+    assertQuery("(foo AND bar) OR baz").resultsIn("{{'foo' AND 'bar'} OR 
'baz'}");
+
+    //    <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions">
+    //    <Input>$search=(NOT foo) OR baz</Input>
+    assertQuery("(NOT foo) OR baz").resultsIn("{{NOT 'foo'} OR 'baz'}");
+
+    //    <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions">
+    //    <Input>$search=(NOT foo)</Input>
+    assertQuery("(NOT foo)").resultsIn("{NOT 'foo'}");
+
+    //    <TestCase Name="5.1.7 Search - on entity set" Rule="odataUri">
+    //    <Input>http://serviceRoot/Products?$search=blue</Input>
+    assertQuery("blue").resultsIn("'blue'");
+
+
+    // below cases can not be tested here
+    //    <TestCase Name="5.1.7 Search - on entity container" Rule="odataUri">
+    //    <Input>http://serviceRoot/Model.Container/$all?$search=blue</Input>
+    //    <TestCase Name="5.1.7 Search - on service" Rule="odataUri">
+    //    <Input>http://serviceRoot/$all?$search=blue</Input>
+  }
+
+
   private static Validator assertQuery(String searchQuery) {
     return Validator.init(searchQuery);
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dacc3185/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
index 61cd28b..66e784b 100644
--- 
a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
+++ 
b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java
@@ -92,40 +92,7 @@ public class SearchTokenizerTest {
     assertQuery("abc or \"xyz\"").resultsIn(WORD, WORD, PHRASE);
   }
 
-  /**
-   * 
https://tools.oasis-open.org/version-control/browse/wsvn/odata/trunk/spec/ABNF/odata-abnf-testcases.xml
-   * @throws Exception
-   */
   @Test
-  @Ignore("Test must be moved to SearchParserTest and 
SearchParserAndTokenizerTest")
-  public void parsePhraseAbnfTestcases() throws Exception {
-    //    <TestCase Name="5.1.7 Search - simple phrase" Rule="queryOptions">
-    assertQuery("\"blue%20green\"");
-    //    <TestCase Name="5.1.7 Search - simple phrase" Rule="queryOptions">
-    assertQuery("\"blue%20green%22");
-    //    <TestCase Name="5.1.7 Search - phrase with escaped double-quote" 
Rule="queryOptions">
-    //    <Input>$search="blue\"green"</Input>
-    assertQuery("\"blue\\\"green\"");
-
-    //    <TestCase Name="5.1.7 Search - phrase with escaped backslash" 
Rule="queryOptions">
-    //    <Input>$search="blue\\green"</Input>
-    assertQuery("\"blue\\\\green\"");
-
-    //    <TestCase Name="5.1.7 Search - phrase with unescaped double-quote" 
Rule="queryOptions" FailAt="14">
-    assertQuery("\"blue\"green\"");
-
-    //    <TestCase Name="5.1.7 Search - phrase with unescaped double-quote" 
Rule="queryOptions" FailAt="16">
-    assertQuery("\"blue%22green\"");
-
-//    <TestCase Name="5.1.7 Search - implicit AND" Rule="queryOptions">
-//    <Input>$search=blue green</Input>
-//    SearchassertQuery("\"blue%20green\"").resultsIn();
-    //    <TestCase Name="5.1.7 Search - implicit AND, encoced" 
Rule="queryOptions">
-//    SearchassertQuery("blue%20green").resultsIn();
-  }
-
-
-    @Test
   public void parseNot() throws Exception {
     assertQuery("NOT").resultsIn(NOT);
     assertQuery(" NOT ").resultsIn(NOT);
@@ -221,7 +188,6 @@ public class SearchTokenizerTest {
     assertQuery("abc OR ORsomething").resultsIn(WORD, OR, WORD);
   }
 
-  @Ignore
   @Test
   public void unicodeInWords() throws Exception {
     // Ll, Lm, Lo, Lt, Lu, Nl
@@ -392,15 +358,6 @@ public class SearchTokenizerTest {
       }
       return this;
     }
-//    private void resultsIn(Class<? extends Exception> exception) throws 
SearchTokenizerException {
-//      try {
-//        validate();
-//      } catch (Exception e) {
-//        Assert.assertEquals(exception, e.getClass());
-//        return;
-//      }
-//      Assert.fail("Expected exception " + 
exception.getClass().getSimpleName() + " was not thrown.");
-//    }
 
     private void resultsIn(SearchTokenizerException.MessageKey key)
         throws SearchTokenizerException {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/dacc3185/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 27fa2c1..379345e 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
@@ -5482,6 +5482,91 @@ public class TestFullResourcePath {
         
.isExceptionMessage(SearchParserException.MessageKeys.TOKENIZER_EXCEPTION);
   }
 
+  /**
+   * 
https://tools.oasis-open.org/version-control/browse/wsvn/odata/trunk/spec/ABNF/odata-abnf-testcases.xml
+   * @throws Exception
+   */
+  @Test
+  public void searchQueryPhraseAbnfTestcases() throws Exception {
+    //    <TestCase Name="5.1.7 Search - simple phrase" Rule="queryOptions">
+    testUri.run("ESTwoKeyNav", "$search=\"blue%20green\"");
+    //    <TestCase Name="5.1.7 Search - simple phrase" Rule="queryOptions">
+    testUri.run("ESTwoKeyNav", "$search=\"blue%20green%22");
+    //    <TestCase Name="5.1.7 Search - phrase with escaped double-quote" 
Rule="queryOptions">
+    //    <Input>$search="blue\"green"</Input>
+    testUri.run("ESTwoKeyNav", "$search=\"blue\\\"green\"");
+
+    //    <TestCase Name="5.1.7 Search - phrase with escaped backslash" 
Rule="queryOptions">
+    //    <Input>$search="blue\\green"</Input>
+    testUri.run("ESTwoKeyNav", "$search=\"blue\\\\green\"");
+    //    <TestCase Name="5.1.7 Search - phrase with unescaped double-quote" 
Rule="queryOptions" FailAt="14">
+    testUri.runEx("ESTwoKeyNav", "$search=\"blue\"green\"")
+            
.isExceptionMessage(SearchParserException.MessageKeys.TOKENIZER_EXCEPTION);
+    //    <TestCase Name="5.1.7 Search - phrase with unescaped double-quote" 
Rule="queryOptions" FailAt="16">
+    testUri.runEx("ESTwoKeyNav", "$search=\"blue%22green\"")
+            
.isExceptionMessage(SearchParserException.MessageKeys.TOKENIZER_EXCEPTION);
+
+    //    <TestCase Name="5.1.7 Search - implicit AND" Rule="queryOptions">
+    //    <Input>$search=blue green</Input>
+    //    SearchassertQuery("\"blue%20green\"").resultsIn();
+    testUri.run("ESTwoKeyNav", "$search=blue green");
+    //    <TestCase Name="5.1.7 Search - implicit AND, encoced" 
Rule="queryOptions">
+    //    SearchassertQuery("blue%20green").resultsIn();
+    testUri.run("ESTwoKeyNav", "$search=blue%20green");
+
+    //    <TestCase Name="5.1.7 Search - AND" Rule="queryOptions">
+    //    <Input>$search=blue AND green</Input>
+    testUri.run("ESTwoKeyNav", "$search=blue AND green");
+
+    //    <TestCase Name="5.1.7 Search - OR" Rule="queryOptions">
+    //    <Input>$search=blue OR green</Input>
+    testUri.run("ESTwoKeyNav", "$search=blue OR green");
+
+    //    <TestCase Name="5.1.7 Search - NOT" Rule="queryOptions">
+    //    <Input>$search=blue NOT green</Input>
+    testUri.run("ESTwoKeyNav", "$search=blue NOT green");
+
+    //    <TestCase Name="5.1.7 Search - only NOT" Rule="queryOptions">
+    //    <Input>$search=NOT blue</Input>
+    testUri.run("ESTwoKeyNav", "$search=NOT blue");
+
+    //    <TestCase Name="5.1.7 Search - multiple" Rule="queryOptions">
+    //    <Input>$search=foo AND bar OR foo AND baz OR that AND bar OR that 
AND baz</Input>
+    testUri.run("ESTwoKeyNav", "$search=foo AND bar OR foo AND baz OR that AND 
bar OR that AND baz");
+
+    //    <TestCase Name="5.1.7 Search - multiple" Rule="queryOptions">
+    //    <Input>$search=(foo OR that) AND (bar OR baz)</Input>
+    testUri.run("ESTwoKeyNav", "$search=(foo OR that) AND (bar OR baz)");
+
+    //    <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions">
+    //    <Input>$search=foo AND (bar OR baz)</Input>
+    testUri.run("ESTwoKeyNav", "$search=foo AND (bar OR baz)");
+
+    //    <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions">
+    //    <Input>$search=(foo AND bar) OR baz</Input>
+    testUri.run("ESTwoKeyNav", "$search=(foo AND bar) OR baz");
+
+    //    <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions">
+    //    <Input>$search=(NOT foo) OR baz</Input>
+    testUri.run("ESTwoKeyNav", "$search=(NOT foo) OR baz");
+
+    //    <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions">
+    //    <Input>$search=(NOT foo)</Input>
+    testUri.run("ESTwoKeyNav", "$search=(NOT foo)");
+
+    //    <TestCase Name="5.1.7 Search - on entity set" Rule="odataUri">
+    //    <Input>http://serviceRoot/Products?$search=blue</Input>
+    testUri.run("ESTwoKeyNav", "$search=blue");
+
+    //    <TestCase Name="5.1.7 Search - on entity container" Rule="odataUri">
+    //    <Input>http://serviceRoot/Model.Container/$all?$search=blue</Input>
+    testUri.run("$all", "$search=blue");
+
+    //    <TestCase Name="5.1.7 Search - on service" Rule="odataUri">
+    //    <Input>http://serviceRoot/$all?$search=blue</Input>
+    testUri.run("$all", "$search=blue");
+  }
+
   @Test
   public void testErrors() {
     
testUri.runEx("FICRTString(wrong1='ABC')/olingo.odata.test1.BFCStringRTESTwoKeyNav()")

Reply via email to