james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [06/18] james-project git commit: MAILBOX-266 Activate tests on custom flags, now supported in memory
Date Wed, 06 Apr 2016 09:21:50 GMT
MAILBOX-266 Activate tests on custom flags, now supported in memory


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/2730305c
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/2730305c
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/2730305c

Branch: refs/heads/master
Commit: 2730305cd90ad0bbdb43a163efd47aafdd2f2cfd
Parents: b446bff
Author: Benoit Tellier <btellier@linagora.com>
Authored: Mon Mar 28 14:39:55 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Apr 6 16:18:45 2016 +0700

----------------------------------------------------------------------
 .../elasticsearch/query/CriterionConverter.java        | 13 +++++++++----
 .../elasticsearch/ElasticSearchIntegrationTest.java    | 10 ++++------
 2 files changed, 13 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/2730305c/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
index 935c683..a523c3d 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/CriterionConverter.java
@@ -26,7 +26,6 @@ import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
 import static org.elasticsearch.index.query.QueryBuilders.nestedQuery;
 import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
 import static org.elasticsearch.index.query.QueryBuilders.termQuery;
-import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
 
 import java.util.Arrays;
 import java.util.HashMap;
@@ -66,6 +65,7 @@ public class CriterionConverter {
         registerCriterionConverter(SearchQuery.ConjunctionCriterion.class, this::convertConjunction);
         registerCriterionConverter(SearchQuery.HeaderCriterion.class, this::convertHeader);
         registerCriterionConverter(SearchQuery.TextCriterion.class, this::convertTextCriterion);
+        registerCriterionConverter(SearchQuery.CustomFlagCriterion.class, this::convertCustomFlagCriterion);
         
         registerCriterionConverter(SearchQuery.AllCriterion.class,
             criterion -> matchAllQuery());
@@ -75,9 +75,6 @@ public class CriterionConverter {
         
         registerCriterionConverter(SearchQuery.SizeCriterion.class,
             criterion -> createNumericFilter(JsonMessageConstants.SIZE, criterion.getOperator()));
-        
-        registerCriterionConverter(SearchQuery.CustomFlagCriterion.class,
-            criterion -> termsQuery(JsonMessageConstants.USER_FLAGS, criterion.getFlag()));
 
         registerCriterionConverter(SearchQuery.InternalDateCriterion.class,
             criterion -> dateRangeFilter(JsonMessageConstants.DATE, criterion.getOperator()));
@@ -118,6 +115,14 @@ public class CriterionConverter {
         return criterionConverterMap.get(criterion.getClass()).apply(criterion);
     }
 
+    private QueryBuilder convertCustomFlagCriterion(SearchQuery.CustomFlagCriterion criterion)
{
+        QueryBuilder termQueryBuilder = termQuery(JsonMessageConstants.USER_FLAGS, criterion.getFlag());
+        if (criterion.getOperator().isSet()) {
+            return termQueryBuilder;
+        } else {
+            return boolQuery().mustNot(termQueryBuilder);
+        }
+    }
 
     private QueryBuilder convertTextCriterion(SearchQuery.TextCriterion textCriterion) {
         switch (textCriterion.getType()) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/2730305c/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index 95b3f7f..832e4a6 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -32,6 +32,7 @@ import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
 import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex;
 import org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJson;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
 import org.apache.james.mailbox.elasticsearch.query.CriterionConverter;
 import org.apache.james.mailbox.elasticsearch.query.QueryConverter;
@@ -173,7 +174,7 @@ public class ElasticSearchIntegrationTest {
             new ElasticSearchIndexer(clientProvider, new DeleteByQueryPerformer(clientProvider,
Executors.newSingleThreadExecutor(), BATCH_SIZE)),
             new ElasticSearchSearcher<>(clientProvider, new QueryConverter(new CriterionConverter()),
SEARCH_SIZE),
             new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.of("Europe/Paris")));
-        storeMailboxManager = new StoreMailboxManager<>(
+        storeMailboxManager = new InMemoryMailboxManager(
             mapperFactory,
             new MockAuthenticator(),
             new JVMMailboxPathLocker(),
@@ -271,7 +272,6 @@ public class ElasticSearchIntegrationTest {
             .containsOnly(6L);
     }
 
-    @Ignore("This test will fail as Memory mailbox has no support for user defined flags.
This test will return two message instead of one => mapping issue")
     @Test
     public void flagIsSetShouldReturnUidsOfMessageContainingAGivenUserFlag() throws MailboxException
{
         SearchQuery searchQuery = new SearchQuery();
@@ -280,13 +280,12 @@ public class ElasticSearchIntegrationTest {
             .containsOnly(8L);
     }
 
-    @Ignore("This test will fail as Memory mailbox has no support for user defined flags.
This test will return two message instead of one => mapping issue")
     @Test
     public void userFlagsShouldBeMatchedExactly() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsSet("Hello bonjour"));
         assertThat(elasticSearchListeningMessageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(8L);
+            .isEmpty();
     }
 
     @Test
@@ -339,13 +338,12 @@ public class ElasticSearchIntegrationTest {
             .containsOnly(1L, 2L, 3L, 4L, 5L, 7L, 8L, 9L);
     }
 
-    @Ignore("This test will fail as Memory mailbox has no support for user defined flags.
This test will return two message instead of one => mapping issue")
     @Test
     public void flagIsUnSetShouldReturnUidsOfMessageNotContainingAGivenUserFlag() throws
MailboxException {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.flagIsUnSet("Hello"));
         assertThat(elasticSearchListeningMessageSearchIndex.search(session, mailbox, searchQuery))
-            .containsOnly(8L);
+            .containsOnly(1L, 2L, 3L, 4L, 5L, 6L, 7L,  9L);
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message