You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/01/24 08:04:10 UTC

[01/11] james-project git commit: JAMES-2293 Charsets should rely on constants.

Repository: james-project
Updated Branches:
  refs/heads/master 558f86e7c -> f3eb9b1fb


JAMES-2293 Charsets should rely on constants.


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

Branch: refs/heads/master
Commit: 70ec31658500897af406a7ff7b3e0fbd4dd01093
Parents: c920857
Author: benwa <bt...@linagora.com>
Authored: Mon Jan 22 09:51:02 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jan 24 14:58:03 2018 +0700

----------------------------------------------------------------------
 .../main/java/org/apache/james/webadmin/routes/GroupsRoutes.java  | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/70ec3165/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
index 63ec39a..d4987b4 100644
--- a/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
+++ b/server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/GroupsRoutes.java
@@ -24,6 +24,7 @@ import static spark.Spark.halt;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -229,7 +230,7 @@ public class GroupsRoutes implements Routes {
 
     private MailAddress parseMailAddress(String address) {
         try {
-            String decodedAddress = URLDecoder.decode(address, "UTF-8");
+            String decodedAddress = URLDecoder.decode(address, StandardCharsets.UTF_8.displayName());
             return new MailAddress(decodedAddress);
         } catch (AddressException e) {
             throw ErrorResponder.builder()


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


[08/11] james-project git commit: JAMES-2293 Allow to retrieve repository size

Posted by bt...@apache.org.
JAMES-2293 Allow to retrieve repository size


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

Branch: refs/heads/master
Commit: 438c3a4bdcc07d54c4a2e69c0eff244cbde39e96
Parents: 452183a
Author: benwa <bt...@linagora.com>
Authored: Mon Jan 22 11:41:33 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jan 24 15:00:05 2018 +0700

----------------------------------------------------------------------
 .../mailrepository/file/MBoxMailRepository.java | 14 ++++++--
 .../lib/AbstractMailRepository.java             |  6 ++++
 .../mailrepository/api/MailRepository.java      |  5 +++
 .../mailrepository/MailRepositoryContract.java  | 38 ++++++++++++++++++++
 .../memory/MemoryMailRepository.java            |  7 ++++
 5 files changed, 68 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/438c3a4b/server/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java b/server/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
index e378f28..b2f7510 100755
--- a/server/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
+++ b/server/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
@@ -77,6 +77,7 @@ import org.apache.mailet.Mail;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Iterators;
 import com.google.common.hash.Hashing;
 
 /**
@@ -495,8 +496,7 @@ public class MBoxMailRepository implements MailRepository, Configurable {
      * @see org.apache.james.mailrepository.api.MailRepository#list()
      */
     public Iterator<String> list() {
-        loadKeys();
-        ArrayList<String> keys = new ArrayList<>(mList.keySet());
+        ArrayList<String> keys = loadKeysAsArray();
 
         if (!keys.isEmpty()) {
             // find the first message. This is a trick to make sure that if
@@ -512,6 +512,11 @@ public class MBoxMailRepository implements MailRepository, Configurable {
         return keys.iterator();
     }
 
+    private ArrayList<String> loadKeysAsArray() {
+        loadKeys();
+        return new ArrayList<>(mList.keySet());
+    }
+
     /**
      * @see org.apache.james.mailrepository.api.MailRepository#retrieve(String)
      */
@@ -690,4 +695,9 @@ public class MBoxMailRepository implements MailRepository, Configurable {
     public boolean unlock(String key) {
         return false;
     }
+
+    @Override
+    public long size() throws MessagingException {
+        return loadKeysAsArray().size();
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/438c3a4b/server/data/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java b/server/data/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java
index 7778880..11f3eb6 100644
--- a/server/data/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java
+++ b/server/data/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java
@@ -33,6 +33,8 @@ import org.apache.mailet.Mail;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Iterators;
+
 /**
  * This class represent an AbstractMailRepository. All MailRepositories should
  * extend this class.
@@ -157,4 +159,8 @@ public abstract class AbstractMailRepository implements MailRepository, Configur
      */
     protected abstract void internalRemove(String key) throws MessagingException;
 
+    @Override
+    public long size() throws MessagingException {
+        return Iterators.size(list());
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/438c3a4b/server/mailrepository/mailrepository-api/src/main/java/org/apache/james/mailrepository/api/MailRepository.java
----------------------------------------------------------------------
diff --git a/server/mailrepository/mailrepository-api/src/main/java/org/apache/james/mailrepository/api/MailRepository.java b/server/mailrepository/mailrepository-api/src/main/java/org/apache/james/mailrepository/api/MailRepository.java
index e1a4092..95d7a89 100644
--- a/server/mailrepository/mailrepository-api/src/main/java/org/apache/james/mailrepository/api/MailRepository.java
+++ b/server/mailrepository/mailrepository-api/src/main/java/org/apache/james/mailrepository/api/MailRepository.java
@@ -32,6 +32,11 @@ import org.apache.mailet.Mail;
 public interface MailRepository {
 
     /**
+     * @return Number of mails stored in that repository
+     */
+    long size() throws MessagingException;
+
+    /**
      * Stores a message in this repository. 
      * 
      * TODO: Shouldn't this return the key under which it is stored?

http://git-wip-us.apache.org/repos/asf/james-project/blob/438c3a4b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
----------------------------------------------------------------------
diff --git a/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
index 3dae16a..7594fde 100644
--- a/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
+++ b/server/mailrepository/mailrepository-api/src/test/java/org/apache/james/mailrepository/MailRepositoryContract.java
@@ -96,6 +96,44 @@ public interface MailRepositoryContract {
     MailRepository retrieveRepository() throws Exception;
 
     @Test
+    default void sizeShouldReturnZeroWhenEmpty() throws Exception {
+        MailRepository testee = retrieveRepository();
+        assertThat(testee.size()).isEqualTo(0L);
+    }
+
+    @Test
+    default void sizeShouldReturnMailCount() throws Exception {
+        MailRepository testee = retrieveRepository();
+
+        testee.store(createMail("mail1"));
+        testee.store(createMail("mail2"));
+
+        assertThat(testee.size()).isEqualTo(2L);
+    }
+
+    @Test
+    default void sizeShouldBeIncrementedByOneWhenDuplicates() throws Exception {
+        MailRepository testee = retrieveRepository();
+
+        String key = "mail1";
+        testee.store(createMail(key));
+        testee.store(createMail(key));
+
+        assertThat(testee.size()).isEqualTo(1L);
+    }
+
+    @Test
+    default void sizeShouldBeDecrementedByRemove() throws Exception {
+        MailRepository testee = retrieveRepository();
+
+        String key = "mail1";
+        testee.store(createMail(key));
+        testee.remove(key);
+
+        assertThat(testee.size()).isEqualTo(0L);
+    }
+
+    @Test
     default void storeRegularMailShouldNotFail() throws Exception {
         MailRepository testee = retrieveRepository();
         Mail mail = createMail("mail1");

http://git-wip-us.apache.org/repos/asf/james-project/blob/438c3a4b/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java
----------------------------------------------------------------------
diff --git a/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java b/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java
index e281d83..e6b0bbf 100644
--- a/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java
+++ b/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java
@@ -23,6 +23,8 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.concurrent.ConcurrentHashMap;
 
+import javax.mail.MessagingException;
+
 import org.apache.james.mailrepository.api.MailRepository;
 import org.apache.mailet.Mail;
 
@@ -73,4 +75,9 @@ public class MemoryMailRepository implements MailRepository {
     public boolean unlock(String key) {
         return false;
     }
+
+    @Override
+    public long size() {
+        return mails.size();
+    }
 }


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


[11/11] james-project git commit: JAMES-2290 Remove io.vavr dependency

Posted by bt...@apache.org.
JAMES-2290 Remove io.vavr dependency


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

Branch: refs/heads/master
Commit: f3eb9b1fb0ed19d17ea1088ac84eaa35a78c8079
Parents: 21e1b55
Author: benwa <bt...@linagora.com>
Authored: Tue Jan 23 16:32:06 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jan 24 15:03:00 2018 +0700

----------------------------------------------------------------------
 server/testing/pom.xml                                    |  5 -----
 .../java/org/apache/james/utils/DiscreteDistribution.java |  6 +++---
 .../org/apache/james/utils/DiscreteDistributionTest.java  | 10 +++++-----
 3 files changed, 8 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f3eb9b1f/server/testing/pom.xml
----------------------------------------------------------------------
diff --git a/server/testing/pom.xml b/server/testing/pom.xml
index eadf713..8c6a7bf 100644
--- a/server/testing/pom.xml
+++ b/server/testing/pom.xml
@@ -67,11 +67,6 @@
             <artifactId>commons-net</artifactId>
         </dependency>
         <dependency>
-            <groupId>io.vavr</groupId>
-            <artifactId>vavr</artifactId>
-            <version>0.9.2</version>
-        </dependency>
-        <dependency>
             <groupId>org.assertj</groupId>
             <artifactId>assertj-core</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3eb9b1f/server/testing/src/main/java/org/apache/james/utils/DiscreteDistribution.java
----------------------------------------------------------------------
diff --git a/server/testing/src/main/java/org/apache/james/utils/DiscreteDistribution.java b/server/testing/src/main/java/org/apache/james/utils/DiscreteDistribution.java
index a21a3ca..eaeaaf5 100644
--- a/server/testing/src/main/java/org/apache/james/utils/DiscreteDistribution.java
+++ b/server/testing/src/main/java/org/apache/james/utils/DiscreteDistribution.java
@@ -20,6 +20,7 @@
 package org.apache.james.utils;
 
 import java.util.List;
+import java.util.stream.Stream;
 
 import org.apache.commons.math3.distribution.EnumeratedDistribution;
 import org.apache.commons.math3.util.Pair;
@@ -27,8 +28,6 @@ import org.apache.commons.math3.util.Pair;
 import com.github.steveash.guavate.Guavate;
 import com.google.common.base.Preconditions;
 
-import io.vavr.collection.Stream;
-
 public class DiscreteDistribution<T> {
 
     public static class DistributionEntry<V> {
@@ -73,7 +72,8 @@ public class DiscreteDistribution<T> {
     }
 
     public Stream<T> generateRandomStream() {
-        return Stream.continually(this::sample);
+        return Stream.iterate(this, i -> i)
+            .map(DiscreteDistribution::sample);
     }
 
     public T sample() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3eb9b1f/server/testing/src/test/java/org/apache/james/utils/DiscreteDistributionTest.java
----------------------------------------------------------------------
diff --git a/server/testing/src/test/java/org/apache/james/utils/DiscreteDistributionTest.java b/server/testing/src/test/java/org/apache/james/utils/DiscreteDistributionTest.java
index fdba0eb..4aaf150 100644
--- a/server/testing/src/test/java/org/apache/james/utils/DiscreteDistributionTest.java
+++ b/server/testing/src/test/java/org/apache/james/utils/DiscreteDistributionTest.java
@@ -47,7 +47,7 @@ class DiscreteDistributionTest {
                 new DistributionEntry<>("a", 0),
                 new DistributionEntry<>("b", 1)));
 
-        assertThat(testee.generateRandomStream().take(10)).containsOnly("b");
+        assertThat(testee.generateRandomStream().limit(10)).containsOnly("b");
     }
 
     @Test
@@ -72,7 +72,7 @@ class DiscreteDistributionTest {
             ImmutableList.of(
                 new DistributionEntry<>("a", 1)));
 
-        assertThat(testee.generateRandomStream().take(10)).containsOnly("a");
+        assertThat(testee.generateRandomStream().limit(10)).containsOnly("a");
     }
 
     @Test
@@ -82,7 +82,7 @@ class DiscreteDistributionTest {
                 new DistributionEntry<>("a", 10),
                 new DistributionEntry<>("b", 10)));
 
-        Map<String, Long> experimentOutcome = testee.generateRandomStream().take(1_000_000)
+        Map<String, Long> experimentOutcome = testee.generateRandomStream().limit(1_000_000)
             .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
         assertThat(experimentOutcome.get("a")).isCloseTo(experimentOutcome.get("b"), Offset.offset(5_000L));
     }
@@ -94,7 +94,7 @@ class DiscreteDistributionTest {
                 new DistributionEntry<>("a", 20),
                 new DistributionEntry<>("b", 10)));
 
-        Map<String, Long> experimentOutcome = testee.generateRandomStream().take(1_000_000)
+        Map<String, Long> experimentOutcome = testee.generateRandomStream().limit(1_000_000)
             .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
         assertThat(experimentOutcome.get("a")).isCloseTo(experimentOutcome.get("b") * 2, Offset.offset(5_000L));
     }
@@ -107,7 +107,7 @@ class DiscreteDistributionTest {
                 new DistributionEntry<>("b", 10),
                 new DistributionEntry<>("a", 10)));
 
-        Map<String, Long> experimentOutcome = testee.generateRandomStream().take(1_000_000)
+        Map<String, Long> experimentOutcome = testee.generateRandomStream().limit(1_000_000)
             .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
         assertThat(experimentOutcome.get("a")).isCloseTo(experimentOutcome.get("b") * 2, Offset.offset(5_000L));
     }


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


[03/11] james-project git commit: JAMES-2293 Webadmin should allow to list mail in repositories

Posted by bt...@apache.org.
JAMES-2293 Webadmin should allow to list mail in repositories


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

Branch: refs/heads/master
Commit: d423ef05367684d6827a1297f48fdf6db14e6d92
Parents: b773ace
Author: benwa <bt...@linagora.com>
Authored: Tue Jan 23 15:54:31 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jan 24 14:58:37 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/util/streams/Limit.java    |   5 +
 .../org/apache/james/webadmin/dto/MailKey.java  |  50 +++++++
 .../webadmin/routes/MailRepositoriesRoutes.java |  84 +++++++++++
 .../service/MailRepositoryStoreService.java     |  14 ++
 .../routes/MailRepositoriesRoutesTest.java      | 148 ++++++++++++++++++-
 .../service/MailRepositoryStoreServiceTest.java |  62 ++++++++
 6 files changed, 359 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d423ef05/server/container/util-java8/src/main/java/org/apache/james/util/streams/Limit.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/streams/Limit.java b/server/container/util-java8/src/main/java/org/apache/james/util/streams/Limit.java
index b3ba512..268ed5e 100644
--- a/server/container/util-java8/src/main/java/org/apache/james/util/streams/Limit.java
+++ b/server/container/util-java8/src/main/java/org/apache/james/util/streams/Limit.java
@@ -35,6 +35,11 @@ public class Limit {
         }
     }
 
+    public static Limit from(Optional<Integer> limit) {
+        return limit.map(Limit::from)
+            .orElse(unlimited());
+    }
+
     public static Limit unlimited() {
         return new Limit(Optional.empty());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d423ef05/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailKey.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailKey.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailKey.java
new file mode 100644
index 0000000..9d44dae
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailKey.java
@@ -0,0 +1,50 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.dto;
+
+import java.util.Objects;
+
+public class MailKey {
+
+    private final String repository;
+
+    public MailKey(String mailKey) {
+        this.repository = mailKey;
+    }
+
+    public String getMailKey() {
+        return repository;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof MailKey) {
+            MailKey mailKey = (MailKey) o;
+
+            return Objects.equals(this.repository, mailKey.repository);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(repository);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d423ef05/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
index dbfc60d..1cc7a06 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
@@ -19,22 +19,34 @@
 
 package org.apache.james.webadmin.routes;
 
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
+import java.util.Optional;
 
 import javax.inject.Inject;
+import javax.mail.MessagingException;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 
+import org.apache.james.mailrepository.api.MailRepositoryStore;
+import org.apache.james.util.streams.Limit;
 import org.apache.james.webadmin.Routes;
 import org.apache.james.webadmin.service.MailRepositoryStoreService;
+import org.apache.james.webadmin.utils.ErrorResponder;
 import org.apache.james.webadmin.utils.JsonTransformer;
 import org.eclipse.jetty.http.HttpStatus;
 
+import com.google.common.base.Strings;
+
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiResponse;
 import io.swagger.annotations.ApiResponses;
+import spark.Request;
 import spark.Service;
 
 @Api(tags = "MailRepositories")
@@ -43,6 +55,7 @@ import spark.Service;
 public class MailRepositoriesRoutes implements Routes {
 
     public static final String MAIL_REPOSITORIES = "mailRepositories";
+    public static final int NO_OFFSET = 0;
 
     private final JsonTransformer jsonTransformer;
     private final MailRepositoryStoreService repositoryStoreService;
@@ -59,6 +72,50 @@ public class MailRepositoriesRoutes implements Routes {
         this.service = service;
 
         defineGetMailRepositories();
+
+        defineListMails();
+    }
+
+    @GET
+    @Path("/{encodedUrl}/mails")
+    @ApiOperation(value = "Listing all mails in a repository")
+    @ApiImplicitParams({
+        @ApiImplicitParam(
+            required = false,
+            paramType = "query parameter",
+            dataType = "Integer",
+            defaultValue = "0",
+            example = "?offset=100",
+            value = "If present, skips the given number of key in the output."),
+        @ApiImplicitParam(
+            required = false,
+            paramType = "query parameter",
+            dataType = "Integer",
+            defaultValue = "0",
+            example = "?limit=100",
+            value = "If present, fixes the maximal number of key returned in that call.")
+    })
+    @ApiResponses(value = {
+        @ApiResponse(code = HttpStatus.OK_200, message = "The list of all mails in a repository", response = List.class),
+        @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side."),
+        @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad request - invalid parameter")
+    })
+    public void defineListMails() {
+        service.get(MAIL_REPOSITORIES + "/:encodedUrl/mails", (request, response) -> {
+            int offset = asInteger(request, "offset").orElse(NO_OFFSET);
+            Limit limit = Limit.from(asInteger(request, "limit"));
+            String url = URLDecoder.decode(request.params("encodedUrl"), StandardCharsets.UTF_8.displayName());
+            try {
+                return repositoryStoreService.listMails(url, offset, limit);
+            } catch (MailRepositoryStore.MailRepositoryStoreException| MessagingException e) {
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                    .type(ErrorResponder.ErrorType.SERVER_ERROR)
+                    .cause(e)
+                    .message("Error while listing keys")
+                    .haltError();
+            }
+        }, jsonTransformer);
     }
 
     @GET
@@ -73,4 +130,31 @@ public class MailRepositoriesRoutes implements Routes {
             return repositoryStoreService.listMailRepositories();
         }, jsonTransformer);
     }
+
+    private Optional<Integer> asInteger(Request request, String parameterName) {
+        try {
+            return Optional.ofNullable(request.queryParams(parameterName))
+                .filter(s -> !Strings.isNullOrEmpty(s))
+                .map(Integer::valueOf)
+                .map(value -> keepPositive(value, parameterName));
+        } catch (NumberFormatException e) {
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
+                .cause(e)
+                .message("Can not parse " + parameterName)
+                .haltError();
+        }
+    }
+
+    private int keepPositive(int value, String parameterName) {
+        if (value < 0) {
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
+                .message(parameterName + " can not be negative")
+                .haltError();
+        }
+        return value;
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d423ef05/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
index bb7f6cd..8be5c44 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
@@ -22,8 +22,13 @@ package org.apache.james.webadmin.service;
 import java.util.List;
 
 import javax.inject.Inject;
+import javax.mail.MessagingException;
 
+import org.apache.james.mailrepository.api.MailRepository;
 import org.apache.james.mailrepository.api.MailRepositoryStore;
+import org.apache.james.util.streams.Iterators;
+import org.apache.james.util.streams.Limit;
+import org.apache.james.webadmin.dto.MailKey;
 import org.apache.james.webadmin.dto.MailRepositoryResponse;
 
 import com.github.steveash.guavate.Guavate;
@@ -43,4 +48,13 @@ public class MailRepositoryStoreService {
             .collect(Guavate.toImmutableList());
     }
 
+    public List<MailKey> listMails(String url, long offset, Limit limit) throws MailRepositoryStore.MailRepositoryStoreException, MessagingException {
+        MailRepository mailRepository = mailRepositoryStore.select(url);
+        return limit.applyOnStream(
+            Iterators.toStream(mailRepository.list())
+                .skip(offset))
+            .map(MailKey::new)
+            .collect(Guavate.toImmutableList());
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d423ef05/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
index 7788b98..ddac73d 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
@@ -24,6 +24,8 @@ import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
 import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.is;
 import static org.mockito.Mockito.mock;
@@ -33,11 +35,14 @@ import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 import org.apache.james.mailrepository.api.MailRepositoryStore;
+import org.apache.james.mailrepository.memory.MemoryMailRepository;
 import org.apache.james.metrics.logger.DefaultMetricFactory;
 import org.apache.james.webadmin.WebAdminServer;
 import org.apache.james.webadmin.WebAdminUtils;
 import org.apache.james.webadmin.service.MailRepositoryStoreService;
+import org.apache.james.webadmin.utils.ErrorResponder;
 import org.apache.james.webadmin.utils.JsonTransformer;
+import org.apache.mailet.base.test.FakeMail;
 import org.eclipse.jetty.http.HttpStatus;
 import org.junit.After;
 import org.junit.Before;
@@ -50,12 +55,17 @@ import com.jayway.restassured.http.ContentType;
 
 public class MailRepositoriesRoutesTest {
 
+    public static final String URL_MY_REPO = "url://myRepo";
+    public static final String URL_ESCAPED_MY_REPO = "url%3A%2F%2FmyRepo";
+    public static final String MY_REPO_MAILS = "url%3A%2F%2FmyRepo/mails";
     private WebAdminServer webAdminServer;
     private MailRepositoryStore mailRepositoryStore;
+    private MemoryMailRepository mailRepository;
 
     @Before
     public void setUp() throws Exception {
         mailRepositoryStore = mock(MailRepositoryStore.class);
+        mailRepository = new MemoryMailRepository();
 
         webAdminServer = WebAdminUtils.createWebAdminServer(
                 new DefaultMetricFactory(),
@@ -96,20 +106,20 @@ public class MailRepositoriesRoutesTest {
     @Test
     public void getMailRepositoriesShouldReturnRepositoryWhenOne() {
         when(mailRepositoryStore.getUrls())
-            .thenReturn(ImmutableList.of("url://myRepo"));
+            .thenReturn(ImmutableList.of(URL_MY_REPO));
 
         when()
             .get()
         .then()
             .statusCode(HttpStatus.OK_200)
             .body("", hasSize(1))
-            .body("[0].repository", is("url://myRepo"))
-            .body("[0].encodedUrl", is("url%3A%2F%2FmyRepo"));
+            .body("[0].repository", is(URL_MY_REPO))
+            .body("[0].encodedUrl", is(URL_ESCAPED_MY_REPO));
     }
 
     @Test
     public void getMailRepositoriesShouldReturnTwoRepositoriesWhenTwo() {
-        ImmutableList<String> myRepositories = ImmutableList.of("url://myRepo", "url://mySecondRepo");
+        ImmutableList<String> myRepositories = ImmutableList.of(URL_MY_REPO, "url://mySecondRepo");
         when(mailRepositoryStore.getUrls())
             .thenReturn(myRepositories);
 
@@ -127,4 +137,134 @@ public class MailRepositoriesRoutesTest {
         assertThat(mailRepositories).containsOnlyElementsOf(myRepositories);
     }
 
+    @Test
+    public void listingKeysShouldReturnEmptyWhenNoMail() throws Exception {
+        when(mailRepositoryStore.select(URL_MY_REPO)).thenReturn(mailRepository);
+
+        when()
+            .get(MY_REPO_MAILS)
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .body("", hasSize(0));
+    }
+
+    @Test
+    public void listingKeysShouldReturnContainedKeys() throws Exception {
+        when(mailRepositoryStore.select(URL_MY_REPO)).thenReturn(mailRepository);
+
+        mailRepository.store(FakeMail.builder()
+            .name("name1")
+            .build());
+        mailRepository.store(FakeMail.builder()
+            .name("name2")
+            .build());
+
+        when()
+            .get(MY_REPO_MAILS)
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .body("", hasSize(2))
+            .body("mailKey", containsInAnyOrder("name1", "name2"));
+    }
+
+    @Test
+    public void listingKeysShouldApplyLimitAndOffset() throws Exception {
+        when(mailRepositoryStore.select(URL_MY_REPO)).thenReturn(mailRepository);
+
+        mailRepository.store(FakeMail.builder()
+            .name("name1")
+            .build());
+        mailRepository.store(FakeMail.builder()
+            .name("name2")
+            .build());
+        mailRepository.store(FakeMail.builder()
+            .name("name3")
+            .build());
+
+        when()
+            .get(MY_REPO_MAILS + "?offset=1&limit=1")
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .body("", hasSize(1))
+            .body("mailKey", containsInAnyOrder("name2"));
+    }
+
+    @Test
+    public void listingKeysShouldHandleErrorGracefully() throws Exception {
+        when(mailRepositoryStore.select(URL_MY_REPO))
+            .thenThrow(new MailRepositoryStore.MailRepositoryStoreException("message"));
+
+        when()
+            .get(MY_REPO_MAILS)
+        .then()
+            .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+            .body("statusCode", is(500))
+            .body("type", is(ErrorResponder.ErrorType.SERVER_ERROR.getType()))
+            .body("message", is("Error while listing keys"))
+            .body("cause", containsString("message"));
+    }
+
+    @Test
+    public void listingKeysShouldReturnErrorOnInvalidOffset() throws Exception {
+        when()
+            .get(MY_REPO_MAILS + "?offset=invalid")
+        .then()
+            .statusCode(HttpStatus.BAD_REQUEST_400)
+            .body("statusCode", is(400))
+            .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+            .body("message", is("Can not parse offset"));
+    }
+
+    @Test
+    public void listingKeysShouldReturnErrorOnNegativeOffset() throws Exception {
+        when()
+            .get(MY_REPO_MAILS + "?offset=-1")
+        .then()
+            .statusCode(HttpStatus.BAD_REQUEST_400)
+            .body("statusCode", is(400))
+            .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+            .body("message", is("offset can not be negative"));
+    }
+
+    @Test
+    public void listingKeysShouldReturnErrorOnInvalidLimit() throws Exception {
+        when()
+            .get(MY_REPO_MAILS + "?limit=invalid")
+        .then()
+            .statusCode(HttpStatus.BAD_REQUEST_400)
+            .body("statusCode", is(400))
+            .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+            .body("message", is("Can not parse limit"));
+    }
+
+    @Test
+    public void listingKeysShouldReturnErrorOnNegativeLimit() throws Exception {
+        when()
+            .get(MY_REPO_MAILS + "?limit=-1")
+        .then()
+            .statusCode(HttpStatus.BAD_REQUEST_400)
+            .body("statusCode", is(400))
+            .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+            .body("message", is("limit can not be negative"));
+    }
+
+    @Test
+    public void listingKeysShouldIgnoreZeroedOffset() throws Exception {
+        when(mailRepositoryStore.select(URL_MY_REPO)).thenReturn(mailRepository);
+
+        mailRepository.store(FakeMail.builder()
+            .name("name1")
+            .build());
+        mailRepository.store(FakeMail.builder()
+            .name("name2")
+            .build());
+
+        when()
+            .get(MY_REPO_MAILS + "?offset=0")
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .body("", hasSize(2))
+            .body("mailKey", containsInAnyOrder("name1", "name2"));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d423ef05/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
index 11305f3..9079ae6 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
@@ -19,11 +19,17 @@
 package org.apache.james.webadmin.service;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import org.apache.james.mailrepository.api.MailRepositoryStore;
+import org.apache.james.mailrepository.memory.MemoryMailRepository;
+import org.apache.james.util.streams.Limit;
+import org.apache.james.webadmin.dto.MailKey;
 import org.apache.james.webadmin.dto.MailRepositoryResponse;
+import org.apache.james.webadmin.routes.MailRepositoriesRoutes;
+import org.apache.mailet.base.test.FakeMail;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -32,12 +38,17 @@ import com.google.common.collect.ImmutableList;
 public class MailRepositoryStoreServiceTest {
     private static final String FIRST_REPOSITORY = "url://repository";
     private static final String SECOND_REPOSITORY = "url://repository2";
+    private static final String NAME_1 = "name1";
+    private static final String NAME_2 = "name2";
+
     private MailRepositoryStore mailRepositoryStore;
     private MailRepositoryStoreService testee;
+    private MemoryMailRepository repository;
 
     @Before
     public void setUp() {
         mailRepositoryStore = mock(MailRepositoryStore.class);
+        repository = new MemoryMailRepository();
         testee = new MailRepositoryStoreService(mailRepositoryStore);
     }
 
@@ -63,4 +74,55 @@ public class MailRepositoryStoreServiceTest {
             .extracting(MailRepositoryResponse::getRepository)
             .containsOnly(FIRST_REPOSITORY, SECOND_REPOSITORY);
     }
+
+    @Test
+    public void listMailsShouldThrowWhenMailRepositoryStoreThrows() throws Exception {
+        when(mailRepositoryStore.select(FIRST_REPOSITORY))
+            .thenThrow(new MailRepositoryStore.MailRepositoryStoreException("message"));
+
+        assertThatThrownBy(() -> testee.listMails(FIRST_REPOSITORY, MailRepositoriesRoutes.NO_OFFSET, Limit.unlimited()))
+            .isInstanceOf(MailRepositoryStore.MailRepositoryStoreException.class);
+    }
+
+    @Test
+    public void listMailsShouldReturnEmptyWhenMailRepositoryIsEmpty() throws Exception {
+        when(mailRepositoryStore.select(FIRST_REPOSITORY)).thenReturn(repository);
+
+        assertThat(testee.listMails(FIRST_REPOSITORY, MailRepositoriesRoutes.NO_OFFSET, Limit.unlimited()))
+            .isEmpty();
+    }
+
+    @Test
+    public void listMailsShouldReturnContainedMailKeys() throws Exception {
+        when(mailRepositoryStore.select(FIRST_REPOSITORY)).thenReturn(repository);
+
+        repository.store(FakeMail.builder()
+            .name(NAME_1)
+            .build());
+        repository.store(FakeMail.builder()
+            .name(NAME_2)
+            .build());
+
+        assertThat(testee.listMails(FIRST_REPOSITORY, MailRepositoriesRoutes.NO_OFFSET, Limit.unlimited()))
+            .containsOnly(new MailKey(NAME_1), new MailKey(NAME_2));
+    }
+
+    @Test
+    public void listMailsShouldApplyLimitAndOffset() throws Exception {
+        when(mailRepositoryStore.select(FIRST_REPOSITORY)).thenReturn(repository);
+
+        repository.store(FakeMail.builder()
+            .name(NAME_1)
+            .build());
+        repository.store(FakeMail.builder()
+            .name(NAME_2)
+            .build());
+        repository.store(FakeMail.builder()
+            .name("name3")
+            .build());
+
+        int offset = 1;
+        assertThat(testee.listMails(FIRST_REPOSITORY, offset, Limit.from(1)))
+            .containsOnly(new MailKey(NAME_2));
+    }
 }


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


[06/11] james-project git commit: JAMES-2293 Introduce route for mail repositories

Posted by bt...@apache.org.
JAMES-2293 Introduce route for mail repositories


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

Branch: refs/heads/master
Commit: 6b2d54faeed8e60add873f2cb2fd1702b1569762
Parents: d0a26a9
Author: benwa <bt...@linagora.com>
Authored: Tue Jan 23 15:55:57 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jan 24 14:58:37 2018 +0700

----------------------------------------------------------------------
 .../webadmin/dto/MailRepositoryResponse.java    |  41 ++++++
 .../webadmin/routes/MailRepositoriesRoutes.java |  76 +++++++++++
 .../service/MailRepositoryStoreService.java     |  46 +++++++
 .../routes/MailRepositoriesRoutesTest.java      | 130 +++++++++++++++++++
 .../service/MailRepositoryStoreServiceTest.java |  66 ++++++++++
 5 files changed, 359 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/6b2d54fa/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailRepositoryResponse.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailRepositoryResponse.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailRepositoryResponse.java
new file mode 100644
index 0000000..e4b43ae
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailRepositoryResponse.java
@@ -0,0 +1,41 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.dto;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+
+public class MailRepositoryResponse {
+
+    private final String repository;
+
+    public MailRepositoryResponse(String repository) {
+        this.repository = repository;
+    }
+
+    public String getRepository() {
+        return repository;
+    }
+
+    public String getEncodedUrl() throws UnsupportedEncodingException {
+        return URLEncoder.encode(repository, StandardCharsets.UTF_8.displayName());
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b2d54fa/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
new file mode 100644
index 0000000..dbfc60d
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
@@ -0,0 +1,76 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.routes;
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.service.MailRepositoryStoreService;
+import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import spark.Service;
+
+@Api(tags = "MailRepositories")
+@Path("/mailRepositories")
+@Produces("application/json")
+public class MailRepositoriesRoutes implements Routes {
+
+    public static final String MAIL_REPOSITORIES = "mailRepositories";
+
+    private final JsonTransformer jsonTransformer;
+    private final MailRepositoryStoreService repositoryStoreService;
+    private Service service;
+
+    @Inject
+    public MailRepositoriesRoutes(MailRepositoryStoreService repositoryStoreService, JsonTransformer jsonTransformer) {
+        this.repositoryStoreService = repositoryStoreService;
+        this.jsonTransformer = jsonTransformer;
+    }
+
+    @Override
+    public void define(Service service) {
+        this.service = service;
+
+        defineGetMailRepositories();
+    }
+
+    @GET
+    @ApiOperation(value = "Listing all mail repositories URLs")
+    @ApiResponses(value = {
+        @ApiResponse(code = HttpStatus.OK_200, message = "Listing all mail repositories URLs", response = List.class),
+        @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.")
+    })
+    public void defineGetMailRepositories() {
+        service.get(MAIL_REPOSITORIES, (request, response) -> {
+            response.status(HttpStatus.OK_200);
+            return repositoryStoreService.listMailRepositories();
+        }, jsonTransformer);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b2d54fa/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
new file mode 100644
index 0000000..bb7f6cd
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
@@ -0,0 +1,46 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.service;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.james.mailrepository.api.MailRepositoryStore;
+import org.apache.james.webadmin.dto.MailRepositoryResponse;
+
+import com.github.steveash.guavate.Guavate;
+
+public class MailRepositoryStoreService {
+    private final MailRepositoryStore mailRepositoryStore;
+
+    @Inject
+    public MailRepositoryStoreService(MailRepositoryStore mailRepositoryStore) {
+        this.mailRepositoryStore = mailRepositoryStore;
+    }
+
+    public List<MailRepositoryResponse> listMailRepositories() {
+        return mailRepositoryStore.getUrls()
+            .stream()
+            .map(MailRepositoryResponse::new)
+            .collect(Guavate.toImmutableList());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b2d54fa/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
new file mode 100644
index 0000000..7788b98
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
@@ -0,0 +1,130 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.routes;
+
+import static com.jayway.restassured.RestAssured.when;
+import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
+import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
+import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+import org.apache.james.mailrepository.api.MailRepositoryStore;
+import org.apache.james.metrics.logger.DefaultMetricFactory;
+import org.apache.james.webadmin.WebAdminServer;
+import org.apache.james.webadmin.WebAdminUtils;
+import org.apache.james.webadmin.service.MailRepositoryStoreService;
+import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.jayway.restassured.RestAssured;
+import com.jayway.restassured.builder.RequestSpecBuilder;
+import com.jayway.restassured.http.ContentType;
+
+public class MailRepositoriesRoutesTest {
+
+    private WebAdminServer webAdminServer;
+    private MailRepositoryStore mailRepositoryStore;
+
+    @Before
+    public void setUp() throws Exception {
+        mailRepositoryStore = mock(MailRepositoryStore.class);
+
+        webAdminServer = WebAdminUtils.createWebAdminServer(
+                new DefaultMetricFactory(),
+                new MailRepositoriesRoutes(new MailRepositoryStoreService(mailRepositoryStore), new JsonTransformer()));
+        webAdminServer.configure(NO_CONFIGURATION);
+        webAdminServer.await();
+
+        RestAssured.requestSpecification = new RequestSpecBuilder()
+            .setContentType(ContentType.JSON)
+            .setAccept(ContentType.JSON)
+            .setBasePath(MailRepositoriesRoutes.MAIL_REPOSITORIES)
+            .setPort(webAdminServer.getPort().get().getValue())
+            .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)))
+            .build();
+    }
+
+    @After
+    public void tearDown() {
+        webAdminServer.destroy();
+    }
+
+    @Test
+    public void getMailRepositoriesShouldReturnEmptyWhenEmpty() {
+        List<Object> mailRepositories =
+            when()
+                .get()
+            .then()
+                .statusCode(HttpStatus.OK_200)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getList(".");
+
+        assertThat(mailRepositories).isEmpty();
+    }
+
+    @Test
+    public void getMailRepositoriesShouldReturnRepositoryWhenOne() {
+        when(mailRepositoryStore.getUrls())
+            .thenReturn(ImmutableList.of("url://myRepo"));
+
+        when()
+            .get()
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .body("", hasSize(1))
+            .body("[0].repository", is("url://myRepo"))
+            .body("[0].encodedUrl", is("url%3A%2F%2FmyRepo"));
+    }
+
+    @Test
+    public void getMailRepositoriesShouldReturnTwoRepositoriesWhenTwo() {
+        ImmutableList<String> myRepositories = ImmutableList.of("url://myRepo", "url://mySecondRepo");
+        when(mailRepositoryStore.getUrls())
+            .thenReturn(myRepositories);
+
+        List<String> mailRepositories =
+            when()
+                .get()
+            .then()
+                .statusCode(HttpStatus.OK_200)
+                .contentType(ContentType.JSON)
+                .extract()
+                .body()
+                .jsonPath()
+                .getList("repository");
+
+        assertThat(mailRepositories).containsOnlyElementsOf(myRepositories);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/6b2d54fa/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
new file mode 100644
index 0000000..11305f3
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
@@ -0,0 +1,66 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.webadmin.service;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.james.mailrepository.api.MailRepositoryStore;
+import org.apache.james.webadmin.dto.MailRepositoryResponse;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class MailRepositoryStoreServiceTest {
+    private static final String FIRST_REPOSITORY = "url://repository";
+    private static final String SECOND_REPOSITORY = "url://repository2";
+    private MailRepositoryStore mailRepositoryStore;
+    private MailRepositoryStoreService testee;
+
+    @Before
+    public void setUp() {
+        mailRepositoryStore = mock(MailRepositoryStore.class);
+        testee = new MailRepositoryStoreService(mailRepositoryStore);
+    }
+
+    @Test
+    public void listMailRepositoriesShouldReturnEmptyWhenEmpty() {
+        assertThat(testee.listMailRepositories()).isEmpty();
+    }
+
+    @Test
+    public void listMailRepositoriesShouldReturnOneRepositoryWhenOne() {
+        when(mailRepositoryStore.getUrls())
+            .thenReturn(ImmutableList.of(FIRST_REPOSITORY));
+        assertThat(testee.listMailRepositories())
+            .extracting(MailRepositoryResponse::getRepository)
+            .containsOnly(FIRST_REPOSITORY);
+    }
+
+    @Test
+    public void listMailRepositoriesShouldReturnTwoRepositoriesWhentwo() {
+        when(mailRepositoryStore.getUrls())
+            .thenReturn(ImmutableList.of(FIRST_REPOSITORY, SECOND_REPOSITORY));
+        assertThat(testee.listMailRepositories())
+            .extracting(MailRepositoryResponse::getRepository)
+            .containsOnly(FIRST_REPOSITORY, SECOND_REPOSITORY);
+    }
+}


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


[02/11] james-project git commit: Suppress Eclipse warnings

Posted by bt...@apache.org.
Suppress Eclipse warnings


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

Branch: refs/heads/master
Commit: c920857566e6e8e4ae27cbc0b35b631d47e05bec
Parents: 558f86e
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Fri Jan 19 15:20:09 2018 +0100
Committer: benwa <bt...@linagora.com>
Committed: Wed Jan 24 14:58:03 2018 +0700

----------------------------------------------------------------------
 .../mailbox/cassandra/CassandraMailboxSessionMapperFactory.java  | 3 +--
 .../mailbox/cassandra/CassandraSubscriptionManagerTest.java      | 3 ---
 .../cassandra/TestCassandraMailboxSessionMapperFactory.java      | 2 +-
 .../org/apache/james/filesystem/api/AbstractFileSystemTest.java  | 4 ----
 4 files changed, 2 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c9208575/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
index 69888e2..b70516c 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
@@ -23,7 +23,6 @@ import javax.inject.Inject;
 
 import org.apache.james.backends.cassandra.init.CassandraConfiguration;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
-import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.ObjectStore;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.cassandra.mail.CassandraACLMapper;
@@ -104,7 +103,7 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa
                                                 ObjectStore objectStore, CassandraAttachmentMessageIdDAO attachmentMessageIdDAO,
                                                 CassandraAttachmentOwnerDAO ownerDAO, CassandraACLMapper aclMapper,
                                                 CassandraUserMailboxRightsDAO userMailboxRightsDAO,
-                                                BlobId.Factory blobIdFactory, CassandraUtils cassandraUtils, CassandraConfiguration cassandraConfiguration) {
+                                                CassandraUtils cassandraUtils, CassandraConfiguration cassandraConfiguration) {
         this.uidProvider = uidProvider;
         this.modSeqProvider = modSeqProvider;
         this.session = session;

http://git-wip-us.apache.org/repos/asf/james-project/blob/c9208575/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
index 64a7d84..1222958 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManagerTest.java
@@ -24,7 +24,6 @@ import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.backends.cassandra.init.CassandraConfiguration;
 import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
-import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.ObjectStore;
 import org.apache.james.mailbox.AbstractSubscriptionManagerTest;
 import org.apache.james.mailbox.SubscriptionManager;
@@ -99,7 +98,6 @@ public class CassandraSubscriptionManagerTest extends AbstractSubscriptionManage
         CassandraAttachmentOwnerDAO ownerDAO = null;
         CassandraACLMapper aclMapper = null;
         CassandraUserMailboxRightsDAO userMailboxRightsDAO = null;
-        BlobId.Factory blobIdFactory = null;
         ObjectStore objectStore = null;
         return new CassandraSubscriptionManager(
             new CassandraMailboxSessionMapperFactory(
@@ -123,7 +121,6 @@ public class CassandraSubscriptionManagerTest extends AbstractSubscriptionManage
                 ownerDAO,
                 aclMapper,
                 userMailboxRightsDAO,
-                blobIdFactory,
                 CassandraUtils.WITH_DEFAULT_CONFIGURATION,
                 CassandraConfiguration.DEFAULT_CONFIGURATION));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/c9208575/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/TestCassandraMailboxSessionMapperFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/TestCassandraMailboxSessionMapperFactory.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/TestCassandraMailboxSessionMapperFactory.java
index c4503b1..3afdf36 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/TestCassandraMailboxSessionMapperFactory.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/TestCassandraMailboxSessionMapperFactory.java
@@ -73,7 +73,7 @@ public class TestCassandraMailboxSessionMapperFactory {
                 new CassandraUserMailboxRightsDAO(session, CassandraUtils.WITH_DEFAULT_CONFIGURATION),
                 CassandraConfiguration.DEFAULT_CONFIGURATION),
             new CassandraUserMailboxRightsDAO(session, CassandraUtils.WITH_DEFAULT_CONFIGURATION),
-            blobIdFactory, CassandraUtils.WITH_DEFAULT_CONFIGURATION,
+            CassandraUtils.WITH_DEFAULT_CONFIGURATION,
             CassandraConfiguration.DEFAULT_CONFIGURATION);
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/c9208575/server/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/AbstractFileSystemTest.java
----------------------------------------------------------------------
diff --git a/server/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/AbstractFileSystemTest.java b/server/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/AbstractFileSystemTest.java
index 18e4b3b..0d8890d 100644
--- a/server/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/AbstractFileSystemTest.java
+++ b/server/container/filesystem-api/src/test/java/org/apache/james/filesystem/api/AbstractFileSystemTest.java
@@ -72,7 +72,6 @@ public abstract class AbstractFileSystemTest {
         fileSystem = buildFileSystem(rootDirectory.getAbsolutePath());
     }
 
-    @SuppressWarnings("deprecation")
     private void createSubFolderWithAFileIn(String folderName, String fileName, String fileContent) throws IOException {
         File folder = tmpFolder.newFolder(folderName);
         File file = new File(folder.getAbsolutePath() + "/" + fileName);
@@ -231,7 +230,6 @@ public abstract class AbstractFileSystemTest {
         }
     }
 
-    @SuppressWarnings("deprecation")
     @Test
     @Parameters(source = FileToCreateProvider.class)
     public final void createdFilesAsInputStreamShouldBeAvailable(String name, String extension) throws Exception {
@@ -246,7 +244,6 @@ public abstract class AbstractFileSystemTest {
         }
     }
 
-    @SuppressWarnings("deprecation")
     @Test
     @Parameters(source = FileToCreateProvider.class)
     public final void createdFilesAsInputStreamShouldBeAvailableWhenAccessedWithTwoSlashes(String name, String extension) throws Exception {
@@ -261,7 +258,6 @@ public abstract class AbstractFileSystemTest {
         }
     }
 
-    @SuppressWarnings("deprecation")
     private File createTempFile(String name, String extension) throws IOException {
         File temp = File.createTempFile(name, extension);
         FileUtils.write(temp, "content", StandardCharsets.UTF_8);


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


[04/11] james-project git commit: JAMES-2293 Move Limit to a more generic project

Posted by bt...@apache.org.
JAMES-2293 Move Limit to a more generic project


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

Branch: refs/heads/master
Commit: b773ace9d1a68ef3ec2c5e6a2870fd35a61d8a47
Parents: 6b2d54f
Author: benwa <bt...@linagora.com>
Authored: Mon Jan 22 10:05:57 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jan 24 14:58:37 2018 +0700

----------------------------------------------------------------------
 .../cassandra/mail/CassandraMessageDAO.java     |   2 +-
 .../mail/CassandraMessageIdMapper.java          |   2 +-
 .../cassandra/mail/CassandraMessageMapper.java  |   2 +-
 .../mailbox/cassandra/mail/utils/Limit.java     |  76 ------------
 .../cassandra/mail/CassandraMessageDAOTest.java |   2 +-
 .../mailbox/cassandra/mail/utils/LimitTest.java | 115 -------------------
 .../org/apache/james/util/streams/Limit.java    |  76 ++++++++++++
 .../apache/james/util/streams/LimitTest.java    | 115 +++++++++++++++++++
 8 files changed, 195 insertions(+), 195 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b773ace9/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
index e00ca41..dadd033 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
@@ -62,7 +62,6 @@ import org.apache.james.backends.cassandra.utils.CassandraUtils;
 import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.ObjectStore;
 import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
-import org.apache.james.mailbox.cassandra.mail.utils.Limit;
 import org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table;
 import org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.Attachments;
 import org.apache.james.mailbox.cassandra.table.CassandraMessageV2Table.Properties;
@@ -80,6 +79,7 @@ import org.apache.james.mailbox.store.mail.model.impl.SimpleProperty;
 import org.apache.james.util.CompletableFutureUtil;
 import org.apache.james.util.FluentFutureStream;
 import org.apache.james.util.streams.JamesCollectors;
+import org.apache.james.util.streams.Limit;
 
 import com.datastax.driver.core.BoundStatement;
 import com.datastax.driver.core.PreparedStatement;

http://git-wip-us.apache.org/repos/asf/james-project/blob/b773ace9/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
index 5307674..ef039c6 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageIdMapper.java
@@ -36,7 +36,6 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
 import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
-import org.apache.james.mailbox.cassandra.mail.utils.Limit;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData;
@@ -51,6 +50,7 @@ import org.apache.james.mailbox.store.mail.ModSeqProvider;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 import org.apache.james.util.FluentFutureStream;
+import org.apache.james.util.streams.Limit;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b773ace9/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index 770c360..08172ed 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -39,7 +39,6 @@ import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
 import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
 import org.apache.james.mailbox.cassandra.mail.utils.FlagsUpdateStageResult;
-import org.apache.james.mailbox.cassandra.mail.utils.Limit;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData;
@@ -56,6 +55,7 @@ import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 import org.apache.james.util.FluentFutureStream;
 import org.apache.james.util.OptionalUtils;
 import org.apache.james.util.streams.JamesCollectors;
+import org.apache.james.util.streams.Limit;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b773ace9/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/utils/Limit.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/utils/Limit.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/utils/Limit.java
deleted file mode 100644
index 3b8bb90..0000000
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/utils/Limit.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mailbox.cassandra.mail.utils;
-
-import java.util.Objects;
-import java.util.Optional;
-import java.util.stream.Stream;
-
-import com.google.common.base.Preconditions;
-
-public class Limit {
-
-    public static Limit from(int limit) {
-        if (limit > 0) {
-            return new Limit(Optional.of(limit));
-        } else {
-            return unlimited();
-        }
-    }
-
-    public static Limit unlimited() {
-        return new Limit(Optional.empty());
-    }
-
-    public static Limit limit(int limit) {
-        Preconditions.checkArgument(limit > 0, "limit should be positive");
-        return new Limit(Optional.of(limit));
-    }
-
-    private final Optional<Integer> limit;
-
-    private Limit(Optional<Integer> limit) {
-        this.limit = limit;
-    }
-
-    public Optional<Integer> getLimit() {
-        return limit;
-    }
-
-    public <T> Stream<T> applyOnStream(Stream<T> stream) {
-        return limit
-            .map(stream::limit)
-            .orElse(stream);
-    }
-
-    @Override
-    public final boolean equals(Object o) {
-        if (o instanceof Limit) {
-            Limit other = (Limit) o;
-            return Objects.equals(limit, other.limit);
-        }
-        return false;
-    }
-
-    @Override
-    public final int hashCode() {
-        return Objects.hash(limit);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b773ace9/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
index f9d3f45..8e00d7b 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOTest.java
@@ -45,7 +45,6 @@ import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
 import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
 import org.apache.james.mailbox.cassandra.mail.CassandraMessageDAO.MessageIdAttachmentIds;
-import org.apache.james.mailbox.cassandra.mail.utils.Limit;
 import org.apache.james.mailbox.cassandra.modules.CassandraMessageModule;
 import org.apache.james.mailbox.model.Attachment;
 import org.apache.james.mailbox.model.ComposedMessageId;
@@ -55,6 +54,7 @@ import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
+import org.apache.james.util.streams.Limit;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;

http://git-wip-us.apache.org/repos/asf/james-project/blob/b773ace9/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/LimitTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/LimitTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/LimitTest.java
deleted file mode 100644
index 81536f1..0000000
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/utils/LimitTest.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mailbox.cassandra.mail.utils;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.List;
-import java.util.Optional;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import com.github.steveash.guavate.Guavate;
-import com.google.common.collect.ImmutableList;
-
-import nl.jqno.equalsverifier.EqualsVerifier;
-
-public class LimitTest {
-
-    private final List<Integer> aList = ImmutableList.of(1, 2, 3, 4, 5, 6);
-
-    @Rule
-    public final ExpectedException expectedException = ExpectedException.none();
-
-    @Test
-    public void unlimitedShouldCreateLimitWithNoLimit() {
-        Limit testee = Limit.unlimited();
-        assertThat(testee.getLimit()).isEqualTo(Optional.empty());
-    }
-
-    @Test
-    public void beanShouldRespectBeanContract() {
-        EqualsVerifier.forClass(Limit.class)
-            .verify();
-    }
-
-    @Test
-    public void unlimitedShouldCreateLimitThatDoesNotAffectStream() {
-
-        Limit testee = Limit.unlimited();
-        assertThat(
-            testee
-                .applyOnStream(aList.stream())
-                .collect(Guavate.toImmutableList())
-        ).isEqualTo(aList);
-    }
-
-    @Test
-    public void limitShouldCreateLimitWithNoLimit() {
-        int expected = 3;
-
-        Limit testee = Limit.limit(expected);
-        assertThat(testee.getLimit())
-            .isEqualTo(Optional.of(expected));
-    }
-
-    @Test
-    public void limitShouldCreateLimitThatCorrectlyTruncateStream() {
-        Limit testee = Limit.limit(3);
-
-        assertThat(testee
-            .applyOnStream(aList.stream())
-            .collect(Guavate.toImmutableList())
-        ).isEqualTo(ImmutableList.of(1, 2, 3));
-    }
-
-    @Test
-    public void limitShouldThrowAnErrorWhenCalledWithZero() {
-        expectedException.expect(IllegalArgumentException.class);
-        Limit.limit(0);
-    }
-
-
-    @Test
-    public void limitShouldThrowAnErrorWhenCalledWithNegativeValue() {
-        expectedException.expect(IllegalArgumentException.class);
-        Limit.limit(-1);
-    }
-
-    @Test
-    public void ofShouldTakePositiveValueAsLimit() {
-        assertThat(Limit.from(3))
-            .isEqualTo(Limit.limit(3));
-    }
-
-    @Test
-    public void ofShouldTakeNegativeValueAsUnlimited() {
-        assertThat(Limit.from(-1))
-            .isEqualTo(Limit.unlimited());
-    }
-
-    @Test
-    public void ofShouldTakeZeroValueAsUnlimited() {
-        assertThat(Limit.from(0))
-            .isEqualTo(Limit.unlimited());
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/b773ace9/server/container/util-java8/src/main/java/org/apache/james/util/streams/Limit.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/streams/Limit.java b/server/container/util-java8/src/main/java/org/apache/james/util/streams/Limit.java
new file mode 100644
index 0000000..b3ba512
--- /dev/null
+++ b/server/container/util-java8/src/main/java/org/apache/james/util/streams/Limit.java
@@ -0,0 +1,76 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.util.streams;
+
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Stream;
+
+import com.google.common.base.Preconditions;
+
+public class Limit {
+
+    public static Limit from(int limit) {
+        if (limit > 0) {
+            return new Limit(Optional.of(limit));
+        } else {
+            return unlimited();
+        }
+    }
+
+    public static Limit unlimited() {
+        return new Limit(Optional.empty());
+    }
+
+    public static Limit limit(int limit) {
+        Preconditions.checkArgument(limit > 0, "limit should be positive");
+        return new Limit(Optional.of(limit));
+    }
+
+    private final Optional<Integer> limit;
+
+    private Limit(Optional<Integer> limit) {
+        this.limit = limit;
+    }
+
+    public Optional<Integer> getLimit() {
+        return limit;
+    }
+
+    public <T> Stream<T> applyOnStream(Stream<T> stream) {
+        return limit
+            .map(stream::limit)
+            .orElse(stream);
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof Limit) {
+            Limit other = (Limit) o;
+            return Objects.equals(limit, other.limit);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(limit);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/b773ace9/server/container/util-java8/src/test/java/org/apache/james/util/streams/LimitTest.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/test/java/org/apache/james/util/streams/LimitTest.java b/server/container/util-java8/src/test/java/org/apache/james/util/streams/LimitTest.java
new file mode 100644
index 0000000..fcd92d8
--- /dev/null
+++ b/server/container/util-java8/src/test/java/org/apache/james/util/streams/LimitTest.java
@@ -0,0 +1,115 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.util.streams;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.github.steveash.guavate.Guavate;
+import com.google.common.collect.ImmutableList;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class LimitTest {
+
+    private final List<Integer> aList = ImmutableList.of(1, 2, 3, 4, 5, 6);
+
+    @Rule
+    public final ExpectedException expectedException = ExpectedException.none();
+
+    @Test
+    public void unlimitedShouldCreateLimitWithNoLimit() {
+        Limit testee = Limit.unlimited();
+        assertThat(testee.getLimit()).isEqualTo(Optional.empty());
+    }
+
+    @Test
+    public void beanShouldRespectBeanContract() {
+        EqualsVerifier.forClass(Limit.class)
+            .verify();
+    }
+
+    @Test
+    public void unlimitedShouldCreateLimitThatDoesNotAffectStream() {
+
+        Limit testee = Limit.unlimited();
+        assertThat(
+            testee
+                .applyOnStream(aList.stream())
+                .collect(Guavate.toImmutableList())
+        ).isEqualTo(aList);
+    }
+
+    @Test
+    public void limitShouldCreateLimitWithNoLimit() {
+        int expected = 3;
+
+        Limit testee = Limit.limit(expected);
+        assertThat(testee.getLimit())
+            .isEqualTo(Optional.of(expected));
+    }
+
+    @Test
+    public void limitShouldCreateLimitThatCorrectlyTruncateStream() {
+        Limit testee = Limit.limit(3);
+
+        assertThat(testee
+            .applyOnStream(aList.stream())
+            .collect(Guavate.toImmutableList())
+        ).isEqualTo(ImmutableList.of(1, 2, 3));
+    }
+
+    @Test
+    public void limitShouldThrowAnErrorWhenCalledWithZero() {
+        expectedException.expect(IllegalArgumentException.class);
+        Limit.limit(0);
+    }
+
+
+    @Test
+    public void limitShouldThrowAnErrorWhenCalledWithNegativeValue() {
+        expectedException.expect(IllegalArgumentException.class);
+        Limit.limit(-1);
+    }
+
+    @Test
+    public void ofShouldTakePositiveValueAsLimit() {
+        assertThat(Limit.from(3))
+            .isEqualTo(Limit.limit(3));
+    }
+
+    @Test
+    public void ofShouldTakeNegativeValueAsUnlimited() {
+        assertThat(Limit.from(-1))
+            .isEqualTo(Limit.unlimited());
+    }
+
+    @Test
+    public void ofShouldTakeZeroValueAsUnlimited() {
+        assertThat(Limit.from(0))
+            .isEqualTo(Limit.unlimited());
+    }
+}
\ No newline at end of file


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


[05/11] james-project git commit: JAMES-2295 A zeroed limit should be invalid

Posted by bt...@apache.org.
JAMES-2295 A zeroed limit should be invalid


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

Branch: refs/heads/master
Commit: 452183a17e39d7df8b20b018204f2d967a6ec452
Parents: d423ef0
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Mon Jan 22 17:36:12 2018 +0100
Committer: benwa <bt...@linagora.com>
Committed: Wed Jan 24 14:58:37 2018 +0700

----------------------------------------------------------------------
 .../webadmin/routes/MailRepositoriesRoutes.java | 21 ++++++++++++++++----
 .../routes/MailRepositoriesRoutesTest.java      | 10 ++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/452183a1/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
index 1cc7a06..529dfd5 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
@@ -91,9 +91,9 @@ public class MailRepositoriesRoutes implements Routes {
             required = false,
             paramType = "query parameter",
             dataType = "Integer",
-            defaultValue = "0",
+            defaultValue = "absent",
             example = "?limit=100",
-            value = "If present, fixes the maximal number of key returned in that call.")
+            value = "If present, fixes the maximal number of key returned in that call. Must be more than zero if specified.")
     })
     @ApiResponses(value = {
         @ApiResponse(code = HttpStatus.OK_200, message = "The list of all mails in a repository", response = List.class),
@@ -103,8 +103,10 @@ public class MailRepositoriesRoutes implements Routes {
     public void defineListMails() {
         service.get(MAIL_REPOSITORIES + "/:encodedUrl/mails", (request, response) -> {
             int offset = asInteger(request, "offset").orElse(NO_OFFSET);
-            Limit limit = Limit.from(asInteger(request, "limit"));
-            String url = URLDecoder.decode(request.params("encodedUrl"), StandardCharsets.UTF_8.displayName());
+            Limit limit = Limit.from(asInteger(request, "limit")
+                .map(value -> keepNotZero(value, "limit")));
+            String encodedUrl = request.params("encodedUrl");
+            String url = URLDecoder.decode(encodedUrl, StandardCharsets.UTF_8.displayName());
             try {
                 return repositoryStoreService.listMails(url, offset, limit);
             } catch (MailRepositoryStore.MailRepositoryStoreException| MessagingException e) {
@@ -157,4 +159,15 @@ public class MailRepositoriesRoutes implements Routes {
         }
         return value;
     }
+
+    private int keepNotZero(int value, String parameterName) {
+        if (value == 0) {
+            throw ErrorResponder.builder()
+                .statusCode(HttpStatus.BAD_REQUEST_400)
+                .type(ErrorResponder.ErrorType.INVALID_ARGUMENT)
+                .message(parameterName + " can not be equal to zero")
+                .haltError();
+        }
+        return value;
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/452183a1/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
index ddac73d..d318715 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
@@ -267,4 +267,14 @@ public class MailRepositoriesRoutesTest {
             .body("mailKey", containsInAnyOrder("name1", "name2"));
     }
 
+    @Test
+    public void zeroLimitShouldNotBeValid() throws Exception {
+        when()
+            .get(MY_REPO_MAILS + "?limit=0")
+        .then()
+            .statusCode(HttpStatus.BAD_REQUEST_400)
+            .body("statusCode", is(400))
+            .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
+            .body("message", is("limit can not be equal to zero"));
+    }
 }


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


[07/11] james-project git commit: JAMES-2993 Introduce Webadmin module for mail repository

Posted by bt...@apache.org.
JAMES-2993 Introduce Webadmin module for mail repository


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

Branch: refs/heads/master
Commit: d0a26a97a66bab3ef84e9f35c5b8c920d1e0d9fc
Parents: 70ec316
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Fri Jan 19 16:15:54 2018 +0100
Committer: benwa <bt...@linagora.com>
Committed: Wed Jan 24 14:58:37 2018 +0700

----------------------------------------------------------------------
 pom.xml                                         |   5 +
 server/protocols/webadmin/pom.xml               |   1 +
 .../webadmin/webadmin-mailrepository/pom.xml    | 143 +++++++++++++++++++
 3 files changed, 149 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d0a26a97/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index d91877c..3b888f0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1234,6 +1234,11 @@
             </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
+                <artifactId>james-server-mailrepository-memory</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
                 <artifactId>james-server-mailets</artifactId>
                 <version>${project.version}</version>
             </dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0a26a97/server/protocols/webadmin/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/pom.xml b/server/protocols/webadmin/pom.xml
index 7af36c5..eefbf4a 100644
--- a/server/protocols/webadmin/pom.xml
+++ b/server/protocols/webadmin/pom.xml
@@ -37,6 +37,7 @@
         <module>webadmin-core</module>
         <module>webadmin-data</module>
         <module>webadmin-mailbox</module>
+        <module>webadmin-mailrepository</module>
         <module>webadmin-swagger</module>
     </modules>
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0a26a97/server/protocols/webadmin/webadmin-mailrepository/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/pom.xml b/server/protocols/webadmin/webadmin-mailrepository/pom.xml
new file mode 100644
index 0000000..367ea83
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailrepository/pom.xml
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements. See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership. The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License. You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied. See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.james</groupId>
+        <artifactId>james-server</artifactId>
+        <version>3.1.0-SNAPSHOT</version>
+        <relativePath>../../../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>james-server-webadmin-mailrepository</artifactId>
+    <packaging>jar</packaging>
+
+    <name>Apache James :: Server :: Web Admin :: MailRepository</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>apache-mailet-base</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-data-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-mailrepository-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-mailrepository-memory</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-util-java8</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-webadmin-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>james-server-webadmin-core</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.jayway.restassured</groupId>
+            <artifactId>rest-assured</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.inject</groupId>
+            <artifactId>javax.inject</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.github.kongchen</groupId>
+                <artifactId>swagger-maven-plugin</artifactId>
+                <configuration>
+                    <apiSources>
+                        <apiSource>
+                            <springmvc>false</springmvc>
+                            <locations>org.apache.james.webadmin</locations>
+                            <info>
+                                <title>Swagger Maven Plugin</title>
+                                <version>v1</version>
+                            </info>
+                            <swaggerDirectory>${project.build.directory}</swaggerDirectory>
+                            <swaggerFileName>webadmin-mailrepository</swaggerFileName>
+                        </apiSource>
+                    </apiSources>
+                </configuration>
+                <executions>
+                    <execution>
+                        <phase>compile</phase>
+                        <goals>
+                            <goal>generate</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>


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


[09/11] james-project git commit: JAMES-2293 encodedUrl should be named id

Posted by bt...@apache.org.
JAMES-2293 encodedUrl should be named id


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

Branch: refs/heads/master
Commit: 21e1b55f08268edb5abf6ed65696e254b8f49c5e
Parents: ff8e779
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Tue Jan 23 15:45:16 2018 +0100
Committer: benwa <bt...@linagora.com>
Committed: Wed Jan 24 15:00:41 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/webadmin/dto/MailRepositoryResponse.java    | 2 +-
 .../apache/james/webadmin/routes/MailRepositoriesRoutesTest.java | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/21e1b55f/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailRepositoryResponse.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailRepositoryResponse.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailRepositoryResponse.java
index e4b43ae..6e58052 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailRepositoryResponse.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/MailRepositoryResponse.java
@@ -35,7 +35,7 @@ public class MailRepositoryResponse {
         return repository;
     }
 
-    public String getEncodedUrl() throws UnsupportedEncodingException {
+    public String getId() throws UnsupportedEncodingException {
         return URLEncoder.encode(repository, StandardCharsets.UTF_8.displayName());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/21e1b55f/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
index 52bddca..433eeaa 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
@@ -117,7 +117,7 @@ public class MailRepositoriesRoutesTest {
             .statusCode(HttpStatus.OK_200)
             .body("", hasSize(1))
             .body("[0].repository", is(URL_MY_REPO))
-            .body("[0].encodedUrl", is(URL_ESCAPED_MY_REPO));
+            .body("[0].id", is(URL_ESCAPED_MY_REPO));
     }
 
     @Test
@@ -328,7 +328,7 @@ public class MailRepositoriesRoutesTest {
             .statusCode(HttpStatus.OK_200)
             .contentType(ContentType.JSON)
             .body("repository", is(URL_MY_REPO))
-            .body("encodedUrl", is(URL_ESCAPED_MY_REPO));
+            .body("id", is(URL_ESCAPED_MY_REPO));
     }
 
     @Test


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


[10/11] james-project git commit: JAMES-2293 WebAdmin should allow to retrieve a MailRepository size

Posted by bt...@apache.org.
JAMES-2293 WebAdmin should allow to retrieve a MailRepository size


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

Branch: refs/heads/master
Commit: ff8e7790b64a1c6995d0ff8c5518b077d0f1af83
Parents: 438c3a4
Author: benwa <bt...@linagora.com>
Authored: Mon Jan 22 12:55:49 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jan 24 15:00:41 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/util/streams/Offset.java   | 66 +++++++++++++++
 .../apache/james/util/streams/OffsetTest.java   | 59 +++++++++++++
 .../mailrepository/file/MBoxMailRepository.java |  1 -
 .../memory/MemoryMailRepository.java            |  2 -
 .../dto/ExtendedMailRepositoryResponse.java     | 34 ++++++++
 .../webadmin/routes/MailRepositoriesRoutes.java | 73 ++++++++++++----
 .../service/MailRepositoryStoreService.java     | 25 ++++--
 .../routes/MailRepositoriesRoutesTest.java      | 87 +++++++++++++++++++-
 .../service/MailRepositoryStoreServiceTest.java | 11 ++-
 9 files changed, 325 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ff8e7790/server/container/util-java8/src/main/java/org/apache/james/util/streams/Offset.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/main/java/org/apache/james/util/streams/Offset.java b/server/container/util-java8/src/main/java/org/apache/james/util/streams/Offset.java
new file mode 100644
index 0000000..109ecae
--- /dev/null
+++ b/server/container/util-java8/src/main/java/org/apache/james/util/streams/Offset.java
@@ -0,0 +1,66 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.util.streams;
+
+import java.util.Objects;
+import java.util.Optional;
+
+import com.google.common.base.Preconditions;
+
+public class Offset {
+
+    public static Offset from(Optional<Integer> offset) {
+        return offset.map(Offset::from)
+            .orElse(none());
+    }
+
+    public static Offset none() {
+        return new Offset(0);
+    }
+
+    public static Offset from(int offset) {
+        Preconditions.checkArgument(offset >= 0, "offset should be positive");
+        return new Offset(offset);
+    }
+
+    private final int offset;
+
+    private Offset(int offset) {
+        this.offset = offset;
+    }
+
+    public int getOffset() {
+        return offset;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof Offset) {
+            Offset other = (Offset) o;
+            return Objects.equals(this.offset, other.offset);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(offset);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff8e7790/server/container/util-java8/src/test/java/org/apache/james/util/streams/OffsetTest.java
----------------------------------------------------------------------
diff --git a/server/container/util-java8/src/test/java/org/apache/james/util/streams/OffsetTest.java b/server/container/util-java8/src/test/java/org/apache/james/util/streams/OffsetTest.java
new file mode 100644
index 0000000..5a5b2b0
--- /dev/null
+++ b/server/container/util-java8/src/test/java/org/apache/james/util/streams/OffsetTest.java
@@ -0,0 +1,59 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.util.streams;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import org.junit.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class OffsetTest {
+
+    public static final int VALUE = 18;
+
+    @Test
+    public void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(Offset.class)
+            .allFieldsShouldBeUsed()
+            .verify();
+    }
+
+    @Test
+    public void fromZeroShouldBeEquivalentToNone() {
+        assertThat(Offset.from(0))
+            .isEqualTo(Offset.none());
+    }
+
+    @Test
+    public void getOffsetShouldReturnContainedValue() {
+        assertThat(Offset.from(VALUE).getOffset())
+            .isEqualTo(VALUE);
+    }
+
+    @Test
+    public void fromOptionalShouldBeEquivalentToFromValueWhenPresent() {
+        assertThat(Offset.from(Optional.of(VALUE)))
+            .isEqualTo(Offset.from(VALUE));
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff8e7790/server/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java b/server/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
index b2f7510..b0b3992 100755
--- a/server/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
+++ b/server/data/data-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
@@ -77,7 +77,6 @@ import org.apache.mailet.Mail;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.Iterators;
 import com.google.common.hash.Hashing;
 
 /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff8e7790/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java
----------------------------------------------------------------------
diff --git a/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java b/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java
index e6b0bbf..b201bc2 100644
--- a/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java
+++ b/server/mailrepository/mailrepository-memory/src/main/java/org/apache/james/mailrepository/memory/MemoryMailRepository.java
@@ -23,8 +23,6 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.concurrent.ConcurrentHashMap;
 
-import javax.mail.MessagingException;
-
 import org.apache.james.mailrepository.api.MailRepository;
 import org.apache.mailet.Mail;
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff8e7790/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/ExtendedMailRepositoryResponse.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/ExtendedMailRepositoryResponse.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/ExtendedMailRepositoryResponse.java
new file mode 100644
index 0000000..c8258be
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/dto/ExtendedMailRepositoryResponse.java
@@ -0,0 +1,34 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.dto;
+
+public class ExtendedMailRepositoryResponse extends MailRepositoryResponse {
+
+    private final long size;
+
+    public ExtendedMailRepositoryResponse(String repository, long size) {
+        super(repository);
+        this.size = size;
+    }
+
+    public long getSize() {
+        return size;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff8e7790/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
index 529dfd5..9250946 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/routes/MailRepositoriesRoutes.java
@@ -32,9 +32,12 @@ import javax.ws.rs.Produces;
 
 import org.apache.james.mailrepository.api.MailRepositoryStore;
 import org.apache.james.util.streams.Limit;
+import org.apache.james.util.streams.Offset;
 import org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.dto.ExtendedMailRepositoryResponse;
 import org.apache.james.webadmin.service.MailRepositoryStoreService;
 import org.apache.james.webadmin.utils.ErrorResponder;
+import org.apache.james.webadmin.utils.ErrorResponder.ErrorType;
 import org.apache.james.webadmin.utils.JsonTransformer;
 import org.eclipse.jetty.http.HttpStatus;
 
@@ -55,7 +58,6 @@ import spark.Service;
 public class MailRepositoriesRoutes implements Routes {
 
     public static final String MAIL_REPOSITORIES = "mailRepositories";
-    public static final int NO_OFFSET = 0;
 
     private final JsonTransformer jsonTransformer;
     private final MailRepositoryStoreService repositoryStoreService;
@@ -74,6 +76,8 @@ public class MailRepositoriesRoutes implements Routes {
         defineGetMailRepositories();
 
         defineListMails();
+
+        defineGetMailRepository();
     }
 
     @GET
@@ -82,6 +86,7 @@ public class MailRepositoriesRoutes implements Routes {
     @ApiImplicitParams({
         @ApiImplicitParam(
             required = false,
+            name = "offset",
             paramType = "query parameter",
             dataType = "Integer",
             defaultValue = "0",
@@ -90,6 +95,7 @@ public class MailRepositoriesRoutes implements Routes {
         @ApiImplicitParam(
             required = false,
             paramType = "query parameter",
+            name = "limit",
             dataType = "Integer",
             defaultValue = "absent",
             example = "?limit=100",
@@ -97,19 +103,26 @@ public class MailRepositoriesRoutes implements Routes {
     })
     @ApiResponses(value = {
         @ApiResponse(code = HttpStatus.OK_200, message = "The list of all mails in a repository", response = List.class),
-        @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side."),
-        @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad request - invalid parameter")
+        @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad request - invalid parameter"),
+        @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The repository does not exist", response = ErrorResponder.class),
+        @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.")
     })
     public void defineListMails() {
         service.get(MAIL_REPOSITORIES + "/:encodedUrl/mails", (request, response) -> {
-            int offset = asInteger(request, "offset").orElse(NO_OFFSET);
-            Limit limit = Limit.from(asInteger(request, "limit")
-                .map(value -> keepNotZero(value, "limit")));
+            Offset offset = Offset.from(assertPositiveInteger(request, "offset"));
+            Limit limit = Limit.from(assertPositiveInteger(request, "limit")
+                .map(value -> assertNotZero(value, "limit")));
             String encodedUrl = request.params("encodedUrl");
             String url = URLDecoder.decode(encodedUrl, StandardCharsets.UTF_8.displayName());
             try {
-                return repositoryStoreService.listMails(url, offset, limit);
-            } catch (MailRepositoryStore.MailRepositoryStoreException| MessagingException e) {
+                return repositoryStoreService.listMails(url, offset, limit)
+                    .orElseThrow(() -> ErrorResponder.builder()
+                            .statusCode(HttpStatus.NOT_FOUND_404)
+                            .type(ErrorType.NOT_FOUND)
+                            .message("The repository " + encodedUrl + "(decoded value: '" + url + "') does not exist")
+                            .haltError());
+
+            } catch (MailRepositoryStore.MailRepositoryStoreException | MessagingException e) {
                 throw ErrorResponder.builder()
                     .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
                     .type(ErrorResponder.ErrorType.SERVER_ERROR)
@@ -127,18 +140,48 @@ public class MailRepositoriesRoutes implements Routes {
         @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.")
     })
     public void defineGetMailRepositories() {
-        service.get(MAIL_REPOSITORIES, (request, response) -> {
-            response.status(HttpStatus.OK_200);
-            return repositoryStoreService.listMailRepositories();
+        service.get(MAIL_REPOSITORIES,
+            (request, response) -> repositoryStoreService.listMailRepositories(),
+            jsonTransformer);
+    }
+
+    @GET
+    @Path("/{encodedUrl}")
+    @ApiOperation(value = "Reading the information of a repository, such as size (can take some time to compute)")
+    @ApiResponses(value = {
+        @ApiResponse(code = HttpStatus.OK_200, message = "The repository information", response = List.class),
+        @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The repository does not exist", response = ErrorResponder.class),
+        @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side."),
+    })
+    public void defineGetMailRepository() {
+        service.get(MAIL_REPOSITORIES + "/:encodedUrl", (request, response) -> {
+            String encodedUrl = request.params("encodedUrl");
+            String url = URLDecoder.decode(encodedUrl, StandardCharsets.UTF_8.displayName());
+            try {
+                long size = repositoryStoreService.size(url)
+                    .orElseThrow(() -> ErrorResponder.builder()
+                            .statusCode(HttpStatus.NOT_FOUND_404)
+                            .type(ErrorType.NOT_FOUND)
+                            .message("The repository " + encodedUrl + "(decoded value: '" + url + "') does not exist")
+                            .haltError());
+                return new ExtendedMailRepositoryResponse(url, size);
+            } catch (MailRepositoryStore.MailRepositoryStoreException | MessagingException e) {
+                throw ErrorResponder.builder()
+                    .statusCode(HttpStatus.INTERNAL_SERVER_ERROR_500)
+                    .type(ErrorResponder.ErrorType.SERVER_ERROR)
+                    .cause(e)
+                    .message("Error while retrieving mail repository information")
+                    .haltError();
+            }
         }, jsonTransformer);
     }
 
-    private Optional<Integer> asInteger(Request request, String parameterName) {
+    private Optional<Integer> assertPositiveInteger(Request request, String parameterName) {
         try {
             return Optional.ofNullable(request.queryParams(parameterName))
                 .filter(s -> !Strings.isNullOrEmpty(s))
                 .map(Integer::valueOf)
-                .map(value -> keepPositive(value, parameterName));
+                .map(value -> assertPositive(value, parameterName));
         } catch (NumberFormatException e) {
             throw ErrorResponder.builder()
                 .statusCode(HttpStatus.BAD_REQUEST_400)
@@ -149,7 +192,7 @@ public class MailRepositoriesRoutes implements Routes {
         }
     }
 
-    private int keepPositive(int value, String parameterName) {
+    private int assertPositive(int value, String parameterName) {
         if (value < 0) {
             throw ErrorResponder.builder()
                 .statusCode(HttpStatus.BAD_REQUEST_400)
@@ -160,7 +203,7 @@ public class MailRepositoriesRoutes implements Routes {
         return value;
     }
 
-    private int keepNotZero(int value, String parameterName) {
+    private int assertNotZero(int value, String parameterName) {
         if (value == 0) {
             throw ErrorResponder.builder()
                 .statusCode(HttpStatus.BAD_REQUEST_400)

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff8e7790/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
index 8be5c44..996b0a2 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/main/java/org/apache/james/webadmin/service/MailRepositoryStoreService.java
@@ -20,6 +20,7 @@
 package org.apache.james.webadmin.service;
 
 import java.util.List;
+import java.util.Optional;
 
 import javax.inject.Inject;
 import javax.mail.MessagingException;
@@ -28,9 +29,12 @@ import org.apache.james.mailrepository.api.MailRepository;
 import org.apache.james.mailrepository.api.MailRepositoryStore;
 import org.apache.james.util.streams.Iterators;
 import org.apache.james.util.streams.Limit;
+import org.apache.james.util.streams.Offset;
 import org.apache.james.webadmin.dto.MailKey;
 import org.apache.james.webadmin.dto.MailRepositoryResponse;
 
+import com.github.fge.lambdas.Throwing;
+import com.github.fge.lambdas.functions.ThrowingFunction;
 import com.github.steveash.guavate.Guavate;
 
 public class MailRepositoryStoreService {
@@ -48,13 +52,22 @@ public class MailRepositoryStoreService {
             .collect(Guavate.toImmutableList());
     }
 
-    public List<MailKey> listMails(String url, long offset, Limit limit) throws MailRepositoryStore.MailRepositoryStoreException, MessagingException {
-        MailRepository mailRepository = mailRepositoryStore.select(url);
+    public Optional<List<MailKey>> listMails(String url, Offset offset, Limit limit) throws MailRepositoryStore.MailRepositoryStoreException, MessagingException {
+        Optional<MailRepository> mailRepository = Optional.ofNullable(mailRepositoryStore.select(url));
+        ThrowingFunction<MailRepository, List<MailKey>> list = repository -> list(repository, offset, limit);
+        return mailRepository.map(Throwing.function(list).sneakyThrow());
+    }
+
+    private List<MailKey> list(MailRepository mailRepository, Offset offset, Limit limit) throws MessagingException {
         return limit.applyOnStream(
-            Iterators.toStream(mailRepository.list())
-                .skip(offset))
-            .map(MailKey::new)
-            .collect(Guavate.toImmutableList());
+                Iterators.toStream(mailRepository.list())
+                    .skip(offset.getOffset()))
+                .map(MailKey::new)
+                .collect(Guavate.toImmutableList());
     }
 
+    public Optional<Long> size(String url) throws MailRepositoryStore.MailRepositoryStoreException, MessagingException {
+        Optional<MailRepository> mailRepository = Optional.ofNullable(mailRepositoryStore.select(url));
+        return mailRepository.map(Throwing.function(MailRepository::size).sneakyThrow());
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff8e7790/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
index d318715..52bddca 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/routes/MailRepositoriesRoutesTest.java
@@ -19,13 +19,16 @@
 
 package org.apache.james.webadmin.routes;
 
+import static com.jayway.restassured.RestAssured.given;
 import static com.jayway.restassured.RestAssured.when;
 import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
 import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
 import static org.apache.james.webadmin.WebAdminServer.NO_CONFIGURATION;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.containsInAnyOrder;
 import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.is;
 import static org.mockito.Mockito.mock;
@@ -36,7 +39,7 @@ import java.util.List;
 
 import org.apache.james.mailrepository.api.MailRepositoryStore;
 import org.apache.james.mailrepository.memory.MemoryMailRepository;
-import org.apache.james.metrics.logger.DefaultMetricFactory;
+import org.apache.james.metrics.api.NoopMetricFactory;
 import org.apache.james.webadmin.WebAdminServer;
 import org.apache.james.webadmin.WebAdminUtils;
 import org.apache.james.webadmin.service.MailRepositoryStoreService;
@@ -68,7 +71,7 @@ public class MailRepositoriesRoutesTest {
         mailRepository = new MemoryMailRepository();
 
         webAdminServer = WebAdminUtils.createWebAdminServer(
-                new DefaultMetricFactory(),
+                new NoopMetricFactory(),
                 new MailRepositoriesRoutes(new MailRepositoryStoreService(mailRepositoryStore), new JsonTransformer()));
         webAdminServer.configure(NO_CONFIGURATION);
         webAdminServer.await();
@@ -138,6 +141,14 @@ public class MailRepositoriesRoutesTest {
     }
 
     @Test
+    public void listingKeysShouldReturnNotFoundWhenNoRepository() throws Exception {
+        when()
+            .get(MY_REPO_MAILS)
+        .then()
+            .statusCode(HttpStatus.NOT_FOUND_404);
+    }
+
+    @Test
     public void listingKeysShouldReturnEmptyWhenNoMail() throws Exception {
         when(mailRepositoryStore.select(URL_MY_REPO)).thenReturn(mailRepository);
 
@@ -186,7 +197,7 @@ public class MailRepositoriesRoutesTest {
         .then()
             .statusCode(HttpStatus.OK_200)
             .body("", hasSize(1))
-            .body("mailKey", containsInAnyOrder("name2"));
+            .body("mailKey", contains("name2"));
     }
 
     @Test
@@ -227,6 +238,27 @@ public class MailRepositoriesRoutesTest {
     }
 
     @Test
+    public void listingKeysShouldReturnEmptyWhenOffsetExceedsSize() throws Exception {
+        when(mailRepositoryStore.select(URL_MY_REPO)).thenReturn(mailRepository);
+
+        mailRepository.store(FakeMail.builder()
+            .name("name1")
+            .build());
+        mailRepository.store(FakeMail.builder()
+            .name("name2")
+            .build());
+        mailRepository.store(FakeMail.builder()
+            .name("name3")
+            .build());
+
+        when()
+            .get(MY_REPO_MAILS + "?offset=5")
+            .then()
+            .statusCode(HttpStatus.OK_200)
+            .body("", hasSize(0));
+    }
+
+    @Test
     public void listingKeysShouldReturnErrorOnInvalidLimit() throws Exception {
         when()
             .get(MY_REPO_MAILS + "?limit=invalid")
@@ -277,4 +309,53 @@ public class MailRepositoriesRoutesTest {
             .body("type", is(ErrorResponder.ErrorType.INVALID_ARGUMENT.getType()))
             .body("message", is("limit can not be equal to zero"));
     }
+
+    @Test
+    public void retrievingRepositoryShouldReturnNotFoundWhenNone() throws Exception {
+        given()
+            .get(URL_ESCAPED_MY_REPO)
+        .then()
+            .statusCode(HttpStatus.NOT_FOUND_404);
+    }
+
+    @Test
+    public void retrievingRepositoryShouldReturnBasicInformation() throws Exception {
+        when(mailRepositoryStore.select(URL_MY_REPO)).thenReturn(mailRepository);
+
+        given()
+            .get(URL_ESCAPED_MY_REPO)
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .contentType(ContentType.JSON)
+            .body("repository", is(URL_MY_REPO))
+            .body("encodedUrl", is(URL_ESCAPED_MY_REPO));
+    }
+
+    @Test
+    public void retrievingRepositorySizeShouldReturnZeroWhenEmpty() throws Exception {
+        when(mailRepositoryStore.select(URL_MY_REPO)).thenReturn(mailRepository);
+
+        given()
+            .get(URL_ESCAPED_MY_REPO)
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .contentType(ContentType.JSON)
+            .body("size", equalTo(0));
+    }
+
+    @Test
+    public void retrievingRepositorySizeShouldReturnNumberOfContainedMails() throws Exception {
+        when(mailRepositoryStore.select(URL_MY_REPO)).thenReturn(mailRepository);
+
+        mailRepository.store(FakeMail.builder()
+            .name("name1")
+            .build());
+
+        given()
+            .get(URL_ESCAPED_MY_REPO)
+        .then()
+            .statusCode(HttpStatus.OK_200)
+            .contentType(ContentType.JSON)
+            .body("size", equalTo(1));
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff8e7790/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
index 9079ae6..505d5ca 100644
--- a/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
+++ b/server/protocols/webadmin/webadmin-mailrepository/src/test/java/org/apache/james/webadmin/service/MailRepositoryStoreServiceTest.java
@@ -26,9 +26,9 @@ import static org.mockito.Mockito.when;
 import org.apache.james.mailrepository.api.MailRepositoryStore;
 import org.apache.james.mailrepository.memory.MemoryMailRepository;
 import org.apache.james.util.streams.Limit;
+import org.apache.james.util.streams.Offset;
 import org.apache.james.webadmin.dto.MailKey;
 import org.apache.james.webadmin.dto.MailRepositoryResponse;
-import org.apache.james.webadmin.routes.MailRepositoriesRoutes;
 import org.apache.mailet.base.test.FakeMail;
 import org.junit.Before;
 import org.junit.Test;
@@ -80,7 +80,7 @@ public class MailRepositoryStoreServiceTest {
         when(mailRepositoryStore.select(FIRST_REPOSITORY))
             .thenThrow(new MailRepositoryStore.MailRepositoryStoreException("message"));
 
-        assertThatThrownBy(() -> testee.listMails(FIRST_REPOSITORY, MailRepositoriesRoutes.NO_OFFSET, Limit.unlimited()))
+        assertThatThrownBy(() -> testee.listMails(FIRST_REPOSITORY, Offset.none(), Limit.unlimited()))
             .isInstanceOf(MailRepositoryStore.MailRepositoryStoreException.class);
     }
 
@@ -88,7 +88,7 @@ public class MailRepositoryStoreServiceTest {
     public void listMailsShouldReturnEmptyWhenMailRepositoryIsEmpty() throws Exception {
         when(mailRepositoryStore.select(FIRST_REPOSITORY)).thenReturn(repository);
 
-        assertThat(testee.listMails(FIRST_REPOSITORY, MailRepositoriesRoutes.NO_OFFSET, Limit.unlimited()))
+        assertThat(testee.listMails(FIRST_REPOSITORY, Offset.none(), Limit.unlimited()).get())
             .isEmpty();
     }
 
@@ -103,7 +103,7 @@ public class MailRepositoryStoreServiceTest {
             .name(NAME_2)
             .build());
 
-        assertThat(testee.listMails(FIRST_REPOSITORY, MailRepositoriesRoutes.NO_OFFSET, Limit.unlimited()))
+        assertThat(testee.listMails(FIRST_REPOSITORY, Offset.none(), Limit.unlimited()).get())
             .containsOnly(new MailKey(NAME_1), new MailKey(NAME_2));
     }
 
@@ -121,8 +121,7 @@ public class MailRepositoryStoreServiceTest {
             .name("name3")
             .build());
 
-        int offset = 1;
-        assertThat(testee.listMails(FIRST_REPOSITORY, offset, Limit.from(1)))
+        assertThat(testee.listMails(FIRST_REPOSITORY, Offset.from(1), Limit.from(1)).get())
             .containsOnly(new MailKey(NAME_2));
     }
 }


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