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/09 10:28:25 UTC

[james-project] branch master updated (355a7b9 -> c61f770)

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 355a7b9  Revert "JAMES-2733 RabbitMQ should not dequeue deleted elements"
     new 6698716  JAMES-2717 DockerElasticSearch impl
     new 269eee4  JAMES-2717 Duplicate the embedded es components to the docker components
     new 9b2a329  JAMES-2717 Replace EmbeddedElasticSearchRule by the docker one
     new ddaa9f8  JAMES-2717 Replace EmbeddedElasticSearchExtension by the docker one
     new 4767a7c  JAMES-2717 Replace EmbeddedElasticSearchExtension in ESReporterTest
     new ec0a653  JAMES-2717 Delete EmbeddedElasticSearchExtension
     new 7d594be  JAMES-2712 Extract ExportRequest object
     new e1f435e  JAMES-2712 Linshare blob export mechanism integration tests
     new 6dd31b1  JAMES-2712 Memory implementation of Linshare blob export mechanism integration tests
     new 95170c3  JAMES-2712 Cassandra implementation of Linshare blob export mechanism integration tests
     new dc1fff5  JAMES-2712 Extract deleteMessages to JMAP common requests
     new 0eab09f  JAMES-2712 Extract vault requests to a proper helper class
     new 762d658  JAMES-2712 Extract matching query for export and restore the vault to Linshare fixture
     new c61f770  JAMES-2712 Extract concatenation of message ids into a proper method

The 14 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:
 backends-common/elasticsearch/pom.xml              |   8 +
 .../james/backends/es/DockerElasticSearch.java     | 126 +++++++++++
 .../backends/es/DockerElasticSearchSingleton.java} |   8 +-
 .../org/apache/james/CassandraJamesServerTest.java |   2 +-
 .../apache/james/CassandraJmapJamesServerTest.java |   2 +-
 .../org/apache/james/CassandraJmapTestRule.java    |   9 +-
 .../CassandraMailRepositoryIntegrationTest.java    |   2 +-
 .../CassandraMessageIdManagerInjectionTest.java    |   2 +-
 .../org/apache/james/CassandraNodeConfTest.java    |   6 +-
 .../apache/james/CassandraVersionCheckingTest.java |   2 +-
 .../org/apache/james/CassandraWithTikaTest.java    |   2 +-
 .../james/DefaultCassandraJamesServerTest.java     |   2 +-
 .../apache/james/DockerElasticSearchExtension.java |  21 +-
 .../org/apache/james/DockerElasticSearchRule.java} |  27 ++-
 .../test/java/org/apache/james/ESReporterTest.java |  13 +-
 .../james/EmbeddedElasticSearchExtension.java      |  63 ------
 .../apache/james/EmbeddedElasticSearchRule.java    |  61 ------
 .../org/apache/james/FixingGhostMailboxTest.java   |   2 +-
 .../apache/james/JamesCapabilitiesServerTest.java  |   2 +-
 .../james/JamesServerWithRetryConnectionTest.java  |  13 +-
 ....java => TestDockerESMetricReporterModule.java} |  13 +-
 ...ule.java => TestDockerElasticSearchModule.java} |  39 +++-
 ...ava => TestEmbeddedESMetricReporterModule.java} |   2 +-
 ...e.java => TestEmbeddedElasticSearchModule.java} |   4 +-
 .../apache/james/CassandraLdapJamesServerTest.java |   2 +-
 .../james/CassandraLdapJmapJamesServerTest.java    |   2 +-
 .../james/CassandraRabbitMQAwsS3JmapTestRule.java  |  10 +-
 .../james/CassandraRabbitMQJamesServerTest.java    |   2 +-
 .../james/CassandraRabbitMQSwiftJmapTestRule.java  |   9 +-
 .../CassandraRabbitMQLdapJmapJamesServerTest.java  |   2 +-
 .../cassandra-jmap-integration-testing/pom.xml     |  12 +
 ...inshareBlobExportMechanismIntegrationTest.java} |  36 +--
 .../jmap/cassandra/CassandraSendMDNMethodTest.java |   4 +-
 .../CassandraSpamAssassinContractTest.java         |   4 +-
 .../jmap/cassandra/cucumber/CassandraStepdefs.java |   8 +-
 .../jmap-integration-testing-common/pom.xml        |  10 +
 .../james/jmap/DeletedMessagesVaultRequests.java   |  83 +++++++
 .../{UserCredentials.java => ExportRequest.java}   |  60 +++--
 .../org/apache/james/jmap/JmapCommonRequests.java  |  16 ++
 .../integration/DeletedMessagesVaultTest.java      | 135 ++----------
 ...LinshareBlobExportMechanismIntegrationTest.java | 244 +++++++++++++++++++++
 .../jmap/methods/integration/QuotaMailingTest.java |  10 +-
 .../memory-jmap-integration-testing/pom.xml        |   7 +
 ...inshareBlobExportMechanismIntegrationTest.java} |  47 ++--
 .../rabbitmq/RabbitMQAwsS3SendMDNMethodTest.java   |   4 +-
 .../RabbitMQAwsS3SpamAssassinContractTest.java     |   4 +-
 .../ReindexingWithEventDeadLettersTest.java        |  13 +-
 .../cucumber/awss3/RabbitMQAwsS3Stepdefs.java      |  11 +-
 .../integration/CassandraJmapExtension.java        |   8 +-
 .../james/util/docker/DockerGenericContainer.java  |   4 +
 .../org/apache/james/linshare/LinshareFixture.java |   4 +
 51 files changed, 747 insertions(+), 435 deletions(-)
 create mode 100644 backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearch.java
 copy backends-common/elasticsearch/src/{main/java/org/apache/james/backends/es/WriteAliasName.java => test/java/org/apache/james/backends/es/DockerElasticSearchSingleton.java} (88%)
 copy server/container/guice/{guice-common/src/test/java/org/apache/james/TempFilesystemTestRule.java => cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java} (73%)
 delete mode 100644 server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchExtension.java
 delete mode 100644 server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
 copy server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/{TestESMetricReporterModule.java => TestDockerESMetricReporterModule.java} (84%)
 copy server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/{TestElasticSearchModule.java => TestDockerElasticSearchModule.java} (59%)
 rename server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/{TestESMetricReporterModule.java => TestEmbeddedESMetricReporterModule.java} (96%)
 rename server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/{TestElasticSearchModule.java => TestEmbeddedElasticSearchModule.java} (92%)
 copy server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/{CassandraSendMDNMethodTest.java => CassandraLinshareBlobExportMechanismIntegrationTest.java} (59%)
 create mode 100644 server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/DeletedMessagesVaultRequests.java
 copy server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/{UserCredentials.java => ExportRequest.java} (57%)
 create mode 100644 server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java
 copy server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/{MemorySendMDNMethodTest.java => MemoryLinshareBlobExportMechanismIntegrationTest.java} (53%)


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


[james-project] 10/14: JAMES-2712 Cassandra implementation of Linshare blob export mechanism 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 95170c3dcb3b50d833654edb44981ddeeb9720eb
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Apr 26 17:19:16 2019 +0700

    JAMES-2712 Cassandra implementation of Linshare blob export mechanism integration tests
---
 .../cassandra-jmap-integration-testing/pom.xml     | 12 ++++
 ...LinshareBlobExportMechanismIntegrationTest.java | 64 ++++++++++++++++++++++
 2 files changed, 76 insertions(+)

diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
index 82f0d44..5d2b2c9 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
@@ -35,6 +35,12 @@
     <dependencies>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-linshare</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>apache-james-backends-es</artifactId>
             <type>test-jar</type>
             <scope>test</scope>
@@ -87,6 +93,12 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>blob-export-guice</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>blob-objectstorage-guice</artifactId>
             <scope>test</scope>
         </dependency>
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
new file mode 100644
index 0000000..8cd0b36
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraLinshareBlobExportMechanismIntegrationTest.java
@@ -0,0 +1,64 @@
+/****************************************************************
+ * 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.cassandra;
+
+import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
+
+import org.apache.james.CassandraExtension;
+import org.apache.james.EmbeddedElasticSearchExtension;
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.JamesServerBuilder;
+import org.apache.james.JamesServerExtension;
+import org.apache.james.jmap.methods.integration.LinshareBlobExportMechanismIntegrationTest;
+import org.apache.james.mailrepository.api.MailRepositoryUrl;
+import org.apache.james.modules.LinshareGuiceExtension;
+import org.apache.james.modules.TestJMAPServerModule;
+import org.apache.james.modules.mailbox.PreDeletionHookConfiguration;
+import org.apache.james.modules.mailbox.PreDeletionHooksConfiguration;
+import org.apache.james.vault.DeletedMessageVaultHook;
+import org.apache.james.vault.MailRepositoryDeletedMessageVault;
+import org.apache.james.webadmin.WebAdminConfiguration;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+public class CassandraLinshareBlobExportMechanismIntegrationTest extends LinshareBlobExportMechanismIntegrationTest {
+
+    private static final long LIMIT_TO_10_MESSAGES = 10;
+
+    private final LinshareGuiceExtension linshareGuiceExtension = new LinshareGuiceExtension();
+
+    @RegisterExtension
+    JamesServerExtension testExtension = new JamesServerBuilder()
+        .extension(linshareGuiceExtension)
+        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new CassandraExtension())
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(binder -> {
+                binder.bind(WebAdminConfiguration.class)
+                    .toInstance(WebAdminConfiguration.TEST_CONFIGURATION);
+                binder.bind(PreDeletionHooksConfiguration.class)
+                    .toInstance(PreDeletionHooksConfiguration.forHooks(
+                        PreDeletionHookConfiguration.forClass(DeletedMessageVaultHook.class)));
+                binder.bind(MailRepositoryDeletedMessageVault.Configuration.class)
+                    .toInstance(new MailRepositoryDeletedMessageVault.Configuration(MailRepositoryUrl.from("cassandra://var/deletedMessages/user")));
+            }))
+        .build();
+}


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


[james-project] 13/14: JAMES-2712 Extract matching query for export and restore the vault to Linshare fixture

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 762d658f0da89f6dc617a68d94d72b49c770dfda
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu May 2 15:30:39 2019 +0700

    JAMES-2712 Extract matching query for export and restore the vault to Linshare fixture
---
 .../james/jmap/methods/integration/DeletedMessagesVaultTest.java     | 5 +----
 .../integration/LinshareBlobExportMechanismIntegrationTest.java      | 5 +----
 .../src/test/java/org/apache/james/linshare/LinshareFixture.java     | 4 ++++
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
index 60faec2..4c05393 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
@@ -37,6 +37,7 @@ import static org.apache.james.jmap.TestingConstants.DOMAIN;
 import static org.apache.james.jmap.TestingConstants.LOCALHOST_IP;
 import static org.apache.james.jmap.TestingConstants.calmlyAwait;
 import static org.apache.james.jmap.TestingConstants.jmapRequestSpecBuilder;
+import static org.apache.james.linshare.LinshareFixture.MATCH_ALL_QUERY;
 import static org.apache.james.mailbox.backup.ZipAssert.EntryChecks.hasName;
 import static org.apache.james.mailbox.backup.ZipAssert.assertThatZip;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -98,10 +99,6 @@ public abstract class DeletedMessagesVaultTest {
     private static final ConditionFactory WAIT_TWO_MINUTES = calmlyAwait.atMost(Duration.TWO_MINUTES);
     private static final String SUBJECT = "This mail will be restored from the vault!!";
     private static final String MAILBOX_NAME = "toBeDeleted";
-    private static final String MATCH_ALL_QUERY = "{" +
-        "\"combinator\": \"and\"," +
-        "\"criteria\": []" +
-        "}";
     private static final ExportRequest EXPORT_ALL_HOMER_MESSAGES_TO_BART = ExportRequest
         .userExportFrom(HOMER)
         .exportTo(BART)
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java
index 8e6c704..b5c0004 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java
@@ -32,6 +32,7 @@ import static org.apache.james.jmap.TestingConstants.DOMAIN;
 import static org.apache.james.jmap.TestingConstants.LOCALHOST_IP;
 import static org.apache.james.jmap.TestingConstants.calmlyAwait;
 import static org.apache.james.jmap.TestingConstants.jmapRequestSpecBuilder;
+import static org.apache.james.linshare.LinshareFixture.MATCH_ALL_QUERY;
 import static org.apache.james.linshare.LinshareFixture.USER_1;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.hamcrest.Matchers.containsString;
@@ -72,10 +73,6 @@ public abstract class LinshareBlobExportMechanismIntegrationTest {
     private static final String BART_PASSWORD = "bartPassword";
     private static final ConditionFactory WAIT_TEN_SECONDS = calmlyAwait.atMost(Duration.TEN_SECONDS);
     private static final String SUBJECT = "This mail will be restored from the vault!!";
-    private static final String MATCH_ALL_QUERY = "{" +
-        "\"combinator\": \"and\"," +
-        "\"criteria\": []" +
-        "}";
     private static final ExportRequest EXPORT_ALL_HOMER_MESSAGES_TO_USER_1 = ExportRequest
         .userExportFrom(HOMER)
         .exportTo(USER_1.getUsername())
diff --git a/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareFixture.java b/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareFixture.java
index 9d53133..a47e409 100644
--- a/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareFixture.java
+++ b/third-party/linshare/src/test/java/org/apache/james/linshare/LinshareFixture.java
@@ -80,4 +80,8 @@ public interface LinshareFixture {
     Map<String, Credential> USER_CREDENTIAL_MAP = USER_CREDENTIALS.stream()
         .collect(Guavate.toImmutableMap(Credential::getUsername, Function.identity()));
 
+    String MATCH_ALL_QUERY = "{" +
+        "\"combinator\": \"and\"," +
+        "\"criteria\": []" +
+        "}";
 }


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


[james-project] 01/14: JAMES-2717 DockerElasticSearch impl

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 66987165ec5e4b8957c61417e060281b5968e33c
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Tue May 7 18:18:26 2019 +0700

    JAMES-2717 DockerElasticSearch impl
---
 backends-common/elasticsearch/pom.xml              |   8 ++
 .../james/backends/es/DockerElasticSearch.java     | 126 +++++++++++++++++++++
 .../backends/es/DockerElasticSearchSingleton.java  |  28 +++++
 .../james/util/docker/DockerGenericContainer.java  |   4 +
 4 files changed, 166 insertions(+)

diff --git a/backends-common/elasticsearch/pom.xml b/backends-common/elasticsearch/pom.xml
index 2732012..1df2811 100644
--- a/backends-common/elasticsearch/pom.xml
+++ b/backends-common/elasticsearch/pom.xml
@@ -56,6 +56,14 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>io.github.openfeign</groupId>
+            <artifactId>feign-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.github.openfeign</groupId>
+            <artifactId>feign-slf4j</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.assertj</groupId>
             <artifactId>assertj-core</artifactId>
             <scope>test</scope>
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearch.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearch.java
new file mode 100644
index 0000000..10e6912
--- /dev/null
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearch.java
@@ -0,0 +1,126 @@
+/****************************************************************
+ * 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.backends.es;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import org.apache.http.HttpStatus;
+import org.apache.james.util.Host;
+import org.apache.james.util.docker.DockerGenericContainer;
+import org.apache.james.util.docker.Images;
+import org.apache.james.util.docker.RateLimiters;
+import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;
+
+import com.google.common.collect.ImmutableList;
+
+import feign.Feign;
+import feign.Logger;
+import feign.RequestLine;
+import feign.Response;
+import feign.slf4j.Slf4jLogger;
+
+public class DockerElasticSearch {
+
+    interface ElasticSearchAPI {
+
+        static ElasticSearchAPI from(Host esHttpHost) {
+            return Feign.builder()
+                .logger(new Slf4jLogger(ElasticSearchAPI.class))
+                .logLevel(Logger.Level.FULL)
+                .target(ElasticSearchAPI.class, "http://" + esHttpHost.getHostName() + ":" + esHttpHost.getPort());
+        }
+
+        @RequestLine("DELETE /_all")
+        Response deleteAllIndexes();
+
+        @RequestLine("POST /_flush?force&wait_if_ongoing=true")
+        Response flush();
+    }
+
+    private static final int ES_HTTP_PORT = 9200;
+    private static final int ES_TCP_PORT = 9300;
+
+    private final DockerGenericContainer eSContainer;
+
+    public DockerElasticSearch() {
+        this.eSContainer = new DockerGenericContainer(Images.ELASTICSEARCH_2)
+            .withExposedPorts(ES_HTTP_PORT, ES_TCP_PORT)
+            .waitingFor(new HostPortWaitStrategy().withRateLimiter(RateLimiters.TWENTIES_PER_SECOND));
+    }
+
+    public void start() {
+        if (!eSContainer.isRunning()) {
+            eSContainer.start();
+        }
+    }
+
+    public void stop() {
+        eSContainer.stop();
+    }
+
+    public int getHttpPort() {
+        return eSContainer.getMappedPort(ES_HTTP_PORT);
+    }
+
+    public int getTcpPort() {
+        return eSContainer.getMappedPort(ES_TCP_PORT);
+    }
+
+    public String getIp() {
+        return eSContainer.getHostIp();
+    }
+
+    public Host getTcpHost() {
+        return Host.from(getIp(), getTcpPort());
+    }
+
+    public Host getHttpHost() {
+        return Host.from(getIp(), getHttpPort());
+    }
+
+    public void pause() {
+        eSContainer.pause();
+    }
+
+    public void unpause() {
+        eSContainer.unpause();
+    }
+
+    public void cleanUpData() {
+        assertThat(esAPI().deleteAllIndexes().status())
+            .isEqualTo(HttpStatus.SC_OK);
+    }
+
+    public void awaitForElasticSearch() {
+        assertThat(esAPI().flush().status())
+            .isEqualTo(HttpStatus.SC_OK);
+    }
+
+    public ClientProvider clientProvider() {
+        Optional<String> noClusterName = Optional.empty();
+        return ClientProviderImpl.fromHosts(ImmutableList.of(getTcpHost()), noClusterName);
+    }
+
+    private ElasticSearchAPI esAPI() {
+        return ElasticSearchAPI.from(getHttpHost());
+    }
+}
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearchSingleton.java b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearchSingleton.java
new file mode 100644
index 0000000..e3d409a
--- /dev/null
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/DockerElasticSearchSingleton.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.backends.es;
+
+public class DockerElasticSearchSingleton {
+    public static DockerElasticSearch INSTANCE = new DockerElasticSearch();
+
+    static {
+        INSTANCE.start();
+    }
+}
diff --git a/server/testing/src/main/java/org/apache/james/util/docker/DockerGenericContainer.java b/server/testing/src/main/java/org/apache/james/util/docker/DockerGenericContainer.java
index 62401fb..a833f58 100644
--- a/server/testing/src/main/java/org/apache/james/util/docker/DockerGenericContainer.java
+++ b/server/testing/src/main/java/org/apache/james/util/docker/DockerGenericContainer.java
@@ -125,6 +125,10 @@ public class DockerGenericContainer implements TestRule {
         DockerClientFactory.instance().client().pauseContainerCmd(container.getContainerInfo().getId()).exec();
     }
 
+    public boolean isRunning() {
+        return container.isRunning();
+    }
+
     public void unpause() {
         DockerClientFactory.instance().client().unpauseContainerCmd(container.getContainerInfo().getId()).exec();
     }


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


[james-project] 02/14: JAMES-2717 Duplicate the embedded es components to the docker components

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 269eee48d1e847c659f2e36952547a682d36e49c
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Tue May 7 18:35:31 2019 +0700

    JAMES-2717 Duplicate the embedded es components to the docker components
---
 .../apache/james/DockerElasticSearchExtension.java | 21 +++++-------
 ...earchRule.java => DockerElasticSearchRule.java} | 28 ++++++----------
 .../test/java/org/apache/james/ESReporterTest.java |  6 ++--
 .../james/EmbeddedElasticSearchExtension.java      |  4 +--
 .../apache/james/EmbeddedElasticSearchRule.java    |  4 +--
 .../james/JamesServerWithRetryConnectionTest.java  | 13 +++-----
 ....java => TestDockerESMetricReporterModule.java} | 13 +++++---
 ...ule.java => TestDockerElasticSearchModule.java} | 39 +++++++++++++++++-----
 ...ava => TestEmbeddedESMetricReporterModule.java} |  2 +-
 ...e.java => TestEmbeddedElasticSearchModule.java} |  4 +--
 .../jmap/cassandra/cucumber/CassandraStepdefs.java |  8 ++---
 .../ReindexingWithEventDeadLettersTest.java        | 13 +++-----
 .../cucumber/awss3/RabbitMQAwsS3Stepdefs.java      | 11 +++---
 .../integration/CassandraJmapExtension.java        |  8 ++---
 14 files changed, 89 insertions(+), 85 deletions(-)

diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchExtension.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchExtension.java
index bfc755e..20f2747 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchExtension.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchExtension.java
@@ -19,31 +19,22 @@
 
 package org.apache.james;
 
+import org.apache.james.backends.es.DockerElasticSearch;
+import org.apache.james.backends.es.DockerElasticSearchSingleton;
 import org.apache.james.backends.es.ElasticSearchConfiguration;
-import org.apache.james.util.Host;
-import org.apache.james.util.docker.DockerGenericContainer;
 import org.junit.jupiter.api.extension.ExtensionContext;
 
 import com.google.inject.Module;
 
 public class DockerElasticSearchExtension implements GuiceModuleTestExtension {
-    public static final int ELASTIC_SEARCH_PORT = 9300;
-    public static final int ELASTIC_SEARCH_HTTP_PORT = 9200;
-
-    private final DockerGenericContainer elasticSearchContainer;
-
-    public DockerElasticSearchExtension(DockerGenericContainer elasticSearchContainer) {
-        this.elasticSearchContainer = elasticSearchContainer;
-    }
 
     @Override
     public void beforeEach(ExtensionContext extensionContext) {
-        elasticSearchContainer.start();
+        getDockerES().start();
     }
 
     @Override
     public void afterEach(ExtensionContext extensionContext) {
-        elasticSearchContainer.stop();
     }
 
     @Override
@@ -54,7 +45,11 @@ public class DockerElasticSearchExtension implements GuiceModuleTestExtension {
 
     private ElasticSearchConfiguration getElasticSearchConfigurationForDocker() {
         return ElasticSearchConfiguration.builder()
-            .addHost(Host.from(elasticSearchContainer.getHostIp(), elasticSearchContainer.getMappedPort(ELASTIC_SEARCH_PORT)))
+            .addHost(getDockerES().getTcpHost())
             .build();
     }
+
+    public DockerElasticSearch getDockerES() {
+        return DockerElasticSearchSingleton.INSTANCE;
+    }
 }
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java
similarity index 64%
copy from server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
copy to server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java
index 3c6848a..6287009 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DockerElasticSearchRule.java
@@ -19,43 +19,35 @@
 
 package org.apache.james;
 
-import org.apache.james.backends.es.EmbeddedElasticSearch;
-import org.apache.james.modules.TestElasticSearchModule;
-import org.elasticsearch.node.Node;
-import org.junit.rules.RuleChain;
-import org.junit.rules.TemporaryFolder;
+import org.apache.james.backends.es.DockerElasticSearch;
+import org.apache.james.backends.es.DockerElasticSearchSingleton;
+import org.apache.james.modules.TestDockerElasticSearchModule;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
 
 import com.google.inject.Module;
 
 
-public class EmbeddedElasticSearchRule implements GuiceModuleTestRule {
+public class DockerElasticSearchRule implements GuiceModuleTestRule {
 
-    private final TemporaryFolder temporaryFolder = new TemporaryFolder();
-    private final EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
-
-    private final RuleChain chain = RuleChain
-        .outerRule(temporaryFolder)
-        .around(embeddedElasticSearch);
+    private final DockerElasticSearch elasticSearch = DockerElasticSearchSingleton.INSTANCE;
 
     @Override
     public Statement apply(Statement base, Description description) {
-        return chain.apply(base, description);
+        return base;
     }
 
     @Override
     public void await() {
-        embeddedElasticSearch.awaitForElasticSearch();
+        elasticSearch.awaitForElasticSearch();
     }
 
-
     @Override
     public Module getModule() {
-        return new TestElasticSearchModule(embeddedElasticSearch);
+        return new TestDockerElasticSearchModule(elasticSearch);
     }
 
-    public Node getNode() {
-        return embeddedElasticSearch.getNode();
+    public DockerElasticSearch getDockerEs() {
+        return elasticSearch;
     }
 }
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 65392fd..f896e28 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
@@ -37,7 +37,7 @@ import org.apache.commons.net.imap.IMAPClient;
 import org.apache.james.jmap.api.access.AccessToken;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.store.search.PDFTextExtractor;
-import org.apache.james.modules.TestESMetricReporterModule;
+import org.apache.james.modules.TestEmbeddedESMetricReporterModule;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.protocols.ImapGuiceProbe;
 import org.apache.james.utils.DataProbeImpl;
@@ -71,7 +71,7 @@ class ESReporterTest {
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
             .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
             .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
-            .overrideWith(new TestESMetricReporterModule()))
+            .overrideWith(new TestEmbeddedESMetricReporterModule()))
         .build();
 
     private static final int DELAY_IN_MS = 100;
@@ -156,7 +156,7 @@ class ESReporterTest {
             return !Arrays.stream(client.prepareSearch()
                     .setQuery(QueryBuilders.matchAllQuery())
                     .get().getHits().getHits())
-                .filter(searchHit -> searchHit.getIndex().startsWith(TestESMetricReporterModule.METRICS_INDEX))
+                .filter(searchHit -> searchHit.getIndex().startsWith(TestEmbeddedESMetricReporterModule.METRICS_INDEX))
                 .collect(Collectors.toList())
                 .isEmpty();
         } catch (Exception e) {
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchExtension.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchExtension.java
index 743dbc3..a724c35 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchExtension.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchExtension.java
@@ -21,7 +21,7 @@ package org.apache.james;
 
 import org.apache.james.backends.es.EmbeddedElasticSearch;
 import org.apache.james.junit.TemporaryFolderExtension;
-import org.apache.james.modules.TestElasticSearchModule;
+import org.apache.james.modules.TestEmbeddedElasticSearchModule;
 import org.junit.jupiter.api.extension.ExtensionContext;
 
 import com.google.inject.Module;
@@ -49,7 +49,7 @@ public class EmbeddedElasticSearchExtension implements GuiceModuleTestExtension
 
     @Override
     public Module getModule() {
-        return new TestElasticSearchModule(embeddedElasticSearch);
+        return new TestEmbeddedElasticSearchModule(embeddedElasticSearch);
     }
 
     @Override
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
index 3c6848a..b4c524f 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
@@ -20,7 +20,7 @@
 package org.apache.james;
 
 import org.apache.james.backends.es.EmbeddedElasticSearch;
-import org.apache.james.modules.TestElasticSearchModule;
+import org.apache.james.modules.TestEmbeddedElasticSearchModule;
 import org.elasticsearch.node.Node;
 import org.junit.rules.RuleChain;
 import org.junit.rules.TemporaryFolder;
@@ -52,7 +52,7 @@ public class EmbeddedElasticSearchRule implements GuiceModuleTestRule {
 
     @Override
     public Module getModule() {
-        return new TestElasticSearchModule(embeddedElasticSearch);
+        return new TestEmbeddedElasticSearchModule(embeddedElasticSearch);
     }
 
     public Node getNode() {
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 85263de..4f6745b 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
@@ -20,8 +20,6 @@
 package org.apache.james;
 
 import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
-import static org.apache.james.DockerElasticSearchExtension.ELASTIC_SEARCH_HTTP_PORT;
-import static org.apache.james.DockerElasticSearchExtension.ELASTIC_SEARCH_PORT;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.IOException;
@@ -39,8 +37,6 @@ import org.apache.james.mailbox.store.search.PDFTextExtractor;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.protocols.ImapGuiceProbe;
 import org.apache.james.util.concurrent.NamedThreadFactory;
-import org.apache.james.util.docker.DockerGenericContainer;
-import org.apache.james.util.docker.Images;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -50,13 +46,12 @@ class JamesServerWithRetryConnectionTest {
     private static final int LIMIT_TO_10_MESSAGES = 10;
     private static final long WAITING_TIME = TimeUnit.MILLISECONDS.convert(10, TimeUnit.SECONDS);
 
-    private static DockerGenericContainer elasticSearchContainer = new DockerGenericContainer(Images.ELASTICSEARCH_2)
-        .withExposedPorts(ELASTIC_SEARCH_HTTP_PORT, ELASTIC_SEARCH_PORT);
     private static final DockerCassandraRule cassandraRule = new DockerCassandraRule();
+    private static final DockerElasticSearchExtension dockerElasticSearch = new DockerElasticSearchExtension();
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new DockerElasticSearchExtension(elasticSearchContainer))
+        .extension(dockerElasticSearch)
         .extension(new CassandraExtension(cassandraRule))
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
@@ -97,9 +92,9 @@ class JamesServerWithRetryConnectionTest {
 
     @Test
     void serverShouldRetryToConnectToElasticSearchWhenStartService(GuiceJamesServer server) throws Exception {
-        elasticSearchContainer.pause();
+        dockerElasticSearch.getDockerES().pause();
 
-        waitToStartContainer(WAITING_TIME, elasticSearchContainer::unpause);
+        waitToStartContainer(WAITING_TIME, dockerElasticSearch.getDockerES()::unpause);
 
         assertThatServerStartCorrectly(server);
     }
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestESMetricReporterModule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestDockerESMetricReporterModule.java
similarity index 84%
copy from server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestESMetricReporterModule.java
copy to server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestDockerESMetricReporterModule.java
index 85808e0..3b9e438 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestESMetricReporterModule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestDockerESMetricReporterModule.java
@@ -22,16 +22,21 @@ package org.apache.james.modules;
 import javax.inject.Singleton;
 
 import org.apache.james.metrics.es.ESReporterConfiguration;
+import org.apache.james.util.Host;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
 
-public class TestESMetricReporterModule extends AbstractModule {
+public class TestDockerESMetricReporterModule extends AbstractModule {
 
-    private static final String LOCALHOST = "localhost";
-    private static final int DEFAULT_ES_HTTP_PORT = 9200;
     public static final String METRICS_INDEX = "metrics";
 
+    private final Host esHttpHost;
+
+    public TestDockerESMetricReporterModule(Host esHttpHost) {
+        this.esHttpHost = esHttpHost;
+    }
+
     @Override
     protected void configure() {
     }
@@ -41,7 +46,7 @@ public class TestESMetricReporterModule extends AbstractModule {
     public ESReporterConfiguration provideConfiguration() {
         return ESReporterConfiguration.builder()
             .enabled()
-            .onHost(LOCALHOST, DEFAULT_ES_HTTP_PORT)
+            .onHost(esHttpHost.getHostName(), esHttpHost.getPort())
             .onIndex(METRICS_INDEX)
             .periodInSecond(1L)
             .build();
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestDockerElasticSearchModule.java
similarity index 59%
copy from server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
copy to server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestDockerElasticSearchModule.java
index 0ada1f6..10797a2 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestDockerElasticSearchModule.java
@@ -21,32 +21,53 @@ package org.apache.james.modules;
 
 import javax.inject.Singleton;
 
+import org.apache.james.CleanupTasksPerformer;
+import org.apache.james.backends.es.DockerElasticSearch;
 import org.apache.james.backends.es.ElasticSearchConfiguration;
-import org.apache.james.backends.es.EmbeddedElasticSearch;
-import org.apache.james.backends.es.utils.TestingClientProvider;
 import org.apache.james.mailbox.elasticsearch.MailboxIndexCreationUtil;
 import org.elasticsearch.client.Client;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
+import com.google.inject.multibindings.Multibinder;
 
-public class TestElasticSearchModule extends AbstractModule {
+public class TestDockerElasticSearchModule extends AbstractModule {
 
-    private final EmbeddedElasticSearch embeddedElasticSearch;
+    private static class ESContainerCleanUp implements CleanupTasksPerformer.CleanupTask {
 
-    public TestElasticSearchModule(EmbeddedElasticSearch embeddedElasticSearch) {
-        this.embeddedElasticSearch = embeddedElasticSearch;
+        private final DockerElasticSearch elasticSearch;
+
+        private ESContainerCleanUp(DockerElasticSearch elasticSearch) {
+            this.elasticSearch = elasticSearch;
+        }
+
+        @Override
+        public Result run() {
+            elasticSearch.cleanUpData();
+
+            return Result.COMPLETED;
+        }
+    }
+
+    private final DockerElasticSearch elasticSearch;
+
+    public TestDockerElasticSearchModule(DockerElasticSearch elasticSearch) {
+        this.elasticSearch = elasticSearch;
     }
 
     @Override
     protected void configure() {
-
+        Multibinder.newSetBinder(binder(), CleanupTasksPerformer.CleanupTask.class)
+            .addBinding()
+            .toInstance(new ESContainerCleanUp(elasticSearch));
     }
 
     @Provides
     @Singleton
     protected Client provideClientProvider() {
-        Client client = new TestingClientProvider(embeddedElasticSearch.getNode()).get();
-        return MailboxIndexCreationUtil.prepareDefaultClient(client, ElasticSearchConfiguration.DEFAULT_CONFIGURATION);
+        Client client = elasticSearch.clientProvider().get();
+        return MailboxIndexCreationUtil.prepareDefaultClient(client, ElasticSearchConfiguration.builder()
+            .addHost(elasticSearch.getTcpHost())
+            .build());
     }
 }
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestESMetricReporterModule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestEmbeddedESMetricReporterModule.java
similarity index 96%
rename from server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestESMetricReporterModule.java
rename to server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestEmbeddedESMetricReporterModule.java
index 85808e0..13284fa 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestESMetricReporterModule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestEmbeddedESMetricReporterModule.java
@@ -26,7 +26,7 @@ import org.apache.james.metrics.es.ESReporterConfiguration;
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
 
-public class TestESMetricReporterModule extends AbstractModule {
+public class TestEmbeddedESMetricReporterModule extends AbstractModule {
 
     private static final String LOCALHOST = "localhost";
     private static final int DEFAULT_ES_HTTP_PORT = 9200;
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestEmbeddedElasticSearchModule.java
similarity index 92%
rename from server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
rename to server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestEmbeddedElasticSearchModule.java
index 0ada1f6..a0d4748 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestEmbeddedElasticSearchModule.java
@@ -30,11 +30,11 @@ import org.elasticsearch.client.Client;
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
 
-public class TestElasticSearchModule extends AbstractModule {
+public class TestEmbeddedElasticSearchModule extends AbstractModule {
 
     private final EmbeddedElasticSearch embeddedElasticSearch;
 
-    public TestElasticSearchModule(EmbeddedElasticSearch embeddedElasticSearch) {
+    public TestEmbeddedElasticSearchModule(EmbeddedElasticSearch embeddedElasticSearch) {
         this.embeddedElasticSearch = embeddedElasticSearch;
     }
 
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
index 4cb6304..7f770d6 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java
@@ -36,8 +36,8 @@ import org.apache.james.jmap.methods.integration.cucumber.MainStepdefs;
 import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
-import org.apache.james.modules.TestESMetricReporterModule;
-import org.apache.james.modules.TestElasticSearchModule;
+import org.apache.james.modules.TestEmbeddedESMetricReporterModule;
+import org.apache.james.modules.TestEmbeddedElasticSearchModule;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.server.CassandraTruncateTableTask;
 import org.apache.james.server.core.configuration.Configuration;
@@ -79,8 +79,8 @@ public class CassandraStepdefs {
         mainStepdefs.jmapServer = GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
             .overrideWith(new TestJMAPServerModule(10))
-            .overrideWith(new TestESMetricReporterModule())
-            .overrideWith(new TestElasticSearchModule(embeddedElasticSearch))
+            .overrideWith(new TestEmbeddedESMetricReporterModule())
+            .overrideWith(new TestEmbeddedElasticSearchModule(embeddedElasticSearch))
             .overrideWith(cassandraServer.getModule())
             .overrideWith(binder -> binder.bind(TextExtractor.class).to(DefaultTextExtractor.class))
             .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class))
diff --git a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/ReindexingWithEventDeadLettersTest.java b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/ReindexingWithEventDeadLettersTest.java
index b1e2c85..c4385af 100644
--- a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/ReindexingWithEventDeadLettersTest.java
+++ b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/ReindexingWithEventDeadLettersTest.java
@@ -20,8 +20,6 @@
 package org.apache.james.jmap.rabbitmq;
 
 import static io.restassured.RestAssured.with;
-import static org.apache.james.DockerElasticSearchExtension.ELASTIC_SEARCH_HTTP_PORT;
-import static org.apache.james.DockerElasticSearchExtension.ELASTIC_SEARCH_PORT;
 import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
 import static org.apache.james.jmap.JmapCommonRequests.getDraftId;
 import static org.apache.james.jmap.JmapCommonRequests.listMessageIdsForAccount;
@@ -47,8 +45,6 @@ import org.apache.james.modules.AwsS3BlobStoreExtension;
 import org.apache.james.modules.RabbitMQExtension;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.objectstorage.PayloadCodecFactory;
-import org.apache.james.util.docker.DockerGenericContainer;
-import org.apache.james.util.docker.Images;
 import org.apache.james.utils.DataProbeImpl;
 import org.apache.james.utils.JmapGuiceProbe;
 import org.apache.james.utils.WebAdminGuiceProbe;
@@ -75,8 +71,7 @@ class ReindexingWithEventDeadLettersTest {
         .atMost(Duration.ONE_MINUTE)
         .await();
 
-    private static DockerGenericContainer elasticSearchContainer = new DockerGenericContainer(Images.ELASTICSEARCH_2)
-        .withExposedPorts(ELASTIC_SEARCH_HTTP_PORT, ELASTIC_SEARCH_PORT);
+    private static final DockerElasticSearchExtension dockerElasticSearch = new DockerElasticSearchExtension();
 
     private static final JamesServerBuilder.ServerProvider CONFIGURATION_BUILDER = configuration -> GuiceJamesServer
             .forConfiguration(configuration)
@@ -88,7 +83,7 @@ class ReindexingWithEventDeadLettersTest {
 
     @RegisterExtension
     JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new DockerElasticSearchExtension(elasticSearchContainer))
+        .extension(dockerElasticSearch)
         .extension(new CassandraExtension())
         .extension(new RabbitMQExtension())
         .extension(new AwsS3BlobStoreExtension(PayloadCodecFactory.AES256))
@@ -114,7 +109,7 @@ class ReindexingWithEventDeadLettersTest {
 
         aliceAccessToken = authenticateJamesUser(baseUri(jamesServer), ALICE, ALICE_PASSWORD);
 
-        elasticSearchContainer.pause();
+        dockerElasticSearch.getDockerES().pause();
         Thread.sleep(Duration.TEN_SECONDS.getValueInMS()); // Docker pause is asynchronous and we found no way to poll for it
     }
 
@@ -152,7 +147,7 @@ class ReindexingWithEventDeadLettersTest {
     }
 
     private void unpauseElasticSearch() throws Exception {
-        elasticSearchContainer.unpause();
+        dockerElasticSearch.getDockerES().unpause();
         Thread.sleep(Duration.FIVE_SECONDS.getValueInMS()); // Docker unpause is asynchronous and we found no way to poll for it
     }
 
diff --git a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/cucumber/awss3/RabbitMQAwsS3Stepdefs.java b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/cucumber/awss3/RabbitMQAwsS3Stepdefs.java
index baf2f58..01d6747 100644
--- a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/cucumber/awss3/RabbitMQAwsS3Stepdefs.java
+++ b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/cucumber/awss3/RabbitMQAwsS3Stepdefs.java
@@ -20,6 +20,7 @@
 package org.apache.james.jmap.rabbitmq.cucumber.awss3;
 
 import java.util.Arrays;
+
 import javax.inject.Inject;
 
 import org.apache.activemq.store.PersistenceAdapter;
@@ -35,18 +36,18 @@ import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
 import org.apache.james.modules.DockerRabbitMQRule;
-import org.apache.james.modules.TestESMetricReporterModule;
-import org.apache.james.modules.TestElasticSearchModule;
+import org.apache.james.modules.TestEmbeddedESMetricReporterModule;
+import org.apache.james.modules.TestEmbeddedElasticSearchModule;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.TestRabbitMQModule;
 import org.apache.james.modules.objectstorage.aws.s3.DockerAwsS3TestRule;
 import org.apache.james.server.CassandraTruncateTableTask;
 import org.apache.james.server.core.configuration.Configuration;
-
 import org.junit.rules.TemporaryFolder;
 
 import com.github.fge.lambdas.runnable.ThrowingRunnable;
 import com.google.inject.multibindings.Multibinder;
+
 import cucumber.api.java.After;
 import cucumber.api.java.Before;
 import cucumber.runtime.java.guice.ScenarioScoped;
@@ -86,10 +87,10 @@ public class RabbitMQAwsS3Stepdefs {
         mainStepdefs.jmapServer = GuiceJamesServer.forConfiguration(configuration)
                 .combineWith(CassandraRabbitMQJamesServerMain.MODULES)
                 .overrideWith(new TestJMAPServerModule(JMAP_GET_MESSAGE_LIST_MAXIMUM_LIMIT))
-                .overrideWith(new TestESMetricReporterModule())
+                .overrideWith(new TestEmbeddedESMetricReporterModule())
                 .overrideWith(new TestRabbitMQModule(rabbitMQServer.dockerRabbitMQ()))
                 .overrideWith(swiftServer.getModule())
-                .overrideWith(new TestElasticSearchModule(embeddedElasticSearch))
+                .overrideWith(new TestEmbeddedElasticSearchModule(embeddedElasticSearch))
                 .overrideWith(cassandraServer.getModule())
                 .overrideWith(binder -> binder.bind(TextExtractor.class).to(DefaultTextExtractor.class))
                 .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class))
diff --git a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/CassandraJmapExtension.java b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/CassandraJmapExtension.java
index 3451c21..c89aea7 100644
--- a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/CassandraJmapExtension.java
+++ b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/CassandraJmapExtension.java
@@ -28,8 +28,8 @@ import org.apache.james.GuiceJamesServer;
 import org.apache.james.backends.es.EmbeddedElasticSearch;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.store.search.PDFTextExtractor;
-import org.apache.james.modules.TestESMetricReporterModule;
-import org.apache.james.modules.TestElasticSearchModule;
+import org.apache.james.modules.TestEmbeddedESMetricReporterModule;
+import org.apache.james.modules.TestEmbeddedElasticSearchModule;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.server.core.configuration.Configuration;
 import org.apache.james.util.Runnables;
@@ -68,9 +68,9 @@ public class CassandraJmapExtension implements BeforeAllCallback, AfterAllCallba
         return GuiceJamesServer.forConfiguration(configuration)
                 .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE).overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
                 .overrideWith(new TestJMAPServerModule(LIMIT_TO_20_MESSAGES))
-                .overrideWith(new TestESMetricReporterModule())
+                .overrideWith(new TestEmbeddedESMetricReporterModule())
                 .overrideWith(cassandra.getModule())
-                .overrideWith(new TestElasticSearchModule(elasticSearch))
+                .overrideWith(new TestEmbeddedElasticSearchModule(elasticSearch))
                 .overrideWith(binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION))
                 .overrideWith(new UnauthorizedModule())
                 .overrideWith((binder -> binder.bind(CleanupTasksPerformer.class).asEagerSingleton()));


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


[james-project] 08/14: JAMES-2712 Linshare blob export mechanism 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 e1f435e071dfd1fe613033147fb60bc54a6daaaa
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Apr 26 11:37:18 2019 +0700

    JAMES-2712 Linshare blob export mechanism integration tests
---
 .../jmap-integration-testing-common/pom.xml        |  10 +
 ...LinshareBlobExportMechanismIntegrationTest.java | 274 +++++++++++++++++++++
 2 files changed, 284 insertions(+)

diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml
index 5925135..b2b2fc6 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml
@@ -35,6 +35,16 @@
     <dependencies>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-linshare</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-linshare</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>apache-james-mailbox-api</artifactId>
             <type>test-jar</type>
             <scope>test</scope>
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java
new file mode 100644
index 0000000..66e31bd
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java
@@ -0,0 +1,274 @@
+/****************************************************************
+ * 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.methods.integration;
+
+import static io.restassured.RestAssured.given;
+import static io.restassured.RestAssured.with;
+import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
+import static org.apache.james.jmap.JmapCommonRequests.getOutboxId;
+import static org.apache.james.jmap.JmapCommonRequests.listMessageIdsForAccount;
+import static org.apache.james.jmap.JmapURIBuilder.baseUri;
+import static org.apache.james.jmap.TestingConstants.ARGUMENTS;
+import static org.apache.james.jmap.TestingConstants.DOMAIN;
+import static org.apache.james.jmap.TestingConstants.LOCALHOST_IP;
+import static org.apache.james.jmap.TestingConstants.calmlyAwait;
+import static org.apache.james.jmap.TestingConstants.jmapRequestSpecBuilder;
+import static org.apache.james.linshare.LinshareFixture.USER_1;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.jmap.ExportRequest;
+import org.apache.james.jmap.api.access.AccessToken;
+import org.apache.james.linshare.LinshareExtension;
+import org.apache.james.linshare.client.LinshareAPI;
+import org.apache.james.mailbox.DefaultMailboxes;
+import org.apache.james.mailbox.model.MailboxConstants;
+import org.apache.james.mailbox.probe.MailboxProbe;
+import org.apache.james.modules.MailboxProbeImpl;
+import org.apache.james.modules.protocols.ImapGuiceProbe;
+import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.IMAPMessageReader;
+import org.apache.james.utils.JmapGuiceProbe;
+import org.apache.james.utils.WebAdminGuiceProbe;
+import org.apache.james.webadmin.WebAdminUtils;
+import org.awaitility.Duration;
+import org.awaitility.core.ConditionFactory;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import io.restassured.RestAssured;
+import io.restassured.parsing.Parser;
+import io.restassured.specification.RequestSpecification;
+
+public abstract class LinshareBlobExportMechanismIntegrationTest {
+    private static final String HOMER = "homer@" + DOMAIN;
+    private static final String BART = "bart@" + DOMAIN;
+    private static final String HOMER_PASSWORD = "homerPassword";
+    private static final String BART_PASSWORD = "bartPassword";
+    private static final ConditionFactory WAIT_TEN_SECONDS = calmlyAwait.atMost(Duration.TEN_SECONDS);
+    private static final String SUBJECT = "This mail will be restored from the vault!!";
+    private static final String MATCH_ALL_QUERY = "{" +
+        "\"combinator\": \"and\"," +
+        "\"criteria\": []" +
+        "}";
+    private static final ExportRequest EXPORT_ALL_HOMER_MESSAGES_TO_USER_1 = ExportRequest
+        .userExportFrom(HOMER)
+        .exportTo(USER_1.getUsername())
+        .query(MATCH_ALL_QUERY);
+
+    private AccessToken homerAccessToken;
+    private AccessToken bartAccessToken;
+    private GuiceJamesServer jmapServer;
+    private RequestSpecification webAdminApi;
+    private RequestSpecification fakeSmtpRequestSpecification;
+    private LinshareAPI user1LinshareAPI;
+
+    @RegisterExtension
+    private IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+
+    @BeforeEach
+    void setup(GuiceJamesServer jmapServer) throws Throwable {
+        this.jmapServer = jmapServer;
+
+        jmapServer.getProbe(DataProbeImpl.class)
+            .fluent()
+            .addDomain(DOMAIN)
+            .addUser(HOMER, HOMER_PASSWORD)
+            .addUser(BART, BART_PASSWORD);
+
+        RestAssured.requestSpecification = jmapRequestSpecBuilder
+            .setPort(jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort())
+            .build();
+        RestAssured.defaultParser = Parser.JSON;
+
+        webAdminApi = WebAdminUtils.spec(jmapServer.getProbe(WebAdminGuiceProbe.class).getWebAdminPort());
+
+        MailboxProbe mailboxProbe = jmapServer.getProbe(MailboxProbeImpl.class);
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, HOMER, DefaultMailboxes.INBOX);
+
+        homerAccessToken = authenticateJamesUser(baseUri(jmapServer), HOMER, HOMER_PASSWORD);
+        bartAccessToken = authenticateJamesUser(baseUri(jmapServer), BART, BART_PASSWORD);
+        user1LinshareAPI = new LinshareExtension().getAPIFor(USER_1);
+
+        fakeSmtpRequestSpecification = given(new LinshareExtension().getLinshare().fakeSmtpRequestSpecification());
+    }
+
+    @Test
+    void exportShouldShareTheDocumentViaLinShareWhenJmapDelete() {
+        bartSendMessageToHomer();
+
+        WAIT_TEN_SECONDS.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 1);
+
+        homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
+        WAIT_TEN_SECONDS.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
+
+        exportVaultContent(EXPORT_ALL_HOMER_MESSAGES_TO_USER_1);
+
+        assertThat(user1LinshareAPI.receivedShares())
+            .hasSize(1)
+            .allSatisfy(receivedShare -> assertThat(receivedShare.getDocument().getName()).endsWith(".zip"))
+            .allSatisfy(receivedShare -> assertThat(receivedShare.getSender().getMail()).isEqualTo(USER_1.getUsername()));
+    }
+
+    @Test
+    void exportShouldShareTheDocumentViaLinShareWhenImapDelete() throws Exception {
+        bartSendMessageToHomer();
+
+        WAIT_TEN_SECONDS.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 1);
+
+        imapMessageReader.connect(LOCALHOST_IP, jmapServer.getProbe(ImapGuiceProbe.class).getImapPort())
+            .login(HOMER, HOMER_PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .setFlagsForAllMessagesInMailbox("\\Deleted");
+        imapMessageReader.expunge();
+
+        WAIT_TEN_SECONDS.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
+
+        exportVaultContent(EXPORT_ALL_HOMER_MESSAGES_TO_USER_1);
+
+        assertThat(user1LinshareAPI.receivedShares())
+            .hasSize(1)
+            .allSatisfy(receivedShare -> assertThat(receivedShare.getDocument().getName()).endsWith(".zip"))
+            .allSatisfy(receivedShare -> assertThat(receivedShare.getSender().getMail()).isEqualTo(USER_1.getUsername()));
+    }
+
+    @Test
+    void exportShouldSendAnEmailToShareeWhenJmapDelete() {
+        bartSendMessageToHomer();
+
+        WAIT_TEN_SECONDS.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 1);
+
+        homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
+        WAIT_TEN_SECONDS.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
+
+        exportVaultContent(EXPORT_ALL_HOMER_MESSAGES_TO_USER_1);
+
+        WAIT_TEN_SECONDS.untilAsserted(
+            () -> fakeSmtpRequestSpecification
+                .get("/api/email")
+            .then()
+                .body("", hasSize(2)));
+
+        fakeSmtpRequestSpecification
+            .get("/api/email")
+        .then()
+            .body("[1].subject", containsString("John Doe has shared a file with you"))
+            .body("[1].to", hasItem(USER_1.getUsername()));
+    }
+
+    @Test
+    void exportShouldSendAnEmailToShareeWhenImapDelete() throws Exception {
+        bartSendMessageToHomer();
+
+        WAIT_TEN_SECONDS.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 1);
+
+        imapMessageReader.connect(LOCALHOST_IP, jmapServer.getProbe(ImapGuiceProbe.class).getImapPort())
+            .login(HOMER, HOMER_PASSWORD)
+            .select(IMAPMessageReader.INBOX)
+            .setFlagsForAllMessagesInMailbox("\\Deleted");
+        imapMessageReader.expunge();
+
+        WAIT_TEN_SECONDS.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
+
+        exportVaultContent(EXPORT_ALL_HOMER_MESSAGES_TO_USER_1);
+
+        WAIT_TEN_SECONDS.untilAsserted(
+                () -> fakeSmtpRequestSpecification
+                    .get("/api/email")
+                .then()
+                    .body("", hasSize(2)));
+
+        fakeSmtpRequestSpecification
+            .get("/api/email")
+        .then()
+            .body("[1].subject", containsString("John Doe has shared a file with you"))
+            .body("[1].to", hasItem(USER_1.getUsername()));
+    }
+
+    private void bartSendMessageToHomer() {
+        String messageCreationId = "creationId";
+        String outboxId = getOutboxId(bartAccessToken);
+        String textBody = "You got mail!";
+        String requestBody = "[" +
+            "  [" +
+            "    \"setMessages\"," +
+            "    {" +
+            "      \"create\": { \"" + messageCreationId  + "\" : {" +
+            "        \"from\": { \"name\": \"user2\", \"email\": \"" + BART + "\"}," +
+            "        \"to\": [{ \"name\": \"user1\", \"email\": \"" + HOMER + "\"}]," +
+            "        \"subject\": \"" + SUBJECT + "\"," +
+            "        \"textBody\": \"" + textBody + "\"," +
+            "        \"htmlBody\": \"Test <b>body</b>, HTML version\"," +
+            "        \"mailboxIds\": [\"" + outboxId + "\"] " +
+            "      }}" +
+            "    }," +
+            "    \"#0\"" +
+            "  ]" +
+            "]";
+
+        with()
+            .header("Authorization", bartAccessToken.serialize())
+            .body(requestBody)
+            .post("/jmap")
+        .then()
+            .extract()
+            .body()
+            .path(ARGUMENTS + ".created." + messageCreationId + ".id");
+    }
+
+    private void homerDeletesMessages(List<String> idsToDestroy) {
+        deleteMessages(homerAccessToken, idsToDestroy);
+    }
+
+    private void deleteMessages(AccessToken accessToken, List<String> idsToDestroy) {
+        String idString = idsToDestroy.stream()
+            .map(id -> "\"" + id + "\"")
+            .collect(Collectors.joining(","));
+
+        with()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"setMessages\", {\"destroy\": [" + idString + "]}, \"#0\"]]")
+            .post("/jmap");
+    }
+
+    private void exportVaultContent(ExportRequest exportRequest) {
+        String taskId =
+            webAdminApi.with()
+                .queryParam("action", "export")
+                .queryParam("exportTo", exportRequest.getSharee())
+                .body(exportRequest.getMatchingQuery())
+                .post("/deletedMessages/users/" + exportRequest.getUserExportFrom())
+            .jsonPath()
+                .get("taskId");
+
+        webAdminApi.with()
+            .get("/tasks/" + taskId + "/await")
+        .then()
+            .body("status", is("completed"));
+    }
+}


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


[james-project] 09/14: JAMES-2712 Memory implementation of Linshare blob export mechanism 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 6dd31b114e2a18477273eef16dc72ee915b0ebe1
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Apr 26 11:37:45 2019 +0700

    JAMES-2712 Memory implementation of Linshare blob export mechanism integration tests
---
 .../memory-jmap-integration-testing/pom.xml        |  7 +++
 ...LinshareBlobExportMechanismIntegrationTest.java | 59 ++++++++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml
index 2cf9aab..18ec2f7 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml
@@ -35,6 +35,12 @@
     <dependencies>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-linshare</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>apache-james-mailbox-api</artifactId>
             <type>test-jar</type>
             <scope>test</scope>
@@ -59,6 +65,7 @@
         <dependency>
             <groupId>${james.groupId}</groupId>
             <artifactId>blob-export-guice</artifactId>
+            <type>test-jar</type>
             <scope>test</scope>
         </dependency>
         <dependency>
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
new file mode 100644
index 0000000..97aa5bc
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryLinshareBlobExportMechanismIntegrationTest.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.jmap.memory;
+
+import org.apache.james.GuiceJamesServer;
+import org.apache.james.JamesServerBuilder;
+import org.apache.james.JamesServerExtension;
+import org.apache.james.MemoryJamesServerMain;
+import org.apache.james.jmap.methods.integration.LinshareBlobExportMechanismIntegrationTest;
+import org.apache.james.mailrepository.api.MailRepositoryUrl;
+import org.apache.james.modules.LinshareGuiceExtension;
+import org.apache.james.modules.TestJMAPServerModule;
+import org.apache.james.modules.mailbox.PreDeletionHookConfiguration;
+import org.apache.james.modules.mailbox.PreDeletionHooksConfiguration;
+import org.apache.james.vault.DeletedMessageVaultHook;
+import org.apache.james.vault.MailRepositoryDeletedMessageVault;
+import org.apache.james.webadmin.WebAdminConfiguration;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+class MemoryLinshareBlobExportMechanismIntegrationTest extends LinshareBlobExportMechanismIntegrationTest {
+
+    private static final int LIMIT_TO_10_MESSAGES = 10;
+
+    private final LinshareGuiceExtension linshareGuiceExtension = new LinshareGuiceExtension();
+
+    @RegisterExtension
+    JamesServerExtension jamesServerExtension = new JamesServerBuilder()
+        .extension(linshareGuiceExtension)
+        .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
+            .combineWith(MemoryJamesServerMain.IN_MEMORY_SERVER_AGGREGATE_MODULE)
+            .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
+            .overrideWith(binder -> {
+                binder.bind(WebAdminConfiguration.class)
+                    .toInstance(WebAdminConfiguration.TEST_CONFIGURATION);
+                binder.bind(PreDeletionHooksConfiguration.class)
+                    .toInstance(PreDeletionHooksConfiguration.forHooks(
+                        PreDeletionHookConfiguration.forClass(DeletedMessageVaultHook.class)));
+                binder.bind(MailRepositoryDeletedMessageVault.Configuration.class)
+                    .toInstance(new MailRepositoryDeletedMessageVault.Configuration(MailRepositoryUrl.from("memory://var/deletedMessages/user")));
+            }))
+        .build();
+}


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


[james-project] 11/14: JAMES-2712 Extract deleteMessages to JMAP common requests

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 dc1fff513cf96668df17c4bafa7e48f53c6bf2d2
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu May 2 11:07:27 2019 +0700

    JAMES-2712 Extract deleteMessages to JMAP common requests
---
 .../test/java/org/apache/james/jmap/JmapCommonRequests.java | 12 ++++++++++++
 .../jmap/methods/integration/DeletedMessagesVaultTest.java  | 13 +------------
 .../LinshareBlobExportMechanismIntegrationTest.java         | 13 +------------
 3 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JmapCommonRequests.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JmapCommonRequests.java
index fe3f84d..fec460e 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JmapCommonRequests.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JmapCommonRequests.java
@@ -29,6 +29,7 @@ import static org.hamcrest.Matchers.not;
 
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import org.apache.james.jmap.api.access.AccessToken;
 import org.apache.james.mailbox.Role;
@@ -151,4 +152,15 @@ public class JmapCommonRequests {
             .expectBody(NOT_UPDATED, not(hasKey(messageId)));
         return builder.build();
     }
+
+    public static void deleteMessages(AccessToken accessToken, List<String> idsToDestroy) {
+        String idString = idsToDestroy.stream()
+            .map(id -> "\"" + id + "\"")
+            .collect(Collectors.joining(","));
+
+        with()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"setMessages\", {\"destroy\": [" + idString + "]}, \"#0\"]]")
+            .post("/jmap");
+    }
 }
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
index a979a5e..f8cc0f6 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
@@ -23,6 +23,7 @@ import static io.restassured.RestAssured.given;
 import static io.restassured.RestAssured.with;
 import static io.restassured.config.ParamConfig.UpdateStrategy.REPLACE;
 import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
+import static org.apache.james.jmap.JmapCommonRequests.deleteMessages;
 import static org.apache.james.jmap.JmapCommonRequests.getLastMessageId;
 import static org.apache.james.jmap.JmapCommonRequests.getOutboxId;
 import static org.apache.james.jmap.JmapCommonRequests.listMessageIdsForAccount;
@@ -44,7 +45,6 @@ import java.time.Clock;
 import java.time.Instant;
 import java.time.temporal.ChronoUnit;
 import java.util.List;
-import java.util.stream.Collectors;
 
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.filesystem.api.FileSystem;
@@ -809,17 +809,6 @@ public abstract class DeletedMessagesVaultTest {
         deleteMessages(bartAccessToken, idsToDestroy);
     }
 
-    private void deleteMessages(AccessToken accessToken, List<String> idsToDestroy) {
-        String idString = idsToDestroy.stream()
-            .map(id -> "\"" + id + "\"")
-            .collect(Collectors.joining(","));
-
-        with()
-            .header("Authorization", accessToken.serialize())
-            .body("[[\"setMessages\", {\"destroy\": [" + idString + "]}, \"#0\"]]")
-            .post("/jmap");
-    }
-
     private void restoreAllMessagesOfHomer() {
         restoreMessagesFor(HOMER);
     }
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java
index 66e31bd..58be63e 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java
@@ -22,6 +22,7 @@ package org.apache.james.jmap.methods.integration;
 import static io.restassured.RestAssured.given;
 import static io.restassured.RestAssured.with;
 import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
+import static org.apache.james.jmap.JmapCommonRequests.deleteMessages;
 import static org.apache.james.jmap.JmapCommonRequests.getOutboxId;
 import static org.apache.james.jmap.JmapCommonRequests.listMessageIdsForAccount;
 import static org.apache.james.jmap.JmapURIBuilder.baseUri;
@@ -38,7 +39,6 @@ import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.is;
 
 import java.util.List;
-import java.util.stream.Collectors;
 
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.jmap.ExportRequest;
@@ -245,17 +245,6 @@ public abstract class LinshareBlobExportMechanismIntegrationTest {
         deleteMessages(homerAccessToken, idsToDestroy);
     }
 
-    private void deleteMessages(AccessToken accessToken, List<String> idsToDestroy) {
-        String idString = idsToDestroy.stream()
-            .map(id -> "\"" + id + "\"")
-            .collect(Collectors.joining(","));
-
-        with()
-            .header("Authorization", accessToken.serialize())
-            .body("[[\"setMessages\", {\"destroy\": [" + idString + "]}, \"#0\"]]")
-            .post("/jmap");
-    }
-
     private void exportVaultContent(ExportRequest exportRequest) {
         String taskId =
             webAdminApi.with()


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


[james-project] 12/14: JAMES-2712 Extract vault requests to a proper helper class

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 0eab09fdc7a4d5b425221a41a820c2748a9ba65e
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Thu May 2 11:53:13 2019 +0700

    JAMES-2712 Extract vault requests to a proper helper class
---
 .../james/jmap/DeletedMessagesVaultRequests.java   | 83 +++++++++++++++++++++
 .../integration/DeletedMessagesVaultTest.java      | 85 ++++------------------
 ...LinshareBlobExportMechanismIntegrationTest.java | 26 ++-----
 3 files changed, 104 insertions(+), 90 deletions(-)

diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/DeletedMessagesVaultRequests.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/DeletedMessagesVaultRequests.java
new file mode 100644
index 0000000..21ace61
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/DeletedMessagesVaultRequests.java
@@ -0,0 +1,83 @@
+/****************************************************************
+ * 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.hamcrest.Matchers.is;
+
+import io.restassured.specification.RequestSpecification;
+
+public class DeletedMessagesVaultRequests {
+
+    public static void exportVaultContent(RequestSpecification webAdminApi, ExportRequest exportRequest) {
+        String taskId =
+            webAdminApi.with()
+                .queryParam("action", "export")
+                .queryParam("exportTo", exportRequest.getSharee())
+                .body(exportRequest.getMatchingQuery())
+                .post("/deletedMessages/users/" + exportRequest.getUserExportFrom())
+            .jsonPath()
+                .get("taskId");
+
+        webAdminApi.with()
+            .get("/tasks/" + taskId + "/await")
+        .then()
+            .body("status", is("completed"));
+    }
+
+    public static void restoreMessagesForUserWithQuery(RequestSpecification webAdminApi, String user, String criteria) {
+        String taskId = webAdminApi.with()
+            .body(criteria)
+            .post("/deletedMessages/users/" + user + "?action=restore")
+        .jsonPath()
+            .get("taskId");
+
+        webAdminApi.given()
+            .get("/tasks/" + taskId + "/await")
+        .then()
+            .body("status", is("completed"));
+    }
+
+    public static void purgeVault(RequestSpecification webAdminApi) {
+        String taskId =
+            webAdminApi.with()
+                .queryParam("scope", "expired")
+                .delete("/deletedMessages")
+            .jsonPath()
+                .get("taskId");
+
+        webAdminApi.with()
+            .get("/tasks/" + taskId + "/await")
+        .then()
+            .body("status", is("completed"));
+    }
+
+    public static void deleteFromVault(RequestSpecification webAdminApi, String user, String messageId) {
+        String taskId =
+            webAdminApi.with()
+                .delete("/deletedMessages/users/" + user + "/messages/" + messageId)
+            .jsonPath()
+                .get("taskId");
+
+        webAdminApi.with()
+            .get("/tasks/" + taskId + "/await")
+        .then()
+            .body("status", is("completed"));
+    }
+}
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
index f8cc0f6..60faec2 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
@@ -22,6 +22,10 @@ package org.apache.james.jmap.methods.integration;
 import static io.restassured.RestAssured.given;
 import static io.restassured.RestAssured.with;
 import static io.restassured.config.ParamConfig.UpdateStrategy.REPLACE;
+import static org.apache.james.jmap.DeletedMessagesVaultRequests.deleteFromVault;
+import static org.apache.james.jmap.DeletedMessagesVaultRequests.exportVaultContent;
+import static org.apache.james.jmap.DeletedMessagesVaultRequests.purgeVault;
+import static org.apache.james.jmap.DeletedMessagesVaultRequests.restoreMessagesForUserWithQuery;
 import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
 import static org.apache.james.jmap.JmapCommonRequests.deleteMessages;
 import static org.apache.james.jmap.JmapCommonRequests.getLastMessageId;
@@ -37,7 +41,6 @@ import static org.apache.james.mailbox.backup.ZipAssert.EntryChecks.hasName;
 import static org.apache.james.mailbox.backup.ZipAssert.assertThatZip;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.hamcrest.Matchers.hasItem;
-import static org.hamcrest.Matchers.is;
 
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -258,7 +261,7 @@ public abstract class DeletedMessagesVaultTest {
             "    }" +
             "  ]" +
             "}";
-        restoreMessagesFor(HOMER, query);
+        restoreMessagesForUserWithQuery(webAdminApi, HOMER, query);
 
         WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 1);
 
@@ -294,7 +297,7 @@ public abstract class DeletedMessagesVaultTest {
             "    }" +
             "  ]" +
             "}";
-        restoreMessagesFor(HOMER, query);
+        restoreMessagesForUserWithQuery(webAdminApi, HOMER, query);
 
 
         Thread.sleep(Duration.FIVE_SECONDS.getValueInMS());
@@ -591,7 +594,7 @@ public abstract class DeletedMessagesVaultTest {
         WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
 
         clock.setInstant(ONE_DAY_AFTER_ONE_YEAR_EXPIRATION);
-        purgeVault();
+        purgeVault(webAdminApi);
 
         String fileLocation = exportAndGetFileLocationFromLastMail(EXPORT_ALL_HOMER_MESSAGES_TO_BART, bartAccessToken);
         try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) {
@@ -616,7 +619,7 @@ public abstract class DeletedMessagesVaultTest {
         homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
         WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
 
-        purgeVault();
+        purgeVault(webAdminApi);
 
         String fileLocation = exportAndGetFileLocationFromLastMail(EXPORT_ALL_HOMER_MESSAGES_TO_BART, bartAccessToken);
         try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) {
@@ -635,7 +638,7 @@ public abstract class DeletedMessagesVaultTest {
         homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
         WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
 
-        purgeVault();
+        purgeVault(webAdminApi);
 
         String fileLocation = exportAndGetFileLocationFromLastMail(EXPORT_ALL_HOMER_MESSAGES_TO_BART, bartAccessToken);
         try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) {
@@ -652,7 +655,7 @@ public abstract class DeletedMessagesVaultTest {
         WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
 
         clock.setInstant(ONE_DAY_AFTER_ONE_YEAR_EXPIRATION);
-        purgeVault();
+        purgeVault(webAdminApi);
 
         assertThat(listMessageIdsForAccount(homerAccessToken))
             .hasSize(0);
@@ -668,7 +671,7 @@ public abstract class DeletedMessagesVaultTest {
         homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
         WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
 
-        deleteVault(HOMER, messageIdOfHomer);
+        deleteFromVault(webAdminApi, HOMER, messageIdOfHomer);
 
         String fileLocation = exportAndGetFileLocationFromLastMail(EXPORT_ALL_HOMER_MESSAGES_TO_BART, bartAccessToken);
         try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) {
@@ -683,7 +686,7 @@ public abstract class DeletedMessagesVaultTest {
 
         String messageIdOfHomer = listMessageIdsForAccount(homerAccessToken).get(0);
 
-        deleteVault(HOMER, messageIdOfHomer);
+        deleteFromVault(webAdminApi, HOMER, messageIdOfHomer);
 
         String fileLocation = exportAndGetFileLocationFromLastMail(EXPORT_ALL_HOMER_MESSAGES_TO_BART, bartAccessToken);
         try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) {
@@ -702,7 +705,7 @@ public abstract class DeletedMessagesVaultTest {
         homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
         WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
 
-        deleteVault(HOMER, messageIdOfBart);
+        deleteFromVault(webAdminApi, HOMER, messageIdOfBart);
 
         String fileLocation = exportAndGetFileLocationFromLastMail(EXPORT_ALL_HOMER_MESSAGES_TO_BART, bartAccessToken);
         try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) {
@@ -721,7 +724,7 @@ public abstract class DeletedMessagesVaultTest {
         homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
         WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
 
-        deleteVault(HOMER, messageIdOfHomer);
+        deleteFromVault(webAdminApi, HOMER, messageIdOfHomer);
 
         assertThat(listMessageIdsForAccount(homerAccessToken))
             .hasSize(0);
@@ -729,7 +732,7 @@ public abstract class DeletedMessagesVaultTest {
 
     private String exportAndGetFileLocationFromLastMail(ExportRequest exportRequest, AccessToken shareeAccessToken) {
         int currentNumberOfMessages = listMessageIdsForAccount(shareeAccessToken).size();
-        exportVaultContent(exportRequest);
+        exportVaultContent(webAdminApi, exportRequest);
 
         WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(shareeAccessToken).size() == currentNumberOfMessages + 1);
         String exportingMessageId = getLastMessageId(shareeAccessToken);
@@ -814,20 +817,7 @@ public abstract class DeletedMessagesVaultTest {
     }
 
     private void restoreMessagesFor(String user) {
-        restoreMessagesFor(user, MATCH_ALL_QUERY);
-    }
-
-    private void restoreMessagesFor(String user, String criteria) {
-        String taskId = webAdminApi.with()
-            .body(criteria)
-            .post("/deletedMessages/users/" + user + "?action=restore")
-            .jsonPath()
-            .get("taskId");
-
-        webAdminApi.given()
-            .get("/tasks/" + taskId + "/await")
-            .then()
-            .body("status", is("completed"));
+        restoreMessagesForUserWithQuery(webAdminApi, user, MATCH_ALL_QUERY);
     }
 
     private void homerMovesTheMailInAnotherMailbox(String messageId) {
@@ -849,47 +839,4 @@ public abstract class DeletedMessagesVaultTest {
             .when()
             .post("/jmap");
     }
-
-    private void exportVaultContent(ExportRequest exportRequest) {
-        String taskId =
-            webAdminApi.with()
-                .queryParam("action", "export")
-                .queryParam("exportTo", exportRequest.getSharee())
-                .body(exportRequest.getMatchingQuery())
-                .post("/deletedMessages/users/" + exportRequest.getUserExportFrom())
-            .jsonPath()
-                .get("taskId");
-
-        webAdminApi.with()
-                .get("/tasks/" + taskId + "/await")
-            .then()
-                .body("status", is("completed"));
-    }
-
-    private void purgeVault() {
-        String taskId =
-            webAdminApi.with()
-                .queryParam("scope", "expired")
-                .delete("/deletedMessages")
-            .jsonPath()
-                .get("taskId");
-
-        webAdminApi.with()
-            .get("/tasks/" + taskId + "/await")
-        .then()
-            .body("status", is("completed"));
-    }
-
-    private void deleteVault(String user, String messageId) {
-        String taskId =
-            webAdminApi.with()
-                .delete("/deletedMessages/users/" + user + "/messages/" + messageId)
-            .jsonPath()
-                .get("taskId");
-
-        webAdminApi.with()
-            .get("/tasks/" + taskId + "/await")
-        .then()
-            .body("status", is("completed"));
-    }
 }
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java
index 58be63e..8e6c704 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/LinshareBlobExportMechanismIntegrationTest.java
@@ -21,6 +21,7 @@ package org.apache.james.jmap.methods.integration;
 
 import static io.restassured.RestAssured.given;
 import static io.restassured.RestAssured.with;
+import static org.apache.james.jmap.DeletedMessagesVaultRequests.exportVaultContent;
 import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
 import static org.apache.james.jmap.JmapCommonRequests.deleteMessages;
 import static org.apache.james.jmap.JmapCommonRequests.getOutboxId;
@@ -36,7 +37,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.hasItem;
 import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
 
 import java.util.List;
 
@@ -127,7 +127,7 @@ public abstract class LinshareBlobExportMechanismIntegrationTest {
         homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
         WAIT_TEN_SECONDS.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
 
-        exportVaultContent(EXPORT_ALL_HOMER_MESSAGES_TO_USER_1);
+        exportVaultContent(webAdminApi, EXPORT_ALL_HOMER_MESSAGES_TO_USER_1);
 
         assertThat(user1LinshareAPI.receivedShares())
             .hasSize(1)
@@ -149,7 +149,7 @@ public abstract class LinshareBlobExportMechanismIntegrationTest {
 
         WAIT_TEN_SECONDS.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
 
-        exportVaultContent(EXPORT_ALL_HOMER_MESSAGES_TO_USER_1);
+        exportVaultContent(webAdminApi, EXPORT_ALL_HOMER_MESSAGES_TO_USER_1);
 
         assertThat(user1LinshareAPI.receivedShares())
             .hasSize(1)
@@ -166,7 +166,7 @@ public abstract class LinshareBlobExportMechanismIntegrationTest {
         homerDeletesMessages(listMessageIdsForAccount(homerAccessToken));
         WAIT_TEN_SECONDS.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
 
-        exportVaultContent(EXPORT_ALL_HOMER_MESSAGES_TO_USER_1);
+        exportVaultContent(webAdminApi, EXPORT_ALL_HOMER_MESSAGES_TO_USER_1);
 
         WAIT_TEN_SECONDS.untilAsserted(
             () -> fakeSmtpRequestSpecification
@@ -195,7 +195,7 @@ public abstract class LinshareBlobExportMechanismIntegrationTest {
 
         WAIT_TEN_SECONDS.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 0);
 
-        exportVaultContent(EXPORT_ALL_HOMER_MESSAGES_TO_USER_1);
+        exportVaultContent(webAdminApi, EXPORT_ALL_HOMER_MESSAGES_TO_USER_1);
 
         WAIT_TEN_SECONDS.untilAsserted(
                 () -> fakeSmtpRequestSpecification
@@ -244,20 +244,4 @@ public abstract class LinshareBlobExportMechanismIntegrationTest {
     private void homerDeletesMessages(List<String> idsToDestroy) {
         deleteMessages(homerAccessToken, idsToDestroy);
     }
-
-    private void exportVaultContent(ExportRequest exportRequest) {
-        String taskId =
-            webAdminApi.with()
-                .queryParam("action", "export")
-                .queryParam("exportTo", exportRequest.getSharee())
-                .body(exportRequest.getMatchingQuery())
-                .post("/deletedMessages/users/" + exportRequest.getUserExportFrom())
-            .jsonPath()
-                .get("taskId");
-
-        webAdminApi.with()
-            .get("/tasks/" + taskId + "/await")
-        .then()
-            .body("status", is("completed"));
-    }
 }


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


[james-project] 04/14: JAMES-2717 Replace EmbeddedElasticSearchExtension by the docker one

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 ddaa9f8f9c4618a63d8a25430a73b9b1a0247318
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed May 8 14:05:48 2019 +0700

    JAMES-2717 Replace EmbeddedElasticSearchExtension by the docker one
---
 .../src/test/java/org/apache/james/CassandraJamesServerTest.java    | 2 +-
 .../test/java/org/apache/james/CassandraJmapJamesServerTest.java    | 2 +-
 .../org/apache/james/CassandraMailRepositoryIntegrationTest.java    | 2 +-
 .../org/apache/james/CassandraMessageIdManagerInjectionTest.java    | 2 +-
 .../src/test/java/org/apache/james/CassandraNodeConfTest.java       | 6 +++---
 .../test/java/org/apache/james/CassandraVersionCheckingTest.java    | 2 +-
 .../src/test/java/org/apache/james/CassandraWithTikaTest.java       | 2 +-
 .../test/java/org/apache/james/DefaultCassandraJamesServerTest.java | 2 +-
 .../src/test/java/org/apache/james/FixingGhostMailboxTest.java      | 2 +-
 .../src/test/java/org/apache/james/JamesCapabilitiesServerTest.java | 2 +-
 .../test/java/org/apache/james/CassandraLdapJamesServerTest.java    | 2 +-
 .../java/org/apache/james/CassandraLdapJmapJamesServerTest.java     | 2 +-
 .../java/org/apache/james/CassandraRabbitMQJamesServerTest.java     | 2 +-
 .../org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java  | 2 +-
 .../org/apache/james/jmap/cassandra/CassandraSendMDNMethodTest.java | 4 ++--
 .../james/jmap/cassandra/CassandraSpamAssassinContractTest.java     | 4 ++--
 .../apache/james/jmap/rabbitmq/RabbitMQAwsS3SendMDNMethodTest.java  | 4 ++--
 .../james/jmap/rabbitmq/RabbitMQAwsS3SpamAssassinContractTest.java  | 4 ++--
 18 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
index 3982605..5ded794 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java
@@ -34,7 +34,7 @@ class CassandraJamesServerTest implements JamesServerContract {
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension())
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java
index 92ec06f..3995552 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapJamesServerTest.java
@@ -31,7 +31,7 @@ class CassandraJmapJamesServerTest implements JmapJamesServerContract {
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension())
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
index ffc378f..bc4f7b4 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMailRepositoryIntegrationTest.java
@@ -53,7 +53,7 @@ class CassandraMailRepositoryIntegrationTest {
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension())
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMessageIdManagerInjectionTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMessageIdManagerInjectionTest.java
index f245a65..05f5f27 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMessageIdManagerInjectionTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraMessageIdManagerInjectionTest.java
@@ -43,7 +43,7 @@ class CassandraMessageIdManagerInjectionTest {
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension())
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
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 6b0047a..2444764 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
@@ -66,7 +66,7 @@ class CassandraNodeConfTest {
     class NormalBehaviour {
         @RegisterExtension
         JamesServerExtension testExtension = new JamesServerBuilder()
-            .extension(new EmbeddedElasticSearchExtension())
+            .extension(new DockerElasticSearchExtension())
             .extension(new CassandraExtension())
             .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
                 .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
@@ -89,7 +89,7 @@ class CassandraNodeConfTest {
 
         @RegisterExtension
         JamesServerExtension testExtension = new JamesServerBuilder()
-            .extension(new EmbeddedElasticSearchExtension())
+            .extension(new DockerElasticSearchExtension())
             .extension(new CassandraExtension(cassandra))
             .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
                 .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
@@ -114,7 +114,7 @@ class CassandraNodeConfTest {
 
         @RegisterExtension
         JamesServerExtension testExtension = new JamesServerBuilder()
-            .extension(new EmbeddedElasticSearchExtension())
+            .extension(new DockerElasticSearchExtension())
             .extension(new CassandraExtension(cassandra))
             .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
                 .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java
index 6dab649..d7cb7d1 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java
@@ -55,7 +55,7 @@ class CassandraVersionCheckingTest {
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension())
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
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 c967b68..6a5c3b3 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
@@ -32,7 +32,7 @@ class CassandraWithTikaTest implements JamesServerContract {
         new JamesServerBuilder()
             .extension(new CassandraExtension())
             .extension(new  TikaExtension())
-            .extension(new EmbeddedElasticSearchExtension())
+            .extension(new DockerElasticSearchExtension())
             .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
                 .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
                 .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DefaultCassandraJamesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DefaultCassandraJamesServerTest.java
index 362d929..aa850d0 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DefaultCassandraJamesServerTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/DefaultCassandraJamesServerTest.java
@@ -37,7 +37,7 @@ class DefaultCassandraJamesServerTest {
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension())
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
index 0076501..05daf56 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
@@ -96,7 +96,7 @@ public class FixingGhostMailboxTest {
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension(cassandra))
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
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 089f6ec..dd28af5 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
@@ -39,7 +39,7 @@ class JamesCapabilitiesServerTest {
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension())
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java
index dcc156e..5c91b17 100644
--- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java
+++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJamesServerTest.java
@@ -55,7 +55,7 @@ class CassandraLdapJamesServerTest implements JamesServerContract {
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension())
         .extension(new LdapTestExtension())
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
diff --git a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java
index 0d79356..4971cc7 100644
--- a/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java
+++ b/server/container/guice/cassandra-ldap-guice/src/test/java/org/apache/james/CassandraLdapJmapJamesServerTest.java
@@ -27,7 +27,7 @@ class CassandraLdapJmapJamesServerTest implements JmapJamesServerContract {
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension())
         .extension(new LdapTestExtension())
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
index d683171..4c3c8a0 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
@@ -176,7 +176,7 @@ class CassandraRabbitMQJamesServerTest {
 
     private static JamesServerBuilder baseExtensionBuilder() {
         return new JamesServerBuilder()
-            .extension(new EmbeddedElasticSearchExtension())
+            .extension(new DockerElasticSearchExtension())
             .extension(new CassandraExtension())
             .extension(new RabbitMQExtension())
             .server(CONFIGURATION_BUILDER);
diff --git a/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java b/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java
index 1644816..1867638 100644
--- a/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java
+++ b/server/container/guice/cassandra-rabbitmq-ldap-guice/src/test/java/org/apache/james/CassandraRabbitMQLdapJmapJamesServerTest.java
@@ -86,7 +86,7 @@ class CassandraRabbitMQLdapJmapJamesServerTest {
 
     JamesServerBuilder baseJamesServerExtensionBuilder() {
         return new JamesServerBuilder()
-            .extension(new EmbeddedElasticSearchExtension())
+            .extension(new DockerElasticSearchExtension())
             .extension(new CassandraExtension())
             .extension(new RabbitMQExtension())
             .extension(new LdapTestExtension());
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSendMDNMethodTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSendMDNMethodTest.java
index 31798fe..28878f0 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSendMDNMethodTest.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSendMDNMethodTest.java
@@ -22,7 +22,7 @@ package org.apache.james.jmap.cassandra;
 import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
 
 import org.apache.james.CassandraExtension;
-import org.apache.james.EmbeddedElasticSearchExtension;
+import org.apache.james.DockerElasticSearchExtension;
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.JamesServerBuilder;
 import org.apache.james.JamesServerExtension;
@@ -40,7 +40,7 @@ public class CassandraSendMDNMethodTest extends SendMDNMethodTest {
 
     @RegisterExtension
     JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension())
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSpamAssassinContractTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSpamAssassinContractTest.java
index 7d8ad0c..9dbe045 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSpamAssassinContractTest.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSpamAssassinContractTest.java
@@ -21,7 +21,7 @@ package org.apache.james.jmap.cassandra;
 import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
 
 import org.apache.james.CassandraExtension;
-import org.apache.james.EmbeddedElasticSearchExtension;
+import org.apache.james.DockerElasticSearchExtension;
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.JamesServerBuilder;
 import org.apache.james.JamesServerExtension;
@@ -39,7 +39,7 @@ class CassandraSpamAssassinContractTest implements SpamAssassinContract {
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension())
         .extension(spamAssassinExtension)
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
diff --git a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQAwsS3SendMDNMethodTest.java b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQAwsS3SendMDNMethodTest.java
index 17de893..c0ebee9 100644
--- a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQAwsS3SendMDNMethodTest.java
+++ b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQAwsS3SendMDNMethodTest.java
@@ -21,7 +21,7 @@ package org.apache.james.jmap.rabbitmq;
 
 import org.apache.james.CassandraExtension;
 import org.apache.james.CassandraRabbitMQJamesServerMain;
-import org.apache.james.EmbeddedElasticSearchExtension;
+import org.apache.james.DockerElasticSearchExtension;
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.JamesServerBuilder;
 import org.apache.james.JamesServerExtension;
@@ -41,7 +41,7 @@ public class RabbitMQAwsS3SendMDNMethodTest extends SendMDNMethodTest {
 
     @RegisterExtension
     JamesServerExtension testExtension = new JamesServerBuilder()
-            .extension(new EmbeddedElasticSearchExtension())
+            .extension(new DockerElasticSearchExtension())
             .extension(new CassandraExtension())
             .extension(new AwsS3BlobStoreExtension())
             .extension(new RabbitMQExtension())
diff --git a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQAwsS3SpamAssassinContractTest.java b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQAwsS3SpamAssassinContractTest.java
index bf05180..8f4c5ac 100644
--- a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQAwsS3SpamAssassinContractTest.java
+++ b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQAwsS3SpamAssassinContractTest.java
@@ -20,7 +20,7 @@ package org.apache.james.jmap.rabbitmq;
 
 import org.apache.james.CassandraExtension;
 import org.apache.james.CassandraRabbitMQJamesServerMain;
-import org.apache.james.EmbeddedElasticSearchExtension;
+import org.apache.james.DockerElasticSearchExtension;
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.JamesServerBuilder;
 import org.apache.james.JamesServerExtension;
@@ -40,7 +40,7 @@ class RabbitMQAwsS3SpamAssassinContractTest implements SpamAssassinContract {
     private static final SpamAssassinModuleExtension spamAssassinExtension = new SpamAssassinModuleExtension();
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(new EmbeddedElasticSearchExtension())
+        .extension(new DockerElasticSearchExtension())
         .extension(new CassandraExtension())
         .extension(new RabbitMQExtension())
         .extension(new AwsS3BlobStoreExtension())


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


[james-project] 03/14: JAMES-2717 Replace EmbeddedElasticSearchRule by the docker one

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 9b2a3292ea2a688865efcd4513fab53d8d59df39
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Tue May 7 18:41:32 2019 +0700

    JAMES-2717 Replace EmbeddedElasticSearchRule by the docker one
---
 .../org/apache/james/CassandraJmapTestRule.java    |  9 ++--
 .../apache/james/EmbeddedElasticSearchRule.java    | 61 ----------------------
 .../james/CassandraRabbitMQAwsS3JmapTestRule.java  | 10 ++--
 .../james/CassandraRabbitMQSwiftJmapTestRule.java  |  9 ++--
 4 files changed, 18 insertions(+), 71 deletions(-)

diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java
index b0a3ef5..ac072e2 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java
@@ -25,7 +25,7 @@ import java.io.IOException;
 
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.store.search.PDFTextExtractor;
-import org.apache.james.modules.TestESMetricReporterModule;
+import org.apache.james.modules.TestDockerESMetricReporterModule;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.server.core.configuration.Configuration;
 import org.apache.james.webadmin.WebAdminConfiguration;
@@ -42,17 +42,20 @@ public class CassandraJmapTestRule implements TestRule {
     private final TemporaryFolder temporaryFolder;
 
     public static CassandraJmapTestRule defaultTestRule() {
-        return new CassandraJmapTestRule(new EmbeddedElasticSearchRule());
+        return new CassandraJmapTestRule();
     }
 
     private final GuiceModuleTestRule guiceModuleTestRule;
+    private final DockerElasticSearchRule dockerElasticSearchRule;
 
     public CassandraJmapTestRule(GuiceModuleTestRule... guiceModuleTestRule) {
         TempFilesystemTestRule tempFilesystemTestRule = new TempFilesystemTestRule();
+        this.dockerElasticSearchRule = new DockerElasticSearchRule();
         this.temporaryFolder = tempFilesystemTestRule.getTemporaryFolder();
         this.guiceModuleTestRule =
                 AggregateGuiceModuleTestRule
                     .of(guiceModuleTestRule)
+                    .aggregate(dockerElasticSearchRule)
                     .aggregate(tempFilesystemTestRule);
     }
 
@@ -66,7 +69,7 @@ public class CassandraJmapTestRule implements TestRule {
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
             .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
             .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
-            .overrideWith(new TestESMetricReporterModule())
+            .overrideWith(new TestDockerESMetricReporterModule(dockerElasticSearchRule.getDockerEs().getHttpHost()))
             .overrideWith(guiceModuleTestRule.getModule())
             .overrideWith((binder -> binder.bind(CleanupTasksPerformer.class).asEagerSingleton()))
             .overrideWith(binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION))
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
deleted file mode 100644
index b4c524f..0000000
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java
+++ /dev/null
@@ -1,61 +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;
-
-import org.apache.james.backends.es.EmbeddedElasticSearch;
-import org.apache.james.modules.TestEmbeddedElasticSearchModule;
-import org.elasticsearch.node.Node;
-import org.junit.rules.RuleChain;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-import com.google.inject.Module;
-
-
-public class EmbeddedElasticSearchRule implements GuiceModuleTestRule {
-
-    private final TemporaryFolder temporaryFolder = new TemporaryFolder();
-    private final EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder);
-
-    private final RuleChain chain = RuleChain
-        .outerRule(temporaryFolder)
-        .around(embeddedElasticSearch);
-
-    @Override
-    public Statement apply(Statement base, Description description) {
-        return chain.apply(base, description);
-    }
-
-    @Override
-    public void await() {
-        embeddedElasticSearch.awaitForElasticSearch();
-    }
-
-
-    @Override
-    public Module getModule() {
-        return new TestEmbeddedElasticSearchModule(embeddedElasticSearch);
-    }
-
-    public Node getNode() {
-        return embeddedElasticSearch.getNode();
-    }
-}
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQAwsS3JmapTestRule.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQAwsS3JmapTestRule.java
index 85dd81b..e6c295b 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQAwsS3JmapTestRule.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQAwsS3JmapTestRule.java
@@ -24,8 +24,7 @@ import java.io.IOException;
 import org.apache.james.backend.rabbitmq.DockerRabbitMQSingleton;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.store.search.PDFTextExtractor;
-import org.apache.james.modules.TestAwsS3BlobStoreModule;
-import org.apache.james.modules.TestESMetricReporterModule;
+import org.apache.james.modules.TestDockerESMetricReporterModule;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.TestRabbitMQModule;
 import org.apache.james.modules.blobstore.BlobStoreChoosingConfiguration;
@@ -45,17 +44,20 @@ public class CassandraRabbitMQAwsS3JmapTestRule implements TestRule {
     private final TemporaryFolder temporaryFolder;
 
     public static CassandraRabbitMQAwsS3JmapTestRule defaultTestRule() {
-        return new CassandraRabbitMQAwsS3JmapTestRule(new EmbeddedElasticSearchRule(), new DockerAwsS3TestRule());
+        return new CassandraRabbitMQAwsS3JmapTestRule(new DockerAwsS3TestRule());
     }
 
     private final GuiceModuleTestRule guiceModuleTestRule;
+    private final DockerElasticSearchRule dockerElasticSearchRule;
 
     public CassandraRabbitMQAwsS3JmapTestRule(GuiceModuleTestRule... guiceModuleTestRule) {
         TempFilesystemTestRule tempFilesystemTestRule = new TempFilesystemTestRule();
+        this.dockerElasticSearchRule = new DockerElasticSearchRule();
         this.temporaryFolder = tempFilesystemTestRule.getTemporaryFolder();
         this.guiceModuleTestRule =
             AggregateGuiceModuleTestRule
                 .of(guiceModuleTestRule)
+                .aggregate(dockerElasticSearchRule)
                 .aggregate(tempFilesystemTestRule);
     }
 
@@ -72,7 +74,7 @@ public class CassandraRabbitMQAwsS3JmapTestRule implements TestRule {
             .overrideWith(binder -> binder.bind(BlobStoreChoosingConfiguration.class)
                 .toInstance(BlobStoreChoosingConfiguration.objectStorage()))
             .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
-            .overrideWith(new TestESMetricReporterModule())
+            .overrideWith(new TestDockerESMetricReporterModule(dockerElasticSearchRule.getDockerEs().getHttpHost()))
             .overrideWith(guiceModuleTestRule.getModule())
             .overrideWith((binder -> binder.bind(CleanupTasksPerformer.class).asEagerSingleton()))
             .overrideWith(additionals);
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQSwiftJmapTestRule.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQSwiftJmapTestRule.java
index 8c7d7a1..f9e7918 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQSwiftJmapTestRule.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQSwiftJmapTestRule.java
@@ -24,7 +24,7 @@ import java.io.IOException;
 import org.apache.james.backend.rabbitmq.DockerRabbitMQSingleton;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.store.search.PDFTextExtractor;
-import org.apache.james.modules.TestESMetricReporterModule;
+import org.apache.james.modules.TestDockerESMetricReporterModule;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.TestRabbitMQModule;
 import org.apache.james.modules.TestSwiftBlobStoreModule;
@@ -43,17 +43,20 @@ public class CassandraRabbitMQSwiftJmapTestRule implements TestRule {
     private final TemporaryFolder temporaryFolder;
 
     public static CassandraRabbitMQSwiftJmapTestRule defaultTestRule() {
-        return new CassandraRabbitMQSwiftJmapTestRule(new EmbeddedElasticSearchRule());
+        return new CassandraRabbitMQSwiftJmapTestRule();
     }
 
     private final GuiceModuleTestRule guiceModuleTestRule;
+    private final DockerElasticSearchRule dockerElasticSearchRule;
 
     public CassandraRabbitMQSwiftJmapTestRule(GuiceModuleTestRule... guiceModuleTestRule) {
         TempFilesystemTestRule tempFilesystemTestRule = new TempFilesystemTestRule();
+        this.dockerElasticSearchRule = new DockerElasticSearchRule();
         this.temporaryFolder = tempFilesystemTestRule.getTemporaryFolder();
         this.guiceModuleTestRule =
                 AggregateGuiceModuleTestRule
                     .of(guiceModuleTestRule)
+                    .aggregate(dockerElasticSearchRule)
                     .aggregate(tempFilesystemTestRule);
     }
 
@@ -69,7 +72,7 @@ public class CassandraRabbitMQSwiftJmapTestRule implements TestRule {
             .overrideWith(new TestRabbitMQModule(DockerRabbitMQSingleton.SINGLETON))
             .overrideWith(new TestSwiftBlobStoreModule())
             .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
-            .overrideWith(new TestESMetricReporterModule())
+            .overrideWith(new TestDockerESMetricReporterModule(dockerElasticSearchRule.getDockerEs().getHttpHost()))
             .overrideWith(guiceModuleTestRule.getModule())
             .overrideWith((binder -> binder.bind(CleanupTasksPerformer.class).asEagerSingleton()))
             .overrideWith(additionals);


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


[james-project] 06/14: JAMES-2717 Delete EmbeddedElasticSearchExtension

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 ec0a65349213ebb940d00035c528f24bc2ef3fbd
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed May 8 15:34:54 2019 +0700

    JAMES-2717 Delete EmbeddedElasticSearchExtension
---
 .../james/EmbeddedElasticSearchExtension.java      | 63 ----------------------
 1 file changed, 63 deletions(-)

diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchExtension.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchExtension.java
deleted file mode 100644
index a724c35..0000000
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchExtension.java
+++ /dev/null
@@ -1,63 +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;
-
-import org.apache.james.backends.es.EmbeddedElasticSearch;
-import org.apache.james.junit.TemporaryFolderExtension;
-import org.apache.james.modules.TestEmbeddedElasticSearchModule;
-import org.junit.jupiter.api.extension.ExtensionContext;
-
-import com.google.inject.Module;
-
-public class EmbeddedElasticSearchExtension implements GuiceModuleTestExtension {
-    private final TemporaryFolderExtension folderExtension;
-    private EmbeddedElasticSearch embeddedElasticSearch;
-
-    public EmbeddedElasticSearchExtension() {
-        this.folderExtension = new TemporaryFolderExtension();
-    }
-
-    @Override
-    public void beforeEach(ExtensionContext extensionContext) throws Exception {
-        folderExtension.beforeEach(extensionContext);
-        embeddedElasticSearch = new EmbeddedElasticSearch(folderExtension.getTemporaryFolder().getTempDir().toPath());
-        embeddedElasticSearch.before();
-    }
-
-    @Override
-    public void afterEach(ExtensionContext extensionContext) throws Exception {
-        embeddedElasticSearch.after();
-        folderExtension.afterEach(extensionContext);
-    }
-
-    @Override
-    public Module getModule() {
-        return new TestEmbeddedElasticSearchModule(embeddedElasticSearch);
-    }
-
-    @Override
-    public void await() {
-        embeddedElasticSearch.awaitForElasticSearch();
-    }
-
-    public EmbeddedElasticSearch getEmbeddedElasticSearch() {
-        return embeddedElasticSearch;
-    }
-}


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


[james-project] 14/14: JAMES-2712 Extract concatenation of message ids into a proper method

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 c61f77052bd0b041176ae18b8f9d8e1654b2c37b
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Wed May 8 15:58:14 2019 +0700

    JAMES-2712 Extract concatenation of message ids into a proper method
---
 .../test/java/org/apache/james/jmap/JmapCommonRequests.java    | 10 +++++++---
 .../james/jmap/methods/integration/QuotaMailingTest.java       | 10 +++-------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JmapCommonRequests.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JmapCommonRequests.java
index fec460e..85e241f 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JmapCommonRequests.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/JmapCommonRequests.java
@@ -154,13 +154,17 @@ public class JmapCommonRequests {
     }
 
     public static void deleteMessages(AccessToken accessToken, List<String> idsToDestroy) {
-        String idString = idsToDestroy.stream()
-            .map(id -> "\"" + id + "\"")
-            .collect(Collectors.joining(","));
+        String idString = concatMessageIds(idsToDestroy);
 
         with()
             .header("Authorization", accessToken.serialize())
             .body("[[\"setMessages\", {\"destroy\": [" + idString + "]}, \"#0\"]]")
             .post("/jmap");
     }
+
+    public static String concatMessageIds(List<String> ids) {
+        return ids.stream()
+            .map(id -> "\"" + id + "\"")
+            .collect(Collectors.joining(","));
+    }
 }
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/QuotaMailingTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/QuotaMailingTest.java
index 036435f..cad0367 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/QuotaMailingTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/QuotaMailingTest.java
@@ -22,6 +22,7 @@ package org.apache.james.jmap.methods.integration;
 import static io.restassured.RestAssured.given;
 import static io.restassured.RestAssured.with;
 import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
+import static org.apache.james.jmap.JmapCommonRequests.concatMessageIds;
 import static org.apache.james.jmap.JmapCommonRequests.getOutboxId;
 import static org.apache.james.jmap.JmapCommonRequests.listMessageIdsForAccount;
 import static org.apache.james.jmap.JmapURIBuilder.baseUri;
@@ -34,7 +35,6 @@ import static org.hamcrest.Matchers.hasItem;
 
 import java.io.IOException;
 import java.util.List;
-import java.util.stream.Collectors;
 
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.core.quota.QuotaSize;
@@ -112,9 +112,7 @@ public abstract class QuotaMailingTest {
         WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 2);
 
         List<String> ids = listMessageIdsForAccount(homerAccessToken);
-        String idString = ids.stream()
-            .map(id -> "\"" + id + "\"")
-            .collect(Collectors.joining(","));
+        String idString = concatMessageIds(ids);
 
         given()
             .header("Authorization", homerAccessToken.serialize())
@@ -143,9 +141,7 @@ public abstract class QuotaMailingTest {
         WAIT_TWO_MINUTES.until(() -> listMessageIdsForAccount(homerAccessToken).size() == 4);
 
         List<String> ids = listMessageIdsForAccount(homerAccessToken);
-        String idString = ids.stream()
-            .map(id -> "\"" + id + "\"")
-            .collect(Collectors.joining(","));
+        String idString = concatMessageIds(ids);
 
         given()
             .header("Authorization", homerAccessToken.serialize())


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


[james-project] 07/14: JAMES-2712 Extract ExportRequest object

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 7d594be3524df454a0472c6bf9abb3b3db2042cc
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Apr 26 16:21:55 2019 +0700

    JAMES-2712 Extract ExportRequest object
---
 .../java/org/apache/james/jmap/ExportRequest.java  | 62 ++++++++++++++++++++++
 .../integration/DeletedMessagesVaultTest.java      | 38 ++-----------
 2 files changed, 66 insertions(+), 34 deletions(-)

diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ExportRequest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ExportRequest.java
new file mode 100644
index 0000000..328701e
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/ExportRequest.java
@@ -0,0 +1,62 @@
+/****************************************************************
+ * 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;
+
+public class ExportRequest {
+
+    public static class Builder {
+
+        @FunctionalInterface
+        public interface RequireSharee {
+            RequireMatchingQuery exportTo(String sharee);
+        }
+
+        @FunctionalInterface
+        public interface RequireMatchingQuery {
+            ExportRequest query(String query);
+        }
+    }
+
+    public static Builder.RequireSharee userExportFrom(String userExportFrom) {
+        return sharee -> query -> new ExportRequest(userExportFrom, sharee, query);
+    }
+
+    private final String userExportFrom;
+    private final String sharee;
+    private final String matchingQuery;
+
+    private ExportRequest(String userExportFrom, String sharee, String matchingQuery) {
+        this.userExportFrom = userExportFrom;
+        this.sharee = sharee;
+        this.matchingQuery = matchingQuery;
+    }
+
+    public String getUserExportFrom() {
+        return userExportFrom;
+    }
+
+    public String getSharee() {
+        return sharee;
+    }
+
+    public String getMatchingQuery() {
+        return matchingQuery;
+    }
+}
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
index 8bf523f..a979a5e 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/DeletedMessagesVaultTest.java
@@ -48,6 +48,7 @@ import java.util.stream.Collectors;
 
 import org.apache.james.GuiceJamesServer;
 import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.jmap.ExportRequest;
 import org.apache.james.jmap.api.access.AccessToken;
 import org.apache.james.jmap.categories.BasicFeature;
 import org.apache.james.mailbox.DefaultMailboxes;
@@ -83,37 +84,6 @@ import io.restassured.parsing.Parser;
 import io.restassured.specification.RequestSpecification;
 
 public abstract class DeletedMessagesVaultTest {
-
-    private static class ExportRequest {
-
-        private static class Builder {
-
-            @FunctionalInterface
-            interface RequireSharee {
-                RequireMatchingQuery exportTo(String sharee);
-            }
-
-            @FunctionalInterface
-            interface RequireMatchingQuery {
-                ExportRequest query(String query);
-            }
-        }
-
-        private static Builder.RequireSharee userExportFrom(String userExportFrom) {
-            return sharee -> query -> new ExportRequest(userExportFrom, sharee, query);
-        }
-
-        private final String userExportFrom;
-        private final String sharee;
-        private final String matchingQuery;
-
-        private ExportRequest(String userExportFrom, String sharee, String matchingQuery) {
-            this.userExportFrom = userExportFrom;
-            this.sharee = sharee;
-            this.matchingQuery = matchingQuery;
-        }
-    }
-
     private static final Instant NOW = Instant.now();
     private static final Instant ONE_DAY_AFTER_ONE_YEAR_EXPIRATION = NOW.plus(366, ChronoUnit.DAYS);
     private static final String FIRST_SUBJECT = "first subject";
@@ -895,9 +865,9 @@ public abstract class DeletedMessagesVaultTest {
         String taskId =
             webAdminApi.with()
                 .queryParam("action", "export")
-                .queryParam("exportTo", exportRequest.sharee)
-                .body(exportRequest.matchingQuery)
-                .post("/deletedMessages/users/" + exportRequest.userExportFrom)
+                .queryParam("exportTo", exportRequest.getSharee())
+                .body(exportRequest.getMatchingQuery())
+                .post("/deletedMessages/users/" + exportRequest.getUserExportFrom())
             .jsonPath()
                 .get("taskId");
 


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


[james-project] 05/14: JAMES-2717 Replace EmbeddedElasticSearchExtension in ESReporterTest

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 4767a7c82dea5527306e84a2d298ea0dd63f88e4
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed May 8 14:06:21 2019 +0700

    JAMES-2717 Replace EmbeddedElasticSearchExtension in ESReporterTest
---
 .../src/test/java/org/apache/james/ESReporterTest.java      | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

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 f896e28..71af4c8 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
@@ -37,7 +37,7 @@ import org.apache.commons.net.imap.IMAPClient;
 import org.apache.james.jmap.api.access.AccessToken;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.store.search.PDFTextExtractor;
-import org.apache.james.modules.TestEmbeddedESMetricReporterModule;
+import org.apache.james.modules.TestDockerESMetricReporterModule;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.protocols.ImapGuiceProbe;
 import org.apache.james.utils.DataProbeImpl;
@@ -60,18 +60,17 @@ class ESReporterTest {
     private static final Logger LOGGER = LoggerFactory.getLogger(ESReporterTest.class);
     private static final int LIMIT_TO_10_MESSAGES = 10;
 
-
-    static final EmbeddedElasticSearchExtension embeddedElasticSearchExtension = new EmbeddedElasticSearchExtension();
+    static final DockerElasticSearchExtension elasticSearchExtension = new DockerElasticSearchExtension();
 
     @RegisterExtension
     static JamesServerExtension testExtension = new JamesServerBuilder()
-        .extension(embeddedElasticSearchExtension)
+        .extension(elasticSearchExtension)
         .extension(new CassandraExtension())
         .server(configuration -> GuiceJamesServer.forConfiguration(configuration)
             .combineWith(ALL_BUT_JMX_CASSANDRA_MODULE)
             .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
             .overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
-            .overrideWith(new TestEmbeddedESMetricReporterModule()))
+            .overrideWith(new TestDockerESMetricReporterModule(elasticSearchExtension.getDockerES().getHttpHost())))
         .build();
 
     private static final int DELAY_IN_MS = 100;
@@ -152,11 +151,11 @@ class ESReporterTest {
     }
 
     private boolean checkMetricRecordedInElasticSearch() {
-        try (Client client = embeddedElasticSearchExtension.getEmbeddedElasticSearch().getNode().client()) {
+        try (Client client = elasticSearchExtension.getDockerES().clientProvider().get()) {
             return !Arrays.stream(client.prepareSearch()
                     .setQuery(QueryBuilders.matchAllQuery())
                     .get().getHits().getHits())
-                .filter(searchHit -> searchHit.getIndex().startsWith(TestEmbeddedESMetricReporterModule.METRICS_INDEX))
+                .filter(searchHit -> searchHit.getIndex().startsWith(TestDockerESMetricReporterModule.METRICS_INDEX))
                 .collect(Collectors.toList())
                 .isEmpty();
         } catch (Exception e) {


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