You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2015/11/28 06:30:30 UTC

[22/47] olingo-odata4 git commit: [OLINGO-568] Added search integration test

[OLINGO-568] Added search integration test


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

Branch: refs/heads/OLINGO-811_CountForExpand
Commit: 9ff30e729dffe392dca1dba70356580266e2aef6
Parents: 21e115b
Author: mibo <mi...@apache.org>
Authored: Tue Nov 17 06:21:35 2015 +0100
Committer: mibo <mi...@apache.org>
Committed: Tue Nov 17 06:30:23 2015 +0100

----------------------------------------------------------------------
 .../tecsvc/client/SystemQueryOptionITCase.java  | 42 +++++++++++++++-----
 .../queryoptions/options/SearchHandler.java     |  3 +-
 2 files changed, 35 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9ff30e72/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 4341a53..e605836 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
@@ -21,10 +21,11 @@ package org.apache.olingo.fit.tecsvc.client;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
+import java.io.IOException;
 import java.net.URI;
+import java.util.List;
 
 import org.apache.olingo.client.api.communication.ODataClientErrorException;
-import org.apache.olingo.client.api.communication.ODataServerErrorException;
 import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
 import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
 import org.apache.olingo.client.api.domain.ClientEntity;
@@ -301,18 +302,41 @@ public class SystemQueryOptionITCase extends AbstractParamTecSvcITCase {
   }
   
   @Test
-  public void negativeSearch() {
+  public void basicSearch() {
     ODataEntitySetRequest<ClientEntitySet> request = getClient().getRetrieveRequestFactory()
         .getEntitySetRequest(getClient().newURIBuilder(SERVICE_URI)
             .appendEntitySetSegment(ES_ALL_PRIM)
-            .search("ABC")
+            .search("Second")
             .build());
     setCookieHeader(request);
-    try {
-      request.execute();
-      fail();
-    } catch (ODataServerErrorException e) {
-      assertEquals("HTTP/1.1 501 Not Implemented", e.getMessage());
-    }
+    ODataRetrieveResponse<ClientEntitySet> response = request.execute();
+    List<ClientEntity> entities = response.getBody().getEntities();
+    assertEquals(1, entities.size());
+  }
+
+  @Test
+  public void andSearch() {
+    ODataEntitySetRequest<ClientEntitySet> request = getClient().getRetrieveRequestFactory()
+        .getEntitySetRequest(getClient().newURIBuilder(SERVICE_URI)
+            .appendEntitySetSegment(ES_ALL_PRIM)
+            .search("Second AND positive")
+            .build());
+    setCookieHeader(request);
+    ODataRetrieveResponse<ClientEntitySet> response = request.execute();
+    List<ClientEntity> entities = response.getBody().getEntities();
+    assertEquals(0, entities.size());
+  }
+
+  @Test
+  public void orSearch() {
+    ODataEntitySetRequest<ClientEntitySet> request = getClient().getRetrieveRequestFactory()
+        .getEntitySetRequest(getClient().newURIBuilder(SERVICE_URI)
+            .appendEntitySetSegment(ES_ALL_PRIM)
+            .search("Second OR positive")
+            .build());
+    setCookieHeader(request);
+    ODataRetrieveResponse<ClientEntitySet> response = request.execute();
+    List<ClientEntity> entities = response.getBody().getEntities();
+    assertEquals(2, entities.size());
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9ff30e72/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/SearchHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/SearchHandler.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/SearchHandler.java
index 5ce4530..e56e083 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/SearchHandler.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/options/SearchHandler.java
@@ -58,7 +58,8 @@ public class SearchHandler {
   }
 
   private static boolean isTrue(SearchTerm term, Property property) {
-    if(property.isPrimitive()) {
+    if(property.isPrimitive() && !property.isNull()) {
+      // TODO: mibo(151117): pass EDM information to do correct 'string' convertation
       String propertyString = property.asPrimitive().toString();
       return propertyString != null && propertyString.contains(term.getSearchTerm());
     }