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 2019/05/22 03:37:04 UTC

[james-project] branch master updated (5dc293c -> 7d7e177)

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from 5dc293c  JAMES-2774 Restart docker RabbitMQ each tests in RabbitMQEventBusTest
     new 8955b14  JAMES-2763 Startup check API should be more generic
     new 7097478  JAMES-2763 JMAP mailbox capabilities should rely on StartUpCHeck
     new 7d7e177  JAMES-2775 Linshare should be stopped in integration tests

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../james/modules/LinshareGuiceExtension.java      |   6 +
 .../CassandraSchemaVersionStartUpCheck.java        |   4 +-
 .../modules/mailbox/CassandraSessionModule.java    |   4 +-
 .../apache/james/JamesCapabilitiesServerTest.java  |  45 ++++++--
 .../org/apache/james/StartUpChecksPerformer.java   |  99 +----------------
 .../apache/james/modules/StartUpChecksModule.java  |   4 +-
 .../apache/james/StartUpChecksPerformerTest.java   |  13 ++-
 .../james/GuiceJamesServerStartUpCheckTest.java    |   2 +-
 server/container/guice/protocols/jmap/pom.xml      |   5 +
 .../java/org/apache/james/jmap/JMAPModule.java     |  73 ++++++++-----
 .../java/org/apache/james/jmap/JMAPModuleTest.java | 110 +++++++++++++++++++
 server/container/lifecycle-api/pom.xml             |   4 +
 .../apache/james/lifecycle/api/StartUpCheck.java   | 121 +++++++++++++++++++++
 ...LinshareBlobExportMechanismIntegrationTest.java |   2 +-
 ...LinshareBlobExportMechanismIntegrationTest.java |   2 +-
 15 files changed, 349 insertions(+), 145 deletions(-)
 create mode 100644 server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPModuleTest.java
 create mode 100644 server/container/lifecycle-api/src/main/java/org/apache/james/lifecycle/api/StartUpCheck.java


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


[james-project] 03/03: JAMES-2775 Linshare should be stopped in integration tests

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 7d7e1771b71b26ceab5e7a276ae269f0960f6e87
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Mon May 20 17:16:30 2019 +0700

    JAMES-2775 Linshare should be stopped in integration tests
    
    Because there is only one test class in integration tests module need this docker. When it finishes, we can stop docker linshare to save some resources
---
 .../test/java/org/apache/james/modules/LinshareGuiceExtension.java  | 6 ++++++
 .../CassandraLinshareBlobExportMechanismIntegrationTest.java        | 2 +-
 .../memory/MemoryLinshareBlobExportMechanismIntegrationTest.java    | 2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/LinshareGuiceExtension.java b/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/LinshareGuiceExtension.java
index 090395f..9ed556c 100644
--- a/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/LinshareGuiceExtension.java
+++ b/server/container/guice/blob-export-guice/src/test/java/org/apache/james/modules/LinshareGuiceExtension.java
@@ -41,6 +41,12 @@ public class LinshareGuiceExtension implements GuiceModuleTestExtension {
     }
 
     @Override
+    public void afterAll(ExtensionContext extensionContext) throws Exception {
+        linshareExtension.getLinshare()
+            .stop();
+    }
+
+    @Override
     public Module getModule() {
         return Modules.combine(
             binder -> binder.bind(BlobExportImplChoice.class)
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraLinshareBlobExportMechanismIntegrationTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraLinshareBlobExportMechanismIntegrationTest.java
index 6f5576f..9d8fb46 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraLinshareBlobExportMechanismIntegrationTest.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraLinshareBlobExportMechanismIntegrationTest.java
@@ -41,7 +41,7 @@ public class CassandraLinshareBlobExportMechanismIntegrationTest extends Linshar
 
     private static final long LIMIT_TO_10_MESSAGES = 10;
 
-    private final LinshareGuiceExtension linshareGuiceExtension = new LinshareGuiceExtension();
+    private static final LinshareGuiceExtension linshareGuiceExtension = new LinshareGuiceExtension();
 
     @RegisterExtension
     JamesServerExtension testExtension = new JamesServerBuilder()
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryLinshareBlobExportMechanismIntegrationTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryLinshareBlobExportMechanismIntegrationTest.java
index 97aa5bc..9c64f07 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryLinshareBlobExportMechanismIntegrationTest.java
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryLinshareBlobExportMechanismIntegrationTest.java
@@ -38,7 +38,7 @@ class MemoryLinshareBlobExportMechanismIntegrationTest extends LinshareBlobExpor
 
     private static final int LIMIT_TO_10_MESSAGES = 10;
 
-    private final LinshareGuiceExtension linshareGuiceExtension = new LinshareGuiceExtension();
+    private static final LinshareGuiceExtension linshareGuiceExtension = new LinshareGuiceExtension();
 
     @RegisterExtension
     JamesServerExtension jamesServerExtension = new JamesServerBuilder()


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


[james-project] 01/03: JAMES-2763 Startup check API should be more generic

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 8955b1430ed3c04aa7bab1a87f80f6c657760f68
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu May 16 10:47:22 2019 +0700

    JAMES-2763 Startup check API should be more generic
---
 .../CassandraSchemaVersionStartUpCheck.java        |   4 +-
 .../modules/mailbox/CassandraSessionModule.java    |   4 +-
 .../org/apache/james/StartUpChecksPerformer.java   |  99 +----------------
 .../apache/james/modules/StartUpChecksModule.java  |   4 +-
 .../apache/james/StartUpChecksPerformerTest.java   |  13 ++-
 .../james/GuiceJamesServerStartUpCheckTest.java    |   2 +-
 server/container/lifecycle-api/pom.xml             |   4 +
 .../apache/james/lifecycle/api/StartUpCheck.java   | 121 +++++++++++++++++++++
 8 files changed, 140 insertions(+), 111 deletions(-)

diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSchemaVersionStartUpCheck.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSchemaVersionStartUpCheck.java
index 561b8aa..2c992cb 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSchemaVersionStartUpCheck.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSchemaVersionStartUpCheck.java
@@ -19,14 +19,14 @@
 
 package org.apache.james.modules.mailbox;
 
-import org.apache.james.StartUpChecksPerformer;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager;
+import org.apache.james.lifecycle.api.StartUpCheck;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.inject.Inject;
 
-public class CassandraSchemaVersionStartUpCheck implements StartUpChecksPerformer.StartUpCheck {
+public class CassandraSchemaVersionStartUpCheck implements StartUpCheck {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(CassandraSchemaVersionStartUpCheck.class);
     static final String CHECK_NAME = "CassandraSchemaVersionStartUpCheck";
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
index 951a328..681fa26 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
@@ -23,7 +23,6 @@ import java.util.Set;
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
-import org.apache.james.StartUpChecksPerformer;
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.backends.cassandra.init.CassandraZonedDateTimeModule;
 import org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory;
@@ -35,6 +34,7 @@ import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionDAO;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionModule;
 import org.apache.james.core.healthcheck.HealthCheck;
+import org.apache.james.lifecycle.api.StartUpCheck;
 import org.apache.james.mailbox.store.BatchSizes;
 import org.apache.james.server.CassandraProbe;
 import org.apache.james.util.Host;
@@ -74,7 +74,7 @@ public class CassandraSessionModule extends AbstractModule {
         bind(CassandraSchemaVersionManager.class).in(Scopes.SINGLETON);
         bind(CassandraSchemaVersionDAO.class).in(Scopes.SINGLETON);
 
-        Multibinder.newSetBinder(binder(), StartUpChecksPerformer.StartUpCheck.class)
+        Multibinder.newSetBinder(binder(), StartUpCheck.class)
             .addBinding().to(CassandraSchemaVersionStartUpCheck.class);
 
         Multibinder.newSetBinder(binder(), GuiceProbe.class).addBinding().to(CassandraProbe.class);
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/StartUpChecksPerformer.java b/server/container/guice/guice-common/src/main/java/org/apache/james/StartUpChecksPerformer.java
index cbc52fa..b04f2c3 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/StartUpChecksPerformer.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/StartUpChecksPerformer.java
@@ -20,18 +20,17 @@
 package org.apache.james;
 
 import java.util.List;
-import java.util.Optional;
 import java.util.Set;
 
 import javax.inject.Inject;
 
+import org.apache.james.lifecycle.api.StartUpCheck;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.github.steveash.guavate.Guavate;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Joiner;
-import com.google.common.base.MoreObjects;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Sets;
 
@@ -74,102 +73,6 @@ public class StartUpChecksPerformer {
         }
     }
 
-    public interface StartUpCheck {
-
-        enum ResultType {
-            GOOD, BAD
-        }
-
-        class CheckResult {
-
-            public static class Builder {
-
-                @FunctionalInterface
-                public interface RequireCheckName {
-                    RequireResultType checkName(String name);
-                }
-
-                @FunctionalInterface
-                public interface RequireResultType {
-                    ReadyToBuild resultType(ResultType resultType);
-                }
-
-                public static class ReadyToBuild {
-                    private final String name;
-                    private final ResultType resultType;
-                    private Optional<String> description;
-
-                    ReadyToBuild(String name, ResultType resultType) {
-                        this.name = name;
-                        this.resultType = resultType;
-                        this.description = Optional.empty();
-                    }
-
-                    public ReadyToBuild description(String description) {
-                        this.description = Optional.ofNullable(description);
-                        return this;
-                    }
-
-                    public CheckResult build() {
-                        return new CheckResult(name, resultType, description);
-                    }
-                }
-
-            }
-
-            public static Builder.RequireCheckName builder() {
-                return name -> resultType -> new Builder.ReadyToBuild(name, resultType);
-            }
-
-            private final String name;
-            private final ResultType resultType;
-            private final Optional<String> description;
-
-            private CheckResult(String name, ResultType resultType, Optional<String> description) {
-                Preconditions.checkNotNull(name);
-                Preconditions.checkNotNull(resultType);
-                Preconditions.checkNotNull(description);
-
-                this.name = name;
-                this.resultType = resultType;
-                this.description = description;
-            }
-
-            public String getName() {
-                return name;
-            }
-
-            public ResultType getResultType() {
-                return resultType;
-            }
-
-            public Optional<String> getDescription() {
-                return description;
-            }
-
-            public boolean isBad() {
-                return resultType.equals(ResultType.BAD);
-            }
-
-            public boolean isGood() {
-                return resultType.equals(ResultType.GOOD);
-            }
-
-            @Override
-            public String toString() {
-                return MoreObjects.toStringHelper(this)
-                    .add("name", name)
-                    .add("resultType", resultType)
-                    .add("description", description)
-                    .toString();
-            }
-        }
-
-        CheckResult check();
-
-        String checkName();
-    }
-
     static class StartUpChecks {
 
         private final Set<StartUpCheck> startUpChecks;
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/StartUpChecksModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/StartUpChecksModule.java
index 9f7484d..99cdc8f 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/StartUpChecksModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/StartUpChecksModule.java
@@ -19,7 +19,7 @@
 
 package org.apache.james.modules;
 
-import org.apache.james.StartUpChecksPerformer;
+import org.apache.james.lifecycle.api.StartUpCheck;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.multibindings.Multibinder;
@@ -28,6 +28,6 @@ public class StartUpChecksModule extends AbstractModule {
 
     @Override
     protected void configure() {
-        Multibinder.newSetBinder(binder(), StartUpChecksPerformer.StartUpCheck.class);
+        Multibinder.newSetBinder(binder(), StartUpCheck.class);
     }
 }
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/StartUpChecksPerformerTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/StartUpChecksPerformerTest.java
index cddb6e9..23abb96 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/StartUpChecksPerformerTest.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/StartUpChecksPerformerTest.java
@@ -23,15 +23,16 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import org.apache.james.StartUpChecksPerformer.StartUpCheck.CheckResult;
-import org.apache.james.StartUpChecksPerformer.StartUpCheck.ResultType;
+import org.apache.james.lifecycle.api.StartUpCheck;
+import org.apache.james.lifecycle.api.StartUpCheck.CheckResult;
+import org.apache.james.lifecycle.api.StartUpCheck.ResultType;
 import org.junit.jupiter.api.Test;
 
 class StartUpChecksPerformerTest {
 
     private static final CheckResult GOOD_CHECK_1 = CheckResult.builder()
         .checkName("good 1")
-        .resultType(ResultType.GOOD)
+        .resultType(StartUpCheck.ResultType.GOOD)
         .build();
     private static final CheckResult GOOD_CHECK_2 = CheckResult.builder()
         .checkName("good 2")
@@ -46,8 +47,8 @@ class StartUpChecksPerformerTest {
         .resultType(ResultType.BAD)
         .build();
 
-    private static StartUpChecksPerformer.StartUpCheck fromResult(CheckResult checkResult) {
-        return new StartUpChecksPerformer.StartUpCheck() {
+    private static StartUpCheck fromResult(CheckResult checkResult) {
+        return new StartUpCheck() {
 
             @Override
             public CheckResult check() {
@@ -110,7 +111,7 @@ class StartUpChecksPerformerTest {
         String checkName = "throwing check name";
         StartUpChecksPerformer checksPerformer = StartUpChecksPerformer.from(
 
-            new StartUpChecksPerformer.StartUpCheck() {
+            new StartUpCheck() {
                 @Override
                 public CheckResult check() {
                     throw new RuntimeException("unexpected");
diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceJamesServerStartUpCheckTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceJamesServerStartUpCheckTest.java
index ddf136d..61101f4 100644
--- a/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceJamesServerStartUpCheckTest.java
+++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/GuiceJamesServerStartUpCheckTest.java
@@ -25,7 +25,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import java.util.List;
 import java.util.stream.Stream;
 
-import org.apache.james.StartUpChecksPerformer.StartUpCheck;
+import org.apache.james.lifecycle.api.StartUpCheck;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.store.search.PDFTextExtractor;
 import org.apache.james.modules.BlobExportImplChoice;
diff --git a/server/container/lifecycle-api/pom.xml b/server/container/lifecycle-api/pom.xml
index 7dbc3eb..4c9e47a 100644
--- a/server/container/lifecycle-api/pom.xml
+++ b/server/container/lifecycle-api/pom.xml
@@ -34,6 +34,10 @@
 
     <dependencies>
         <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
             <groupId>commons-configuration</groupId>
             <artifactId>commons-configuration</artifactId>
         </dependency>
diff --git a/server/container/lifecycle-api/src/main/java/org/apache/james/lifecycle/api/StartUpCheck.java b/server/container/lifecycle-api/src/main/java/org/apache/james/lifecycle/api/StartUpCheck.java
new file mode 100644
index 0000000..87c3420
--- /dev/null
+++ b/server/container/lifecycle-api/src/main/java/org/apache/james/lifecycle/api/StartUpCheck.java
@@ -0,0 +1,121 @@
+/****************************************************************
+ * 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.lifecycle.api;
+
+import java.util.Optional;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+public interface StartUpCheck {
+
+    enum ResultType {
+        GOOD, BAD
+    }
+
+    class CheckResult {
+
+        public static class Builder {
+
+            @FunctionalInterface
+            public interface RequireCheckName {
+                RequireResultType checkName(String name);
+            }
+
+            @FunctionalInterface
+            public interface RequireResultType {
+                ReadyToBuild resultType(ResultType resultType);
+            }
+
+            public static class ReadyToBuild {
+                private final String name;
+                private final ResultType resultType;
+                private Optional<String> description;
+
+                ReadyToBuild(String name, ResultType resultType) {
+                    this.name = name;
+                    this.resultType = resultType;
+                    this.description = Optional.empty();
+                }
+
+                public ReadyToBuild description(String description) {
+                    this.description = Optional.ofNullable(description);
+                    return this;
+                }
+
+                public CheckResult build() {
+                    return new CheckResult(name, resultType, description);
+                }
+            }
+
+        }
+
+        public static Builder.RequireCheckName builder() {
+            return name -> resultType -> new Builder.ReadyToBuild(name, resultType);
+        }
+
+        private final String name;
+        private final ResultType resultType;
+        private final Optional<String> description;
+
+        private CheckResult(String name, ResultType resultType, Optional<String> description) {
+            Preconditions.checkNotNull(name);
+            Preconditions.checkNotNull(resultType);
+            Preconditions.checkNotNull(description);
+
+            this.name = name;
+            this.resultType = resultType;
+            this.description = description;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public ResultType getResultType() {
+            return resultType;
+        }
+
+        public Optional<String> getDescription() {
+            return description;
+        }
+
+        public boolean isBad() {
+            return resultType.equals(ResultType.BAD);
+        }
+
+        public boolean isGood() {
+            return resultType.equals(ResultType.GOOD);
+        }
+
+        @Override
+        public String toString() {
+            return MoreObjects.toStringHelper(this)
+                .add("name", name)
+                .add("resultType", resultType)
+                .add("description", description)
+                .toString();
+        }
+    }
+
+    CheckResult check();
+
+    String checkName();
+}


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


[james-project] 02/03: JAMES-2763 JMAP mailbox capabilities should rely on StartUpCHeck

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 7097478cb26fa5b2b77423b29b1a0ba12b5f869f
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu May 16 10:48:21 2019 +0700

    JAMES-2763 JMAP mailbox capabilities should rely on StartUpCHeck
---
 .../apache/james/JamesCapabilitiesServerTest.java  |  45 +++++++--
 server/container/guice/protocols/jmap/pom.xml      |   5 +
 .../java/org/apache/james/jmap/JMAPModule.java     |  73 +++++++++-----
 .../java/org/apache/james/jmap/JMAPModuleTest.java | 110 +++++++++++++++++++++
 4 files changed, 201 insertions(+), 32 deletions(-)

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 dd28af5..9cca3e8 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
@@ -19,12 +19,15 @@
 package org.apache.james;
 
 import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.util.EnumSet;
 
+import org.apache.james.jmap.JMAPModule;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.store.search.PDFTextExtractor;
@@ -58,7 +61,11 @@ class JamesCapabilitiesServerTest {
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.SearchCapabilities.class));
         
-        assertThatThrownBy(server::start).isInstanceOf(IllegalArgumentException.class);
+        assertThatThrownBy(server::start)
+            .isInstanceOfSatisfying(
+                StartUpChecksPerformer.StartUpChecksException.class,
+                exception -> assertThat(exception.badCheckNames())
+                    .containsOnly(JMAPModule.RequiredCapabilitiesStartUpCheck.CHECK_NAME));
     }
     
     @Test
@@ -70,7 +77,11 @@ class JamesCapabilitiesServerTest {
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.SearchCapabilities.class));
         
-        assertThatThrownBy(server::start).isInstanceOf(IllegalArgumentException.class);
+        assertThatThrownBy(server::start)
+            .isInstanceOfSatisfying(
+                StartUpChecksPerformer.StartUpChecksException.class,
+                exception -> assertThat(exception.badCheckNames())
+                    .containsOnly(JMAPModule.RequiredCapabilitiesStartUpCheck.CHECK_NAME));
     }
     
     @Test
@@ -82,7 +93,11 @@ class JamesCapabilitiesServerTest {
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.complementOf(EnumSet.of(MailboxManager.SearchCapabilities.Attachment)));
 
-        assertThatThrownBy(server::start).isInstanceOf(IllegalArgumentException.class);
+        assertThatThrownBy(server::start)
+            .isInstanceOfSatisfying(
+                StartUpChecksPerformer.StartUpChecksException.class,
+                exception -> assertThat(exception.badCheckNames())
+                    .containsOnly(JMAPModule.RequiredCapabilitiesStartUpCheck.CHECK_NAME));
     }
 
     @Test
@@ -94,7 +109,11 @@ class JamesCapabilitiesServerTest {
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.complementOf(EnumSet.of(MailboxManager.SearchCapabilities.AttachmentFileName)));
 
-        assertThatThrownBy(server::start).isInstanceOf(IllegalArgumentException.class);
+        assertThatThrownBy(server::start)
+            .isInstanceOfSatisfying(
+                StartUpChecksPerformer.StartUpChecksException.class,
+                exception -> assertThat(exception.badCheckNames())
+                    .containsOnly(JMAPModule.RequiredCapabilitiesStartUpCheck.CHECK_NAME));
     }
     
     @Test
@@ -106,7 +125,11 @@ class JamesCapabilitiesServerTest {
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.complementOf(EnumSet.of(MailboxManager.SearchCapabilities.MultimailboxSearch)));
 
-        assertThatThrownBy(server::start).isInstanceOf(IllegalArgumentException.class);
+        assertThatThrownBy(server::start)
+            .isInstanceOfSatisfying(
+                StartUpChecksPerformer.StartUpChecksException.class,
+                exception -> assertThat(exception.badCheckNames())
+                    .containsOnly(JMAPModule.RequiredCapabilitiesStartUpCheck.CHECK_NAME));
     }
 
     @Test
@@ -118,7 +141,11 @@ class JamesCapabilitiesServerTest {
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.SearchCapabilities.class));
 
-        assertThatThrownBy(server::start).isInstanceOf(IllegalArgumentException.class);
+        assertThatThrownBy(server::start)
+            .isInstanceOfSatisfying(
+                StartUpChecksPerformer.StartUpChecksException.class,
+                exception -> assertThat(exception.badCheckNames())
+                    .containsOnly(JMAPModule.RequiredCapabilitiesStartUpCheck.CHECK_NAME));
     }
 
     @Test
@@ -130,7 +157,11 @@ class JamesCapabilitiesServerTest {
         when(mailboxManager.getSupportedSearchCapabilities())
             .thenReturn(EnumSet.allOf(MailboxManager.SearchCapabilities.class));
 
-        server.start();
+        assertThatCode(server::start)
+            .doesNotThrowAnyException();
+
+        assertThat(server.isStarted())
+            .isTrue();
     }
 
 }
diff --git a/server/container/guice/protocols/jmap/pom.xml b/server/container/guice/protocols/jmap/pom.xml
index 2beb647..eff914c 100644
--- a/server/container/guice/protocols/jmap/pom.xml
+++ b/server/container/guice/protocols/jmap/pom.xml
@@ -94,6 +94,11 @@
             <artifactId>junit-vintage-engine</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
index 044759d..02a24b0 100644
--- a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
+++ b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
@@ -22,8 +22,8 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.EnumSet;
-import java.util.List;
 import java.util.Optional;
+import java.util.stream.Stream;
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
@@ -37,7 +37,7 @@ import org.apache.james.jmap.send.PostDequeueDecoratorFactory;
 import org.apache.james.jmap.utils.HtmlTextExtractor;
 import org.apache.james.jmap.utils.JsoupHtmlTextExtractor;
 import org.apache.james.jwt.JwtConfiguration;
-import org.apache.james.lifecycle.api.Startable;
+import org.apache.james.lifecycle.api.StartUpCheck;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
 import org.apache.james.mailbox.events.MailboxListener;
@@ -45,13 +45,13 @@ import org.apache.james.modules.server.CamelMailetContainerModule;
 import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
 import org.apache.james.server.core.configuration.FileConfigurationProvider;
 import org.apache.james.transport.matchers.RecipientIsLocal;
-import org.apache.james.utils.ConfigurationPerformer;
 import org.apache.james.utils.PropertiesProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.github.fge.lambdas.Throwing;
-import com.google.common.base.Preconditions;
+import com.github.steveash.guavate.Guavate;
+import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
 import com.google.inject.AbstractModule;
 import com.google.inject.Inject;
@@ -94,7 +94,7 @@ public class JMAPModule extends AbstractModule {
         bind(JsoupHtmlTextExtractor.class).in(Scopes.SINGLETON);
 
         bind(HtmlTextExtractor.class).to(JsoupHtmlTextExtractor.class);
-        Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(RequiredCapabilitiesPrecondition.class);
+        Multibinder.newSetBinder(binder(), StartUpCheck.class).addBinding().to(RequiredCapabilitiesStartUpCheck.class);
 
         Multibinder<CamelMailetContainerModule.TransportProcessorCheck> transportProcessorChecks = Multibinder.newSetBinder(binder(), CamelMailetContainerModule.TransportProcessorCheck.class);
         transportProcessorChecks.addBinding().toInstance(VACATION_MAILET_CHECK);
@@ -136,39 +136,62 @@ public class JMAPModule extends AbstractModule {
     }
 
     @Singleton
-    public static class RequiredCapabilitiesPrecondition implements ConfigurationPerformer {
+    public static class RequiredCapabilitiesStartUpCheck implements StartUpCheck {
+
+        public static final String CHECK_NAME = "MailboxCapabilitiesForJMAP";
 
         private final MailboxManager mailboxManager;
 
         @Inject
-        public RequiredCapabilitiesPrecondition(MailboxManager mailboxManager) {
+        public RequiredCapabilitiesStartUpCheck(MailboxManager mailboxManager) {
             this.mailboxManager = mailboxManager;
         }
 
         @Override
-        public void initModule() {
-            Preconditions.checkArgument(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.Move),
-                    "MOVE support in MailboxManager is required by JMAP Module");
-            Preconditions.checkArgument(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.ACL),
-                    "ACL support in MailboxManager is required by JMAP Module");
-
+        public CheckResult check() {
             EnumSet<MailboxManager.MessageCapabilities> messageCapabilities = mailboxManager.getSupportedMessageCapabilities();
-            Preconditions.checkArgument(messageCapabilities.contains(MailboxManager.MessageCapabilities.UniqueID),
-                    "MessageIdManager is not defined by this Mailbox implementation");
-
             EnumSet<SearchCapabilities> searchCapabilities = mailboxManager.getSupportedSearchCapabilities();
-            Preconditions.checkArgument(searchCapabilities.contains(MailboxManager.SearchCapabilities.MultimailboxSearch),
-                    "Multimailbox search in MailboxManager is required by JMAP Module");
-            Preconditions.checkArgument(searchCapabilities.contains(MailboxManager.SearchCapabilities.Attachment),
-                    "Attachment Search support in MailboxManager is required by JMAP Module");
-            Preconditions.checkArgument(searchCapabilities.contains(SearchCapabilities.AttachmentFileName),
-                    "Attachment file name Search support in MailboxManager is required by JMAP Module");
+
+            ImmutableList<String> badCheckDescriptions = Stream.of(
+                    badCheckDescription(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.Move),
+                        "MOVE support in MailboxManager is required by JMAP Module"),
+                    badCheckDescription(mailboxManager.hasCapability(MailboxManager.MailboxCapabilities.ACL),
+                        "ACL support in MailboxManager is required by JMAP Module"),
+                    badCheckDescription(messageCapabilities.contains(MailboxManager.MessageCapabilities.UniqueID),
+                        "MessageIdManager is not defined by this Mailbox implementation"),
+                    badCheckDescription(searchCapabilities.contains(SearchCapabilities.MultimailboxSearch),
+                        "Multimailbox search in MailboxManager is required by JMAP Module"),
+                    badCheckDescription(searchCapabilities.contains(SearchCapabilities.Attachment),
+                        "Attachment Search support in MailboxManager is required by JMAP Module"),
+                    badCheckDescription(searchCapabilities.contains(SearchCapabilities.AttachmentFileName),
+                    "Attachment file name Search support in MailboxManager is required by JMAP Module"))
+                .filter(Optional::isPresent)
+                .map(Optional::get)
+                .collect(Guavate.toImmutableList());
+
+            if (!badCheckDescriptions.isEmpty()) {
+                return CheckResult.builder()
+                    .checkName(checkName())
+                    .resultType(ResultType.BAD)
+                    .description(Joiner.on(",").join(badCheckDescriptions))
+                    .build();
+            }
+            return CheckResult.builder()
+                .checkName(checkName())
+                .resultType(ResultType.GOOD)
+                .build();
+        }
+
+        private Optional<String> badCheckDescription(boolean expressionResult, String expressionFailsDescription) {
+            if (expressionResult) {
+                return Optional.empty();
+            }
+            return Optional.ofNullable(expressionFailsDescription);
         }
 
         @Override
-        public List<Class<? extends Startable>> forClasses() {
-            return ImmutableList.of();
+        public String checkName() {
+            return CHECK_NAME;
         }
     }
-
 }
diff --git a/server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPModuleTest.java b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPModuleTest.java
new file mode 100644
index 0000000..c4f2f6d
--- /dev/null
+++ b/server/container/guice/protocols/jmap/src/test/java/org/apache/james/jmap/JMAPModuleTest.java
@@ -0,0 +1,110 @@
+/****************************************************************
+ * 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.jmap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.EnumSet;
+
+import org.apache.james.jmap.JMAPModule.RequiredCapabilitiesStartUpCheck;
+import org.apache.james.mailbox.MailboxManager;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+
+class JMAPModuleTest {
+
+    @Nested
+    class RequiredCapabilitiesStartUpCheckTest {
+
+        private RequiredCapabilitiesStartUpCheck testee;
+        private MailboxManager mockMailboxManager;
+        private EnumSet<MailboxManager.MessageCapabilities> mockMessageCapabilities;
+        private EnumSet<MailboxManager.SearchCapabilities> mockSearchCapabilities;
+
+        @BeforeEach
+        void beforeEach() {
+            mockMailboxManager = mock(MailboxManager.class);
+            mockMessageCapabilities = (EnumSet<MailboxManager.MessageCapabilities>) mock(EnumSet.class);
+            mockSearchCapabilities = (EnumSet<MailboxManager.SearchCapabilities>) mock(EnumSet.class);
+            when(mockMailboxManager.getSupportedMessageCapabilities())
+                .thenReturn(mockMessageCapabilities);
+            when(mockMailboxManager.getSupportedSearchCapabilities())
+                .thenReturn(mockSearchCapabilities);
+
+            testee = new RequiredCapabilitiesStartUpCheck(mockMailboxManager);
+        }
+
+        @Test
+        void checkShouldReturnGoodWhenAllChecksSatisfy() {
+            when(mockMailboxManager.hasCapability(any()))
+                .thenReturn(true);
+            when(mockMessageCapabilities.contains(any()))
+                .thenReturn(true);
+            when(mockSearchCapabilities.contains(any()))
+                .thenReturn(true);
+
+            assertThat(testee.check().isGood())
+                .isTrue();
+        }
+
+        @Test
+        void checkShouldReturnBadWhenMailboxManagerDoesntHaveCapabilities() {
+            when(mockMailboxManager.hasCapability(any()))
+                .thenReturn(false);
+            when(mockMessageCapabilities.contains(any()))
+                .thenReturn(true);
+            when(mockSearchCapabilities.contains(any()))
+                .thenReturn(true);
+
+            assertThat(testee.check().isBad())
+                .isTrue();
+        }
+
+        @Test
+        void checkShouldReturnBadWhenMailboxManagerDoesntHaveMessagesCapabilities() {
+            when(mockMailboxManager.hasCapability(any()))
+                .thenReturn(true);
+            when(mockMessageCapabilities.contains(any()))
+                .thenReturn(false);
+            when(mockSearchCapabilities.contains(any()))
+                .thenReturn(true);
+
+            assertThat(testee.check().isBad())
+                .isTrue();
+        }
+
+        @Test
+        void checkShouldReturnBadWhenMailboxManagerDoesntHaveSearchCapabilities() {
+            when(mockMailboxManager.hasCapability(any()))
+                .thenReturn(true);
+            when(mockMessageCapabilities.contains(any()))
+                .thenReturn(true);
+            when(mockSearchCapabilities.contains(any()))
+                .thenReturn(false);
+
+            assertThat(testee.check().isBad())
+                .isTrue();
+        }
+    }
+}
\ 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