james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [12/18] james-project git commit: MAILBOX-266 Improve code coverage
Date Wed, 06 Apr 2016 09:21:56 GMT
MAILBOX-266 Improve code coverage


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

Branch: refs/heads/master
Commit: 0ea8bc6996fc81d9464c4adc334856d46c0ec1a4
Parents: aea76c8
Author: Benoit Tellier <btellier@linagora.com>
Authored: Mon Mar 28 16:41:11 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Apr 6 16:18:45 2016 +0700

----------------------------------------------------------------------
 .../elasticsearch/IndexCreationFactory.java     |  8 +---
 .../ElasticSearchIntegrationTest.java           | 44 ++++++++++++++++++++
 .../query/DateResolutionFormaterTest.java       |  9 ++++
 .../src/test/resources/documents/frnog.eml      |  2 +
 .../src/test/resources/documents/mail4.eml      |  2 +
 5 files changed, 58 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0ea8bc69/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/IndexCreationFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/IndexCreationFactory.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/IndexCreationFactory.java
index fdbfeac..71a6c11 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/IndexCreationFactory.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/IndexCreationFactory.java
@@ -20,7 +20,6 @@
 package org.apache.james.mailbox.elasticsearch;
 
 import java.io.IOException;
-import java.util.Optional;
 
 import org.elasticsearch.client.Client;
 import org.elasticsearch.common.settings.Settings;
@@ -44,12 +43,7 @@ public class IndexCreationFactory {
     }
 
     public static ClientProvider createIndex(ClientProvider clientProvider) {
-        try {
-            return createIndex(clientProvider, generateSetting(DEFAULT_NB_SHARDS, DEFAULT_NB_REPLICA));
-        } catch (IOException e) {
-            LOGGER.error("Error while creating index : ", e);
-            return clientProvider;
-        }
+        return createIndex(clientProvider, DEFAULT_NB_SHARDS, DEFAULT_NB_REPLICA);
     }
 
     private static ClientProvider createIndex(ClientProvider clientProvider, Settings settings)
{

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ea8bc69/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 9b90b72..95b3f7f 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
@@ -184,6 +184,13 @@ public class ElasticSearchIntegrationTest {
     }
 
     @Test
+    public void emptySearchQueryShouldReturnAllUids() throws MailboxException {
+        SearchQuery searchQuery = new SearchQuery();
+        assertThat(elasticSearchListeningMessageSearchIndex.search(session, mailbox, searchQuery))
+            .containsOnly(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L);
+    }
+
+    @Test
     public void allShouldReturnAllUids() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.all());
@@ -443,6 +450,22 @@ public class ElasticSearchIntegrationTest {
     }
 
     @Test
+    public void addressShouldReturnUidHavingRightRecipientWhenCcIsSpecified() throws Exception
{
+        SearchQuery searchQuery = new SearchQuery();
+        searchQuery.andCriteria(SearchQuery.address(SearchQuery.AddressType.Cc, "any@any.com"));
+        assertThat(elasticSearchListeningMessageSearchIndex.search(session, mailbox, searchQuery))
+            .containsOnly(5L);
+    }
+
+    @Test
+    public void addressShouldReturnUidHavingRightRecipientWhenBccIsSpecified() throws Exception
{
+        SearchQuery searchQuery = new SearchQuery();
+        searchQuery.andCriteria(SearchQuery.address(SearchQuery.AddressType.Bcc, "no@no.com"));
+        assertThat(elasticSearchListeningMessageSearchIndex.search(session, mailbox, searchQuery))
+            .containsOnly(9L);
+    }
+
+    @Test
     public void uidShouldreturnExistingUidsOnTheGivenRanges() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
         SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 4L),
new SearchQuery.NumericRange(6L, 7L)};
@@ -452,6 +475,15 @@ public class ElasticSearchIntegrationTest {
     }
 
     @Test
+    public void uidShouldreturnEveryThing() throws Exception {
+        SearchQuery searchQuery = new SearchQuery();
+        SearchQuery.NumericRange[] numericRanges = {};
+        searchQuery.andCriteria(SearchQuery.uid(numericRanges));
+        assertThat(elasticSearchListeningMessageSearchIndex.search(session, mailbox, searchQuery))
+            .containsOnly(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L);
+    }
+
+    @Test
     public void youShouldBeAbleToSpecifySeveralCriterionOnASingleQuery() throws Exception
{
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.headerExists("Precedence"));
@@ -472,6 +504,18 @@ public class ElasticSearchIntegrationTest {
     }
 
     @Test
+    public void orShouldReturnResultsMatchinganyRequests() throws Exception {
+        SearchQuery.NumericRange[] numericRanges = {new SearchQuery.NumericRange(2L, 4L)};
+        SearchQuery searchQuery = new SearchQuery();
+        searchQuery.andCriteria(
+            SearchQuery.or(
+                SearchQuery.uid(numericRanges),
+                SearchQuery.modSeqGreaterThan(6L)));
+        assertThat(elasticSearchListeningMessageSearchIndex.search(session, mailbox, searchQuery))
+            .containsOnly(2L, 3L, 4L, 6L, 7L, 8L, 9L);
+    }
+
+    @Test
     public void notShouldReturnResultsThatDoNotMatchAQuery() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ea8bc69/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java
index c82a050..fed35c1 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/query/DateResolutionFormaterTest.java
@@ -43,6 +43,15 @@ public class DateResolutionFormaterTest {
     }
 
     @Test
+    public void calculateUpperDateShouldReturnDateUpToTheNextHourUsingHourUnit() throws ParseException
{
+        assertThat(
+            ISO_OFFSET_DATE_TIME.format(
+                DateResolutionFormater.computeUpperDate(ZonedDateTime.parse(dateString, ISO_OFFSET_DATE_TIME),
SearchQuery.DateResolution.Hour)
+            )
+        ).isEqualTo("2014-01-02T16:00:00Z");
+    }
+
+    @Test
     public void calculateUpperDateShouldReturnDateUpToTheNextDayUsingDayUnit() throws ParseException
{
         assertThat(
             ISO_OFFSET_DATE_TIME.format(

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ea8bc69/mailbox/elasticsearch/src/test/resources/documents/frnog.eml
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/resources/documents/frnog.eml b/mailbox/elasticsearch/src/test/resources/documents/frnog.eml
index a12c1ce..505fbde 100644
--- a/mailbox/elasticsearch/src/test/resources/documents/frnog.eml
+++ b/mailbox/elasticsearch/src/test/resources/documents/frnog.eml
@@ -39,6 +39,8 @@ From: Guillaume Genty <ggenty@waycom.net>
 Organization: Waycom
 MIME-Version: 1.0
 To: <frnog@frnog.org>
+Cc: no@no.com
+Bcc: no@no.com
 Content-Type: text/plain; charset="utf-8"; format=flowed
 Content-Transfer-Encoding: 8bit
 X-ClientProxiedBy: WCM-HV1-EXCH1.wcmnoc.local (2002:c3d6:f04a::c3d6:f04a) To

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ea8bc69/mailbox/elasticsearch/src/test/resources/documents/mail4.eml
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/resources/documents/mail4.eml b/mailbox/elasticsearch/src/test/resources/documents/mail4.eml
index b01da38..584b24c 100644
--- a/mailbox/elasticsearch/src/test/resources/documents/mail4.eml
+++ b/mailbox/elasticsearch/src/test/resources/documents/mail4.eml
@@ -37,6 +37,8 @@ Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28)
 Date: Fri, 15 May 2015 06:35:59 +0000 (UTC)
 From: "Eric Charles (JIRA)" <mailet-api@james.apache.org>
 To: mailet-api@james.apache.org
+Cc: any@any.com
+Bcc: any@any.com
 Message-ID: <JIRA.12825882.1430301328000.124152.1431671759942@Atlassian.JIRA>
 In-Reply-To: <JIRA.12825882.1430301328000@Atlassian.JIRA>
 References: <JIRA.12825882.1430301328000@Atlassian.JIRA> <JIRA.12825882.1430301328925@arcas>


---------------------------------------------------------------------
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