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/07/04 08:59:05 UTC

[1/4] james-project git commit: JAMES-2450 GET quotas/domain/domain.tld should return scoped information

Repository: james-project
Updated Branches:
  refs/heads/master 3f8423860 -> 5c7ac5122


JAMES-2450 GET quotas/domain/domain.tld should return scoped information

This enables a smarter admin display, allowing:

 - Displaying effective limit for that domain
 - As well as defined limit for that domain

This distinction, done on the user endpoints but not on the domain one, would
have required fetching global endpoints as well as assuming scoping logic in client
code.


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

Branch: refs/heads/master
Commit: 3448c5e9ebfd84c4f13948c2c5d5de9135a8ce63
Parents: 3f84238
Author: benwa <bt...@linagora.com>
Authored: Tue Jul 3 11:14:13 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jul 4 15:58:10 2018 +0700

----------------------------------------------------------------------
 .../james/mailbox/quota/MaxQuotaManager.java    | 15 ++++
 .../james/webadmin/dto/QuotaDomainDTO.java      | 82 ++++++++++++++++++++
 .../webadmin/routes/DomainQuotaRoutes.java      |  3 +-
 .../webadmin/service/DomainQuotaService.java    | 20 +++--
 .../webadmin/routes/DomainQuotaRoutesTest.java  | 75 +++++++++++++++---
 src/site/markdown/server/manage-webadmin.md     | 25 +++++-
 6 files changed, 204 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3448c5e9/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java
index 884ed14..c5b6f68 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/quota/MaxQuotaManager.java
@@ -28,6 +28,9 @@ import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.Quota;
 import org.apache.james.mailbox.model.QuotaRoot;
+import org.apache.james.util.OptionalUtils;
+
+import com.github.fge.lambdas.Throwing;
 
 /**
  * This interface describe how to set the max quotas for users
@@ -136,4 +139,16 @@ public interface MaxQuotaManager {
     Optional<QuotaSize> getDomainMaxStorage(Domain domain);
 
     void removeDomainMaxStorage(Domain domain) throws MailboxException;
+
+    default Optional<QuotaCount> getComputedMaxMessage(Domain domain) throws MailboxException {
+        return OptionalUtils.orSuppliers(
+            Throwing.supplier(() -> getDomainMaxMessage(domain)).sneakyThrow(),
+            Throwing.supplier(this::getGlobalMaxMessage).sneakyThrow());
+    }
+
+    default Optional<QuotaSize> getComputedMaxStorage(Domain domain) throws MailboxException {
+        return OptionalUtils.orSuppliers(
+            Throwing.supplier(() -> getDomainMaxStorage(domain)).sneakyThrow(),
+            Throwing.supplier(this::getGlobalMaxStorage).sneakyThrow());
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/3448c5e9/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/QuotaDomainDTO.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/QuotaDomainDTO.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/QuotaDomainDTO.java
new file mode 100644
index 0000000..527491f
--- /dev/null
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/dto/QuotaDomainDTO.java
@@ -0,0 +1,82 @@
+/****************************************************************
+ * 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.Optional;
+
+public class QuotaDomainDTO {
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public static class Builder {
+        private Optional<QuotaDTO> global;
+        private Optional<QuotaDTO> domain;
+        private Optional<QuotaDTO> computed;
+
+        private Builder() {
+            global = Optional.empty();
+            computed = Optional.empty();
+        }
+
+        public Builder global(QuotaDTO.Builder global) {
+            this.global = Optional.of(global.build());
+            return this;
+        }
+
+        public Builder domain(QuotaDTO.Builder domain) {
+            this.domain = Optional.of(domain.build());
+            return this;
+        }
+
+        public Builder computed(QuotaDTO.Builder computed) {
+            this.computed = Optional.of(computed.build());
+            return this;
+        }
+
+        public QuotaDomainDTO build() {
+            return new QuotaDomainDTO(global, domain, computed);
+        }
+    }
+
+    private final Optional<QuotaDTO> global;
+    private final Optional<QuotaDTO> domain;
+    private final Optional<QuotaDTO> computed;
+
+    private QuotaDomainDTO(Optional<QuotaDTO> global, Optional<QuotaDTO> domain, Optional<QuotaDTO> computed) {
+        this.global = global;
+        this.domain = domain;
+        this.computed = computed;
+    }
+
+    public Optional<QuotaDTO> getGlobal() {
+        return global;
+    }
+
+    public Optional<QuotaDTO> getDomain() {
+        return domain;
+    }
+
+    public Optional<QuotaDTO> getComputed() {
+        return computed;
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/3448c5e9/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaRoutes.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaRoutes.java
index 5c40253..b028946 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaRoutes.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/DomainQuotaRoutes.java
@@ -39,6 +39,7 @@ import org.apache.james.user.api.UsersRepository;
 import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.webadmin.Routes;
 import org.apache.james.webadmin.dto.QuotaDTO;
+import org.apache.james.webadmin.dto.QuotaDomainDTO;
 import org.apache.james.webadmin.service.DomainQuotaService;
 import org.apache.james.webadmin.utils.ErrorResponder;
 import org.apache.james.webadmin.utils.ErrorResponder.ErrorType;
@@ -137,7 +138,7 @@ public class DomainQuotaRoutes implements Routes {
         notes = "If there is no limitation for count and/or size, the returned value will be -1"
     )
     @ApiResponses(value = {
-            @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = QuotaDTO.class),
+            @ApiResponse(code = HttpStatus.OK_200, message = "OK", response = QuotaDomainDTO.class),
             @ApiResponse(code = HttpStatus.NOT_FOUND_404, message = "The requested domain can not be found."),
             @ApiResponse(code = HttpStatus.METHOD_NOT_ALLOWED_405, message = "Domain Quota configuration not supported when virtual hosting is desactivated."),
             @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, message = "Internal server error - Something went bad on the server side.")

http://git-wip-us.apache.org/repos/asf/james-project/blob/3448c5e9/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/DomainQuotaService.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/DomainQuotaService.java b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/DomainQuotaService.java
index 525e041..2b59837 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/DomainQuotaService.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/service/DomainQuotaService.java
@@ -29,6 +29,7 @@ import org.apache.james.core.quota.QuotaSize;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.quota.MaxQuotaManager;
 import org.apache.james.webadmin.dto.QuotaDTO;
+import org.apache.james.webadmin.dto.QuotaDomainDTO;
 
 import com.github.fge.lambdas.Throwing;
 
@@ -65,11 +66,20 @@ public class DomainQuotaService {
         maxQuotaManager.removeDomainMaxStorage(domain);
     }
 
-    public QuotaDTO getQuota(Domain domain) {
-        return QuotaDTO
-            .builder()
-            .count(maxQuotaManager.getDomainMaxMessage(domain))
-            .size(maxQuotaManager.getDomainMaxStorage(domain))
+    public QuotaDomainDTO getQuota(Domain domain) throws MailboxException {
+        return QuotaDomainDTO.builder()
+            .domain(QuotaDTO
+                .builder()
+                .count(maxQuotaManager.getDomainMaxMessage(domain))
+                .size(maxQuotaManager.getDomainMaxStorage(domain)))
+            .global(QuotaDTO
+                .builder()
+                .count(maxQuotaManager.getGlobalMaxMessage())
+                .size(maxQuotaManager.getGlobalMaxStorage()))
+            .computed(QuotaDTO
+                .builder()
+                .count(maxQuotaManager.getComputedMaxMessage(domain))
+                .size(maxQuotaManager.getComputedMaxStorage(domain)))
             .build();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/3448c5e9/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java
index f8548b2..db58a6b 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/DomainQuotaRoutesTest.java
@@ -21,6 +21,7 @@ package org.apache.james.webadmin.routes;
 
 import static com.jayway.restassured.RestAssured.given;
 import static com.jayway.restassured.RestAssured.when;
+import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.Map;
@@ -338,17 +339,21 @@ class DomainQuotaRoutesTest {
         int maxStorage = 42;
         maxQuotaManager.setDomainMaxStorage(TROUVÉ_COM, QuotaSize.size(maxStorage));
 
-        JsonPath jsonPath =
+        String json =
             given()
                 .get(QUOTA_DOMAINS + "/" + TROUVÉ_COM.name())
             .then()
                 .statusCode(HttpStatus.OK_200)
                 .contentType(ContentType.JSON)
                 .extract()
-                .jsonPath();
-
-        assertThat(jsonPath.getLong(SIZE)).isEqualTo(maxStorage);
-        assertThat(jsonPath.getObject(COUNT, Long.class)).isNull();
+                .asString();
+
+        assertThatJson(json)
+            .isEqualTo("{" +
+                "\"global\":{\"count\":null,\"size\":null}," +
+                "\"domain\":{\"count\":null,\"size\":42}," +
+                "\"computed\":{\"count\":null,\"size\":42}" +
+            "}");
     }
 
     @Test
@@ -356,18 +361,70 @@ class DomainQuotaRoutesTest {
         int maxMessage = 42;
         maxQuotaManager.setDomainMaxMessage(TROUVÉ_COM, QuotaCount.count(maxMessage));
 
+        String json =
+            given()
+                .get(QUOTA_DOMAINS + "/" + TROUVÉ_COM.name())
+            .then()
+                .statusCode(HttpStatus.OK_200)
+                .contentType(ContentType.JSON)
+                .extract()
+                .asString();
+
+        assertThatJson(json)
+            .isEqualTo("{" +
+                "\"global\":{\"count\":null,\"size\":null}," +
+                "\"domain\":{\"count\":42,\"size\":null}," +
+                "\"computed\":{\"count\":42,\"size\":null}" +
+            "}");
+    }
 
-        JsonPath jsonPath =
+    @Test
+    void getQuotaShouldDisplayScopesWhenUnlimited() throws Exception {
+        int maxMessage = 42;
+        maxQuotaManager.setGlobalMaxMessage(QuotaCount.unlimited());
+        maxQuotaManager.setGlobalMaxStorage(QuotaSize.size(42));
+        maxQuotaManager.setDomainMaxMessage(TROUVÉ_COM, QuotaCount.count(maxMessage));
+        maxQuotaManager.setDomainMaxStorage(TROUVÉ_COM, QuotaSize.unlimited());
+
+        String json =
             given()
                 .get(QUOTA_DOMAINS + "/" + TROUVÉ_COM.name())
             .then()
                 .statusCode(HttpStatus.OK_200)
                 .contentType(ContentType.JSON)
                 .extract()
-                .jsonPath();
+                .asString();
+
+        assertThatJson(json)
+            .isEqualTo("{" +
+                "\"global\":{\"count\":-1,\"size\":42}," +
+                "\"domain\":{\"count\":42,\"size\":-1}," +
+                "\"computed\":{\"count\":42,\"size\":-1}" +
+            "}");
+    }
 
-        assertThat(jsonPath.getObject(SIZE, Long.class)).isNull();
-        assertThat(jsonPath.getLong(COUNT)).isEqualTo(maxMessage);
+    @Test
+    void getQuotaShouldDisplayScopedInformation() throws Exception {
+        int maxMessage = 42;
+        maxQuotaManager.setDomainMaxMessage(TROUVÉ_COM, QuotaCount.count(maxMessage));
+        maxQuotaManager.setGlobalMaxMessage(QuotaCount.count(32));
+        maxQuotaManager.setGlobalMaxStorage(QuotaSize.size(36));
+
+        String json =
+            given()
+                .get(QUOTA_DOMAINS + "/" + TROUVÉ_COM.name())
+            .then()
+                .statusCode(HttpStatus.OK_200)
+                .contentType(ContentType.JSON)
+                .extract()
+                .asString();
+
+        assertThatJson(json)
+            .isEqualTo("{" +
+                "\"global\":{\"count\":32,\"size\":36}," +
+                "\"domain\":{\"count\":42,\"size\":null}," +
+                "\"computed\":{\"count\":42,\"size\":36}" +
+            "}");
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/3448c5e9/src/site/markdown/server/manage-webadmin.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md
index 8600ae5..f27459b 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -545,7 +545,30 @@ Resource name domainToBeUsed should be an existing domain. For example:
 curl -XGET http://ip:port/quota/domains/james.org
 ```
 
-The answer can contain a fixed value, an empty value (null) or an unlimited value (-1):
+The answer will detail the default quota applied to users belonging to that domain:
+
+```
+{
+  "global": {
+    "count":252,
+    "size":null
+  },
+  "domain": {
+    "count":null,
+    "size":142
+  },
+  "computed": {
+    "count":252,
+    "size":142
+  }
+}
+```
+
+ - The `global` entry represents the quota limit defined on this James server by default.
+ - The `domain` entry represents the quota limit allowed for the user of that domain by default.
+ - The `computed` entry represents the quota limit applied for the users of that domain, by default, resolved from the upper values.
+
+Note that `quota` object can contain a fixed value, an empty value (null) or an unlimited value (-1):
 
 ```
 {"count":52,"size":42}


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


[2/4] james-project git commit: JAMES-2441 Bind test dependencies in test scope

Posted by bt...@apache.org.
JAMES-2441 Bind test dependencies in test scope


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

Branch: refs/heads/master
Commit: fffdff9ac24a77fddeed14d5d78b3d474372ce1f
Parents: 3448c5e
Author: benwa <bt...@linagora.com>
Authored: Wed Jul 4 10:19:18 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jul 4 15:58:29 2018 +0700

----------------------------------------------------------------------
 server/container/guice/cassandra-ldap-guice/pom.xml | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/fffdff9a/server/container/guice/cassandra-ldap-guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-ldap-guice/pom.xml b/server/container/guice/cassandra-ldap-guice/pom.xml
index b7f64a7..84e4042 100644
--- a/server/container/guice/cassandra-ldap-guice/pom.xml
+++ b/server/container/guice/cassandra-ldap-guice/pom.xml
@@ -72,6 +72,7 @@
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>james-server-data-ldap-integration-testing</artifactId>
+            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>


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


[4/4] james-project git commit: JAMES-2441 Ensure DockerCassandraRule is used as a class rule

Posted by bt...@apache.org.
JAMES-2441 Ensure DockerCassandraRule is used as a class rule


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

Branch: refs/heads/master
Commit: 90294f66e39efd44ef77e64fb2cd790aedf58df1
Parents: fffdff9
Author: benwa <bt...@linagora.com>
Authored: Wed Jul 4 11:14:45 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jul 4 15:58:29 2018 +0700

----------------------------------------------------------------------
 .../org/apache/james/CassandraNodeConfTest.java | 29 +++++++++++---------
 .../org/apache/james/CassandraWithTikaTest.java | 14 +++++-----
 .../java/org/apache/james/ESReporterTest.java   |  8 ++++--
 .../james/JamesCapabilitiesServerTest.java      |  8 ++++--
 .../JamesServerWithRetryConnectionTest.java     |  9 +++---
 5 files changed, 39 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/90294f66/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
index 1950bd8..6747acf 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraNodeConfTest.java
@@ -30,6 +30,7 @@ import org.apache.james.backends.cassandra.init.configuration.ClusterConfigurati
 import org.apache.james.util.Host;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.testcontainers.DockerClientFactory;
@@ -43,11 +44,11 @@ public class CassandraNodeConfTest {
         return DockerClientFactory.instance().dockerHostIpAddress();
     }
 
-    private final DockerCassandraRule dockerCassandraRule = new DockerCassandraRule();
+    @ClassRule
+    public static final DockerCassandraRule dockerCassandraRule = new DockerCassandraRule();
 
     @Rule
-    public CassandraJmapTestRule cassandraJmapTestRule = new CassandraJmapTestRule(dockerCassandraRule,
-            new EmbeddedElasticSearchRule());
+    public CassandraJmapTestRule cassandraJmapTestRule = CassandraJmapTestRule.defaultTestRule();
 
     private GuiceJamesServer jamesServer;
     private SocketChannel socketChannel;
@@ -67,7 +68,7 @@ public class CassandraNodeConfTest {
 
     @Test
     public void serverShouldStartServiceWhenNodeIsReachable() throws Exception {
-        jamesServer = cassandraJmapTestRule.jmapServer();
+        jamesServer = cassandraJmapTestRule.jmapServer(dockerCassandraRule.getModule());
 
         assertThatServerStartCorrectly();
     }
@@ -77,11 +78,12 @@ public class CassandraNodeConfTest {
         String unreachableNode = "10.2.3.42";
 
 
-        jamesServer = cassandraJmapTestRule.jmapServer(
-            (binder) -> binder.bind(ClusterConfiguration.class)
-                .toInstance(clusterWithHosts(
-                    Host.from(unreachableNode, 9042),
-                    dockerCassandraRule.getHost())));
+        jamesServer = cassandraJmapTestRule.jmapServer(dockerCassandraRule.getModule())
+            .overrideWith(
+                (binder) -> binder.bind(ClusterConfiguration.class)
+                    .toInstance(clusterWithHosts(
+                        Host.from(unreachableNode, 9042),
+                        dockerCassandraRule.getHost())));
 
         assertThatServerStartCorrectly();
     }
@@ -89,10 +91,11 @@ public class CassandraNodeConfTest {
 
     @Test
     public void configShouldWorkWithNonDefaultPort() throws Exception {
-        jamesServer = cassandraJmapTestRule.jmapServer(
-            (binder) -> binder.bind(ClusterConfiguration.class)
-                .toInstance(clusterWithHosts(
-                    Host.from(getDockerHostIp(), dockerCassandraRule.getMappedPort(CASSANDRA_PORT)))));
+        jamesServer = cassandraJmapTestRule.jmapServer(dockerCassandraRule.getModule())
+            .overrideWith(
+                (binder) -> binder.bind(ClusterConfiguration.class)
+                    .toInstance(clusterWithHosts(
+                        Host.from(getDockerHostIp(), dockerCassandraRule.getMappedPort(CASSANDRA_PORT)))));
 
         assertThatServerStartCorrectly();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/90294f66/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraWithTikaTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraWithTikaTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraWithTikaTest.java
index 54b5bbf..eef9a48 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraWithTikaTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraWithTikaTest.java
@@ -21,22 +21,22 @@ package org.apache.james;
 
 import java.io.IOException;
 
+import org.junit.ClassRule;
 import org.junit.Rule;
 
 public class CassandraWithTikaTest extends AbstractJmapJamesServerTest {
 
-    private final GuiceTikaRule guiceTikaRule = new GuiceTikaRule();
+    @ClassRule
+    public static final DockerCassandraRule cassandra = new DockerCassandraRule();
+    @ClassRule
+    public static final GuiceTikaRule guiceTikaRule = new GuiceTikaRule();
 
     @Rule
-    public CassandraJmapTestRule cassandraJmap = new CassandraJmapTestRule(
-        AggregateGuiceModuleTestRule.of(
-            new EmbeddedElasticSearchRule(),
-            new DockerCassandraRule(),
-            guiceTikaRule));
+    public CassandraJmapTestRule cassandraJmap = CassandraJmapTestRule.defaultTestRule();
 
     @Override
     protected GuiceJamesServer createJamesServer() throws IOException {
-        return cassandraJmap.jmapServer(binder -> guiceTikaRule.getModule());
+        return cassandraJmap.jmapServer(guiceTikaRule.getModule(), cassandra.getModule());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/90294f66/server/container/guice/cassandra-guice/src/test/java/org/apache/james/ESReporterTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/ESReporterTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/ESReporterTest.java
index b0f555e..1c9995f 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/ESReporterTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/ESReporterTest.java
@@ -41,6 +41,7 @@ import org.elasticsearch.client.Client;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -63,19 +64,22 @@ public class ESReporterTest {
     private static final String USERNAME = "user1@" + DOMAIN;
     private static final String PASSWORD = "secret";
 
+    @ClassRule
+    public static final DockerCassandraRule cassandra = new DockerCassandraRule();
+
     private EmbeddedElasticSearchRule embeddedElasticSearchRule = new EmbeddedElasticSearchRule();
 
     private Timer timer;
 
     @Rule
-    public CassandraJmapTestRule cassandraJmap = new CassandraJmapTestRule(embeddedElasticSearchRule, new DockerCassandraRule());
+    public CassandraJmapTestRule cassandraJmap = new CassandraJmapTestRule(embeddedElasticSearchRule);
 
     private GuiceJamesServer server;
     private AccessToken accessToken;
 
     @Before
     public void setup() throws Exception {
-        server = cassandraJmap.jmapServer();
+        server = cassandraJmap.jmapServer(cassandra.getModule());
         server.start();
         server.getProbe(DataProbeImpl.class)
             .fluent()

http://git-wip-us.apache.org/repos/asf/james-project/blob/90294f66/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
index 45cc1a8..2b39d71 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java
@@ -36,6 +36,7 @@ import org.apache.james.modules.TestElasticSearchModule;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.server.core.configuration.Configuration;
 import org.junit.After;
+import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.RuleChain;
@@ -48,15 +49,16 @@ public class JamesCapabilitiesServerTest {
     private GuiceJamesServer server;
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
     private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX);
-    private DockerCassandraRule cassandraServer = new DockerCassandraRule();
+
+    @ClassRule
+    public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
     
     @Rule
-    public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch).around(cassandraServer);
+    public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch);
 
     @After
     public void teardown() {
         server.stop();
-        
     }
     
     private GuiceJamesServer createCassandraJamesServer(final MailboxManager mailboxManager) throws IOException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/90294f66/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
index 678dcc2..87397dd 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesServerWithRetryConnectionTest.java
@@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.junit.After;
 import org.junit.Before;
+import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.testcontainers.shaded.com.google.common.base.Throwables;
@@ -40,12 +41,12 @@ public class JamesServerWithRetryConnectionTest {
     private static final int IMAP_PORT = 1143;
     private static final long WAITING_TIME = TimeUnit.MILLISECONDS.convert(10, TimeUnit.SECONDS);
 
-    private final DockerCassandraRule dockerCassandraRule = new DockerCassandraRule();
+    @ClassRule
+    public static DockerCassandraRule dockerCassandraRule = new DockerCassandraRule();
     private final DockerElasticSearchRule dockerElasticSearchRule = new DockerElasticSearchRule();
 
     @Rule
-    public CassandraJmapTestRule cassandraJmapTestRule = new CassandraJmapTestRule(dockerCassandraRule,
-            dockerElasticSearchRule);
+    public CassandraJmapTestRule cassandraJmapTestRule = new CassandraJmapTestRule(dockerElasticSearchRule);
 
     private GuiceJamesServer jamesServer;
     private SocketChannel socketChannel;
@@ -68,7 +69,7 @@ public class JamesServerWithRetryConnectionTest {
 
     @Test
     public void serverShouldStartAtDefault() throws Exception {
-        jamesServer = cassandraJmapTestRule.jmapServer();
+        jamesServer = cassandraJmapTestRule.jmapServer(dockerCassandraRule.getModule());
         assertThatServerStartCorrectly();
     }
 


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


[3/4] james-project git commit: JAMES-2441 Cleanup some rule chains

Posted by bt...@apache.org.
JAMES-2441 Cleanup some rule chains


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

Branch: refs/heads/master
Commit: 5c7ac51225860cf1d951eb5e4012c1cb268fdb52
Parents: 90294f6
Author: benwa <bt...@linagora.com>
Authored: Wed Jul 4 11:15:12 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jul 4 15:58:29 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/mpt/smtp/SmtpStarttlsCommandTest.java | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/5c7ac512/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpStarttlsCommandTest.java
----------------------------------------------------------------------
diff --git a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpStarttlsCommandTest.java b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpStarttlsCommandTest.java
index efc3a28..a0c110e 100644
--- a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpStarttlsCommandTest.java
+++ b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/SmtpStarttlsCommandTest.java
@@ -24,7 +24,6 @@ import org.apache.james.mpt.script.SimpleScriptedTestProtocol;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.RuleChain;
 import org.junit.rules.TemporaryFolder;
 
 public abstract class SmtpStarttlsCommandTest {
@@ -34,10 +33,8 @@ public abstract class SmtpStarttlsCommandTest {
     public static final String USER_AT_DOMAIN = USER + "@" + DOMAIN;
     public static final String PASSWORD = "secret";
 
-    private final TemporaryFolder folder = new TemporaryFolder();
-    
     @Rule
-    public final RuleChain chain = RuleChain.outerRule(folder);
+    public final TemporaryFolder folder = new TemporaryFolder();
 
     protected abstract SmtpHostSystem createSmtpHostSystem();
     


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