[SYNCOPE-1419] Adding integration test, also verified with Elasticsearch
authorFrancesco Chicchiriccò <ilgrosso@apache.org>
Fri, 21 Dec 2018 07:51:10 +0000 (08:51 +0100)
committerFrancesco Chicchiriccò <ilgrosso@apache.org>
Fri, 21 Dec 2018 07:51:10 +0000 (08:51 +0100)
core/persistence-jpa-json/src/main/java/org/apache/syncope/core/persistence/jpa/dao/PGJPAJSONAnySearchDAO.java
core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java
core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AnySearchTest.java
fit/core-reference/src/test/java/org/apache/syncope/fit/core/SearchITCase.java

index 884a40b..dd34269 100644 (file)
@@ -158,10 +158,10 @@ public class PGJPAJSONAnySearchDAO extends JPAAnySearchDAO {
             final SearchSupport svs) {
 
         // This first branch is required for handling with not conditions given on multivalue fields (SYNCOPE-1419)
-        if (not && !(cond instanceof AnyCond)
-                && schema.isMultivalue()
-                && cond.getType() != AttributeCond.Type.ISNULL
-                && cond.getType() != AttributeCond.Type.ISNOTNULL) {
+        if (not && schema.isMultivalue()
+                && !(cond instanceof AnyCond)
+                && cond.getType() != AttributeCond.Type.ISNULL && cond.getType() != AttributeCond.Type.ISNOTNULL) {
+
             query.append("id NOT IN (SELECT DISTINCT any_id FROM ");
             query.append(svs.field().name).append(" WHERE ");
             fillAttrQuery(anyUtils, query, attrValue, schema, cond, false, parameters, svs);
@@ -280,7 +280,7 @@ public class PGJPAJSONAnySearchDAO extends JPAAnySearchDAO {
             }
         }
 
-        StringBuilder query = 
+        StringBuilder query =
                 new StringBuilder("SELECT DISTINCT any_id FROM ").append(svs.field().name).append(" WHERE ");
         switch (cond.getType()) {
             case ISNOTNULL:
index 81c0376..def529c 100644 (file)
@@ -834,11 +834,12 @@ public class JPAAnySearchDAO extends AbstractAnySearchDAO {
             final boolean not,
             final List<Object> parameters,
             final SearchSupport svs) {
+
         // This first branch is required for handling with not conditions given on multivalue fields (SYNCOPE-1419)
-        if (not && !(cond instanceof AnyCond)
-                && schema.isMultivalue()
-                && cond.getType() != AttributeCond.Type.ISNULL
-                && cond.getType() != AttributeCond.Type.ISNOTNULL) {
+        if (not && schema.isMultivalue()
+                && !(cond instanceof AnyCond)
+                && cond.getType() != AttributeCond.Type.ISNULL && cond.getType() != AttributeCond.Type.ISNOTNULL) {
+
             query.append("any_id NOT IN (SELECT DISTINCT any_id FROM ");
             if (schema.isUniqueConstraint()) {
                 query.append(svs.asSearchViewSupport().uniqueAttr().name);
index 8d8ea69..1dae5c1 100644 (file)
@@ -747,15 +747,15 @@ public class AnySearchTest extends AbstractTest {
                 AnyTypeKind.USER);
         assertFalse(users.isEmpty());
     }
-    
+
     @Test
     public void issueSYNCOPE1416() {
         AttributeCond idLeftCond = new AttributeCond(AttributeCond.Type.ISNOTNULL);
         idLeftCond.setSchema("surname");
-        
+
         AttributeCond idRightCond = new AttributeCond(AttributeCond.Type.ISNOTNULL);
         idRightCond.setSchema("firstname");
-        
+
         SearchCond searchCondition = SearchCond.getAndCond(
                 SearchCond.getLeafCond(idLeftCond), SearchCond.getLeafCond(idRightCond));
 
index a49fc5e..fa7c5ac 100644 (file)
@@ -290,7 +290,7 @@ public class SearchITCase extends AbstractITCase {
                         and("username").equalTo("bellini").query()).
                 build());
         assertEquals(users, issueSYNCOPE1321);
-        
+
         // SYNCOPE-1416 (check the search for attributes of type different from stringvalue)
         PagedResult<UserTO> issueSYNCOPE1416 = userService.search(new AnyQuery.Builder().
                 realm(SyncopeConstants.ROOT_REALM).
@@ -570,4 +570,24 @@ public class SearchITCase extends AbstractITCase {
             assertEquals(ClientExceptionType.InvalidSearchExpression, e.getType());
         }
     }
+
+    @Test
+    public void issueSYNCOPE1419() {
+        PagedResult<UserTO> total = userService.search(
+                new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).page(1).size(1).build());
+
+        PagedResult<UserTO> matching = userService.search(
+                new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
+                        fiql(SyncopeClient.getUserSearchConditionBuilder().
+                                is("loginDate").equalTo("2009-05-26").query()).page(1).size(1).build());
+        assertTrue(matching.getSize() > 0);
+
+        PagedResult<UserTO> unmatching = userService.search(
+                new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
+                        fiql(SyncopeClient.getUserSearchConditionBuilder().
+                                is("loginDate").notEqualTo("2009-05-26").query()).page(1).size(1).build());
+        assertTrue(unmatching.getSize() > 0);
+
+        assertEquals(total.getTotalCount(), matching.getTotalCount() + unmatching.getTotalCount());;
+    }
 }