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 dcfc52235e2d76ea2c2068bc33d4756f1b9c7461 Author: Tran Tien Duc <dt...@linagora.com> AuthorDate: Fri Dec 13 10:49:29 2019 +0700 JAMES-3012 Move DeletedMessageVaultTest to webadmin-integration-tests --- .../pom.xml | 11 -- .../CassandraDeletedMessageVaultTest.java | 54 ---------- .../memory-jmap-draft-integration-testing/pom.xml | 11 -- .../pom.xml | 11 -- .../rabbitmq/RabbitMQDeletedMessagesVaultTest.java | 54 ---------- server/protocols/webadmin-integration-test/pom.xml | 17 +++ .../vault/DeletedMessageVaultIntegrationTest.java} | 118 ++++++++++++--------- .../vault/DeletedMessagesVaultRequests.java | 83 +++++++++++++++ .../webadmin/integration/vault/ExportRequest.java} | 64 ++++++----- 9 files changed, 205 insertions(+), 218 deletions(-) diff --git a/server/protocols/jmap-draft-integration-testing/cassandra-jmap-draft-integration-testing/pom.xml b/server/protocols/jmap-draft-integration-testing/cassandra-jmap-draft-integration-testing/pom.xml index ee1a549..be5be85 100644 --- a/server/protocols/jmap-draft-integration-testing/cassandra-jmap-draft-integration-testing/pom.xml +++ b/server/protocols/jmap-draft-integration-testing/cassandra-jmap-draft-integration-testing/pom.xml @@ -88,11 +88,6 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>backup</artifactId> - <type>test-jar</type> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> <artifactId>blob-export-guice</artifactId> <type>test-jar</type> <scope>test</scope> @@ -169,12 +164,6 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-mailbox-plugin-deleted-messages-vault-guice</artifactId> - <scope>test</scope> - <type>test-jar</type> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> <artifactId>james-server-testing</artifactId> <scope>test</scope> </dependency> diff --git a/server/protocols/jmap-draft-integration-testing/cassandra-jmap-draft-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraDeletedMessageVaultTest.java b/server/protocols/jmap-draft-integration-testing/cassandra-jmap-draft-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraDeletedMessageVaultTest.java deleted file mode 100644 index 49f93e7..0000000 --- a/server/protocols/jmap-draft-integration-testing/cassandra-jmap-draft-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraDeletedMessageVaultTest.java +++ /dev/null @@ -1,54 +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.jmap.cassandra; - -import java.io.IOException; -import java.time.Clock; - -import org.apache.james.CassandraJmapTestRule; -import org.apache.james.DockerCassandraRule; -import org.apache.james.GuiceJamesServer; -import org.apache.james.filesystem.api.FileSystem; -import org.apache.james.jmap.draft.methods.integration.DeletedMessagesVaultTest; -import org.apache.james.modules.vault.TestDeleteMessageVaultPreDeletionHookModule; -import org.apache.james.webadmin.WebAdminConfiguration; -import org.junit.Rule; - -public class CassandraDeletedMessageVaultTest extends DeletedMessagesVaultTest { - @Rule - public DockerCassandraRule cassandra = new DockerCassandraRule(); - - @Rule - public CassandraJmapTestRule rule = CassandraJmapTestRule.defaultTestRule(); - - @Override - protected GuiceJamesServer createJmapServer(FileSystem fileSystem, Clock clock) throws IOException { - return rule.jmapServer(cassandra.getModule(), - new TestDeleteMessageVaultPreDeletionHookModule(), - binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION), - binder -> binder.bind(FileSystem.class).toInstance(fileSystem), - binder -> binder.bind(Clock.class).toInstance(clock)); - } - - @Override - protected void awaitSearchUpToDate() { - rule.await(); - } -} diff --git a/server/protocols/jmap-draft-integration-testing/memory-jmap-draft-integration-testing/pom.xml b/server/protocols/jmap-draft-integration-testing/memory-jmap-draft-integration-testing/pom.xml index fd5b6ea..67e79f1 100644 --- a/server/protocols/jmap-draft-integration-testing/memory-jmap-draft-integration-testing/pom.xml +++ b/server/protocols/jmap-draft-integration-testing/memory-jmap-draft-integration-testing/pom.xml @@ -70,11 +70,6 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>backup</artifactId> - <type>test-jar</type> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> <artifactId>james-server-dnsservice-test</artifactId> </dependency> <dependency> @@ -91,12 +86,6 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-mailbox-plugin-deleted-messages-vault-guice</artifactId> - <version>${project.version}</version> - <type>test-jar</type> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> <artifactId>james-server-jmap-draft-integration-testing</artifactId> <type>test-jar</type> <scope>test</scope> diff --git a/server/protocols/jmap-draft-integration-testing/rabbitmq-jmap-draft-integration-testing/pom.xml b/server/protocols/jmap-draft-integration-testing/rabbitmq-jmap-draft-integration-testing/pom.xml index edf56b3..6dea7f9 100644 --- a/server/protocols/jmap-draft-integration-testing/rabbitmq-jmap-draft-integration-testing/pom.xml +++ b/server/protocols/jmap-draft-integration-testing/rabbitmq-jmap-draft-integration-testing/pom.xml @@ -53,11 +53,6 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>backup</artifactId> - <type>test-jar</type> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> <artifactId>blob-objectstorage</artifactId> <type>test-jar</type> <scope>test</scope> @@ -124,12 +119,6 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-mailbox-plugin-deleted-messages-vault-guice</artifactId> - <scope>test</scope> - <type>test-jar</type> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> <artifactId>james-server-testing</artifactId> <scope>test</scope> </dependency> diff --git a/server/protocols/jmap-draft-integration-testing/rabbitmq-jmap-draft-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQDeletedMessagesVaultTest.java b/server/protocols/jmap-draft-integration-testing/rabbitmq-jmap-draft-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQDeletedMessagesVaultTest.java deleted file mode 100644 index 176b309..0000000 --- a/server/protocols/jmap-draft-integration-testing/rabbitmq-jmap-draft-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/RabbitMQDeletedMessagesVaultTest.java +++ /dev/null @@ -1,54 +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.jmap.rabbitmq; - -import java.io.IOException; -import java.time.Clock; - -import org.apache.james.CassandraRabbitMQAwsS3JmapTestRule; -import org.apache.james.DockerCassandraRule; -import org.apache.james.GuiceJamesServer; -import org.apache.james.filesystem.api.FileSystem; -import org.apache.james.jmap.draft.methods.integration.DeletedMessagesVaultTest; -import org.apache.james.modules.vault.TestDeleteMessageVaultPreDeletionHookModule; -import org.apache.james.webadmin.WebAdminConfiguration; -import org.junit.Rule; - -public class RabbitMQDeletedMessagesVaultTest extends DeletedMessagesVaultTest { - @Rule - public DockerCassandraRule cassandra = new DockerCassandraRule(); - - @Rule - public CassandraRabbitMQAwsS3JmapTestRule rule = CassandraRabbitMQAwsS3JmapTestRule.defaultTestRule(); - - @Override - protected GuiceJamesServer createJmapServer(FileSystem fileSystem, Clock clock) throws IOException { - return rule.jmapServer(cassandra.getModule(), - new TestDeleteMessageVaultPreDeletionHookModule(), - binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION), - binder -> binder.bind(FileSystem.class).toInstance(fileSystem), - binder -> binder.bind(Clock.class).toInstance(clock)); - } - - @Override - protected void awaitSearchUpToDate() { - rule.await(); - } -} diff --git a/server/protocols/webadmin-integration-test/pom.xml b/server/protocols/webadmin-integration-test/pom.xml index 7e58acb..9ef15ce 100644 --- a/server/protocols/webadmin-integration-test/pom.xml +++ b/server/protocols/webadmin-integration-test/pom.xml @@ -70,6 +70,12 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> + <artifactId>backup</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> <artifactId>blob-objectstorage</artifactId> <type>test-jar</type> <scope>test</scope> @@ -111,6 +117,17 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> + <artifactId>james-server-mailbox-plugin-deleted-messages-vault-guice</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> + <artifactId>james-server-testing</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> <artifactId>james-server-webadmin-core</artifactId> <type>test-jar</type> <scope>test</scope> diff --git a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/DeletedMessagesVaultTest.java b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/vault/DeletedMessageVaultIntegrationTest.java similarity index 91% rename from server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/DeletedMessagesVaultTest.java rename to server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/vault/DeletedMessageVaultIntegrationTest.java index 6e43cd8..07755af 100644 --- a/server/protocols/jmap-draft-integration-testing/jmap-draft-integration-testing-common/src/test/java/org/apache/james/jmap/draft/methods/integration/DeletedMessagesVaultTest.java +++ b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/vault/DeletedMessageVaultIntegrationTest.java @@ -17,30 +17,29 @@ * under the License. * ****************************************************************/ -package org.apache.james.jmap.draft.methods.integration; +package org.apache.james.webadmin.integration.vault; 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.JMAPTestingConstants.ARGUMENTS; +import static org.apache.james.jmap.JMAPTestingConstants.DOMAIN; +import static org.apache.james.jmap.JMAPTestingConstants.LOCALHOST_IP; +import static org.apache.james.jmap.JMAPTestingConstants.calmlyAwait; +import static org.apache.james.jmap.JMAPTestingConstants.jmapRequestSpecBuilder; import static org.apache.james.jmap.JmapCommonRequests.deleteMessages; import static org.apache.james.jmap.JmapCommonRequests.getAllMailboxesIds; import static org.apache.james.jmap.JmapCommonRequests.getLastMessageId; 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.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.apache.james.webadmin.integration.vault.DeletedMessagesVaultRequests.deleteFromVault; +import static org.apache.james.webadmin.integration.vault.DeletedMessagesVaultRequests.exportVaultContent; +import static org.apache.james.webadmin.integration.vault.DeletedMessagesVaultRequests.purgeVault; +import static org.apache.james.webadmin.integration.vault.DeletedMessagesVaultRequests.restoreMessagesForUserWithQuery; import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.hasItem; @@ -50,28 +49,29 @@ import java.time.Clock; import java.time.ZonedDateTime; import java.util.List; +import org.apache.james.CassandraRabbitMQAwsS3JmapTestRule; +import org.apache.james.DockerCassandraRule; import org.apache.james.GuiceJamesServer; import org.apache.james.core.Username; 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.jmap.AccessToken; +import org.apache.james.jmap.draft.JmapGuiceProbe; import org.apache.james.mailbox.DefaultMailboxes; import org.apache.james.mailbox.Role; import org.apache.james.mailbox.backup.ZipAssert; -import org.apache.james.mailbox.backup.ZipAssert.EntryChecks; import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.probe.MailboxProbe; import org.apache.james.modules.MailboxProbeImpl; import org.apache.james.modules.protocols.ImapGuiceProbe; +import org.apache.james.modules.vault.TestDeleteMessageVaultPreDeletionHookModule; import org.apache.james.probe.DataProbe; import org.apache.james.server.core.JamesServerResourceLoader; import org.apache.james.server.core.filesystem.FileSystemImpl; import org.apache.james.utils.DataProbeImpl; import org.apache.james.utils.IMAPMessageReader; -import org.apache.james.jmap.draft.JmapGuiceProbe; import org.apache.james.utils.UpdatableTickingClock; import org.apache.james.utils.WebAdminGuiceProbe; +import org.apache.james.webadmin.WebAdminConfiguration; import org.apache.james.webadmin.WebAdminUtils; import org.awaitility.Duration; import org.awaitility.core.ConditionFactory; @@ -79,7 +79,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.categories.Category; import org.junit.rules.TemporaryFolder; import com.google.common.base.Strings; @@ -90,7 +89,8 @@ import io.restassured.config.ParamConfig; import io.restassured.parsing.Parser; import io.restassured.specification.RequestSpecification; -public abstract class DeletedMessagesVaultTest { +public class DeletedMessageVaultIntegrationTest { + private static final ZonedDateTime NOW = ZonedDateTime.now(); private static final ZonedDateTime TWO_MONTH_AFTER_ONE_YEAR_EXPIRATION = NOW.plusYears(1).plusMonths(2); private static final String FIRST_SUBJECT = "first subject"; @@ -103,6 +103,10 @@ 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) @@ -111,13 +115,11 @@ public abstract class DeletedMessagesVaultTest { .userExportFrom(JACK) .exportTo(HOMER) .query(MATCH_ALL_QUERY); - - private MailboxId otherMailboxId; - - protected abstract GuiceJamesServer createJmapServer(FileSystem fileSystem, Clock clock) throws IOException; - - protected abstract void awaitSearchUpToDate(); - + + @Rule + public DockerCassandraRule cassandra = new DockerCassandraRule(); + @Rule + public CassandraRabbitMQAwsS3JmapTestRule rule = CassandraRabbitMQAwsS3JmapTestRule.defaultTestRule(); @Rule public IMAPMessageReader imapMessageReader = new IMAPMessageReader(); @Rule @@ -129,6 +131,7 @@ public abstract class DeletedMessagesVaultTest { private GuiceJamesServer jmapServer; private RequestSpecification webAdminApi; private UpdatableTickingClock clock; + private MailboxId otherMailboxId; private FileSystem fileSystem; @Before @@ -151,21 +154,35 @@ public abstract class DeletedMessagesVaultTest { dataProbe.addUser(JACK, PASSWORD); mailboxProbe.createMailbox("#private", HOMER, DefaultMailboxes.INBOX); otherMailboxId = mailboxProbe.createMailbox("#private", HOMER, MAILBOX_NAME); - homerAccessToken = authenticateJamesUser(baseUri(jmapServer), Username.of(HOMER), PASSWORD); - bartAccessToken = authenticateJamesUser(baseUri(jmapServer), Username.of(BART), BOB_PASSWORD); - jackAccessToken = authenticateJamesUser(baseUri(jmapServer), Username.of(JACK), PASSWORD); + int jmapPort = jmapServer.getProbe(JmapGuiceProbe.class) + .getJmapPort(); + homerAccessToken = authenticateJamesUser(baseUri(jmapPort), Username.of(HOMER), PASSWORD); + bartAccessToken = authenticateJamesUser(baseUri(jmapPort), Username.of(BART), BOB_PASSWORD); + jackAccessToken = authenticateJamesUser(baseUri(jmapPort), Username.of(JACK), PASSWORD); webAdminApi = WebAdminUtils.spec(jmapServer.getProbe(WebAdminGuiceProbe.class).getWebAdminPort()) .config(WebAdminUtils.defaultConfig() .paramConfig(new ParamConfig(REPLACE, REPLACE, REPLACE))); } + + private GuiceJamesServer createJmapServer(FileSystem fileSystem, Clock clock) throws IOException { + return rule.jmapServer(cassandra.getModule(), + new TestDeleteMessageVaultPreDeletionHookModule(), + binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION), + binder -> binder.bind(FileSystem.class).toInstance(fileSystem), + binder -> binder.bind(Clock.class).toInstance(clock)); + } + private void awaitSearchUpToDate() { + rule.await(); + } + @After public void tearDown() throws Exception { jmapServer.stop(); } - @Category(BasicFeature.class) + @Test public void vaultEndpointShouldRestoreJmapDeletedEmail() { bartSendMessageToHomer(); @@ -179,7 +196,7 @@ public abstract class DeletedMessagesVaultTest { String messageId = listMessageIdsForAccount(homerAccessToken).get(0); given() - .header("Authorization", homerAccessToken.serialize()) + .header("Authorization", homerAccessToken.asString()) .body("[[\"getMessages\", {\"ids\": [\"" + messageId + "\"]}, \"#0\"]]") .when() .post("/jmap") @@ -188,8 +205,7 @@ public abstract class DeletedMessagesVaultTest { .log().ifValidationFails() .body(ARGUMENTS + ".list.subject", hasItem(SUBJECT)); } - - @Category(BasicFeature.class) + @Test public void vaultEndpointShouldRestoreImapDeletedEmail() throws Exception { bartSendMessageToHomer(); @@ -208,7 +224,7 @@ public abstract class DeletedMessagesVaultTest { String messageId = listMessageIdsForAccount(homerAccessToken).get(0); given() - .header("Authorization", homerAccessToken.serialize()) + .header("Authorization", homerAccessToken.asString()) .body("[[\"getMessages\", {\"ids\": [\"" + messageId + "\"]}, \"#0\"]]") .when() .post("/jmap") @@ -218,7 +234,7 @@ public abstract class DeletedMessagesVaultTest { .body(ARGUMENTS + ".list.subject", hasItem(SUBJECT)); } - @Category(BasicFeature.class) + @Test public void vaultEndpointShouldRestoreImapDeletedMailbox() throws Exception { bartSendMessageToHomer(); @@ -239,7 +255,7 @@ public abstract class DeletedMessagesVaultTest { String messageId = listMessageIdsForAccount(homerAccessToken).get(0); given() - .header("Authorization", homerAccessToken.serialize()) + .header("Authorization", homerAccessToken.asString()) .body("[[\"getMessages\", {\"ids\": [\"" + messageId + "\"]}, \"#0\"]]") .when() .post("/jmap") @@ -289,7 +305,7 @@ public abstract class DeletedMessagesVaultTest { String messageId = listMessageIdsForAccount(homerAccessToken).get(0); given() - .header("Authorization", homerAccessToken.serialize()) + .header("Authorization", homerAccessToken.asString()) .body("[[\"getMessages\", {\"ids\": [\"" + messageId + "\"]}, \"#0\"]]") .when() .post("/jmap") @@ -452,7 +468,7 @@ public abstract class DeletedMessagesVaultTest { String newMessageId = listMessageIdsForAccount(homerAccessToken).get(0); given() - .header("Authorization", homerAccessToken.serialize()) + .header("Authorization", homerAccessToken.asString()) .body("[[\"getMessages\", {\"ids\": [\"" + newMessageId + "\"]}, \"#0\"]]") .when() .post("/jmap") @@ -462,7 +478,7 @@ public abstract class DeletedMessagesVaultTest { .body(ARGUMENTS + ".list.subject", hasItem(SUBJECT)); } - @Category(BasicFeature.class) + @Test public void vaultExportShouldExportZipContainsVaultMessagesToShareeWhenJmapDeleteMessage() throws Exception { bartSendMessageToHomer(); @@ -476,11 +492,11 @@ public abstract class DeletedMessagesVaultTest { try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) { zipAssert.hasEntriesSize(1) - .allSatisfies(entry -> EntryChecks.hasName(messageIdOfHomer + ".eml")); + .allSatisfies(entry -> hasName(messageIdOfHomer + ".eml")); } } - @Category(BasicFeature.class) + @Test public void vaultExportShouldExportZipContainsVaultMessagesToShareeWhenImapDeleteMessage() throws Exception { bartSendMessageToHomer(); @@ -499,11 +515,11 @@ public abstract class DeletedMessagesVaultTest { try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) { zipAssert.hasEntriesSize(1) - .allSatisfies(entry -> EntryChecks.hasName(messageIdOfHomer + ".eml")); + .allSatisfies(entry -> hasName(messageIdOfHomer + ".eml")); } } - @Category(BasicFeature.class) + @Test public void vaultExportShouldExportZipContainsVaultMessagesToShareeWhenImapDeletedMailbox() throws Exception { bartSendMessageToHomer(); @@ -524,7 +540,7 @@ public abstract class DeletedMessagesVaultTest { try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) { zipAssert.hasEntriesSize(1) - .allSatisfies(entry -> EntryChecks.hasName(messageIdOfHomer + ".eml")); + .allSatisfies(entry -> hasName(messageIdOfHomer + ".eml")); } } @@ -645,7 +661,7 @@ public abstract class DeletedMessagesVaultTest { String fileLocation = exportAndGetFileLocationFromLastMail(EXPORT_ALL_HOMER_MESSAGES_TO_BART, bartAccessToken); try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) { zipAssert.hasEntriesSize(1) - .allSatisfies(entry -> EntryChecks.hasName(messageIdOfNotExpiredMessage + ".eml")); + .allSatisfies(entry -> hasName(messageIdOfNotExpiredMessage + ".eml")); } } @@ -732,7 +748,7 @@ public abstract class DeletedMessagesVaultTest { String fileLocation = exportAndGetFileLocationFromLastMail(EXPORT_ALL_HOMER_MESSAGES_TO_BART, bartAccessToken); try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocation))) { zipAssert.hasEntriesSize(1) - .allSatisfies(entry -> EntryChecks.hasName(messageIdOfHomer + ".eml")); + .allSatisfies(entry -> hasName(messageIdOfHomer + ".eml")); } } @@ -797,7 +813,7 @@ public abstract class DeletedMessagesVaultTest { String fileLocationOfBartMessages = exportAndGetFileLocationFromLastMail(EXPORT_ALL_JACK_MESSAGES_TO_HOMER, homerAccessToken); try (ZipAssert zipAssert = assertThatZip(new FileInputStream(fileLocationOfBartMessages))) { zipAssert.hasEntriesSize(1) - .allSatisfies(entry -> EntryChecks.hasName(jackInboxMessageId + ".eml")); + .allSatisfies(entry -> hasName(jackInboxMessageId + ".eml")); } } @@ -813,7 +829,7 @@ public abstract class DeletedMessagesVaultTest { private String exportedFileLocationFromMailHeader(String messageId, AccessToken accessToken) { return with() - .header("Authorization", accessToken.serialize()) + .header("Authorization", accessToken.asString()) .body("[[\"getMessages\", {\"ids\": [\"" + messageId + "\"]}, \"#0\"]]") .post("/jmap") .jsonPath() @@ -823,7 +839,7 @@ public abstract class DeletedMessagesVaultTest { private void homerSharesHisMailboxWithBart() { with() - .header("Authorization", homerAccessToken.serialize()) + .header("Authorization", homerAccessToken.asString()) .body("[" + " [ \"setMailboxes\"," + " {" + @@ -866,7 +882,7 @@ public abstract class DeletedMessagesVaultTest { "]"; with() - .header("Authorization", bartAccessToken.serialize()) + .header("Authorization", bartAccessToken.asString()) .body(requestBody) .post("/jmap") .then() @@ -898,7 +914,7 @@ public abstract class DeletedMessagesVaultTest { "]"; with() - .header("Authorization", bartAccessToken.serialize()) + .header("Authorization", bartAccessToken.asString()) .body(requestBody) .post("/jmap") .then() @@ -941,7 +957,7 @@ public abstract class DeletedMessagesVaultTest { "]"; given() - .header("Authorization", homerAccessToken.serialize()) + .header("Authorization", homerAccessToken.asString()) .body(updateRequestBody) .when() .post("/jmap"); diff --git a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/vault/DeletedMessagesVaultRequests.java b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/vault/DeletedMessagesVaultRequests.java new file mode 100644 index 0000000..ee38992 --- /dev/null +++ b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/vault/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.webadmin.integration.vault; + +import static org.hamcrest.Matchers.is; + +import io.restassured.specification.RequestSpecification; + +class DeletedMessagesVaultRequests { + + 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")); + } + + 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")); + } + + 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")); + } + + 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-draft-integration-testing/memory-jmap-draft-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryDeletedMessagesVaultTest.java b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/vault/ExportRequest.java similarity index 50% rename from server/protocols/jmap-draft-integration-testing/memory-jmap-draft-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryDeletedMessagesVaultTest.java rename to server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/vault/ExportRequest.java index 1af2008..418ca2c 100644 --- a/server/protocols/jmap-draft-integration-testing/memory-jmap-draft-integration-testing/src/test/java/org/apache/james/jmap/memory/MemoryDeletedMessagesVaultTest.java +++ b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/vault/ExportRequest.java @@ -17,34 +17,46 @@ * under the License. * ****************************************************************/ -package org.apache.james.jmap.memory; - -import java.io.IOException; -import java.time.Clock; - -import org.apache.james.GuiceJamesServer; -import org.apache.james.MemoryJmapTestRule; -import org.apache.james.filesystem.api.FileSystem; -import org.apache.james.jmap.draft.methods.integration.DeletedMessagesVaultTest; -import org.apache.james.modules.vault.TestDeleteMessageVaultPreDeletionHookModule; -import org.apache.james.webadmin.WebAdminConfiguration; -import org.junit.Rule; - -public class MemoryDeletedMessagesVaultTest extends DeletedMessagesVaultTest { - @Rule - public MemoryJmapTestRule memoryJmap = new MemoryJmapTestRule(); - - @Override - protected GuiceJamesServer createJmapServer(FileSystem fileSystem, Clock clock) throws IOException { - return memoryJmap.jmapServer( - new TestDeleteMessageVaultPreDeletionHookModule(), - binder -> binder.bind(WebAdminConfiguration.class).toInstance(WebAdminConfiguration.TEST_CONFIGURATION), - binder -> binder.bind(FileSystem.class).toInstance(fileSystem), - binder -> binder.bind(Clock.class).toInstance(clock)); +package org.apache.james.webadmin.integration.vault; + +class ExportRequest { + + public static class Builder { + + @FunctionalInterface + public interface RequireSharee { + RequireMatchingQuery exportTo(String sharee); + } + + @FunctionalInterface + public interface RequireMatchingQuery { + ExportRequest query(String query); + } + } + + static Builder.RequireSharee userExportFrom(String userExportFrom) { + return sharee -> query -> new ExportRequest(userExportFrom, sharee, query); } - @Override - protected void awaitSearchUpToDate() { + 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; + } + + String getUserExportFrom() { + return userExportFrom; + } + + String getSharee() { + return sharee; + } + String getMatchingQuery() { + return matchingQuery; } } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org