Repository: james-project Updated Branches: refs/heads/master 16689d35e -> 0cb80385a
JAMES-1731 Ensure mailbox rename & move keep emails Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0cb80385 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0cb80385 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0cb80385 Branch: refs/heads/master Commit: 0cb80385afa835e3c4e59628173b3b5d49857f90 Parents: 4d32b9d Author: Raphael Ouazana <[email protected]> Authored: Mon May 2 15:18:17 2016 +0200 Committer: Raphael Ouazana <[email protected]> Committed: Wed May 4 11:02:03 2016 +0200 ---------------------------------------------------------------------- .../cassandra-jmap-integration-testing/pom.xml | 15 ++ ...CassandraSetMailboxesMethodCucumberTest.java | 31 ++++ .../CassandraSetMailboxesMethodStepdefs.java | 60 +++++++ .../jmap-integration-testing-common/pom.xml | 10 ++ .../integration/SetMailboxesMethodStepdefs.java | 174 +++++++++++++++++++ .../cucumber/MailboxModification.feature | 20 +++ .../memory-jmap-integration-testing/pom.xml | 15 ++ .../MemorySetMailboxesMethodCucumberTest.java | 31 ++++ .../MemorySetMailboxesMethodStepdefs.java | 54 ++++++ 9 files changed, 410 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/0cb80385/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml ---------------------------------------------------------------------- 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 c92330a..19b7410 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 @@ -183,6 +183,21 @@ <scope>test</scope> </dependency> <dependency> + <groupId>info.cukes</groupId> + <artifactId>cucumber-java</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>info.cukes</groupId> + <artifactId>cucumber-junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>info.cukes</groupId> + <artifactId>cucumber-picocontainer</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/james-project/blob/0cb80385/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodCucumberTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodCucumberTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodCucumberTest.java new file mode 100644 index 0000000..a859fa9 --- /dev/null +++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodCucumberTest.java @@ -0,0 +1,31 @@ +/**************************************************************** + * 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 org.junit.runner.RunWith; + +import cucumber.api.CucumberOptions; +import cucumber.api.junit.Cucumber; + +@RunWith(Cucumber.class) +@CucumberOptions(features="classpath:cucumber/MailboxModification.feature", + glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.cassandra"}) +public class CassandraSetMailboxesMethodCucumberTest { +} http://git-wip-us.apache.org/repos/asf/james-project/blob/0cb80385/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodStepdefs.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodStepdefs.java new file mode 100644 index 0000000..1df517d --- /dev/null +++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMailboxesMethodStepdefs.java @@ -0,0 +1,60 @@ +/**************************************************************** + * 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 org.apache.james.CassandraJamesServerMain; +import org.apache.james.GuiceJamesServer; +import org.apache.james.backends.cassandra.EmbeddedCassandra; +import org.apache.james.jmap.methods.integration.SetMailboxesMethodStepdefs; +import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch; +import org.apache.james.modules.CassandraJmapServerModule; +import org.junit.rules.TemporaryFolder; + +import cucumber.api.java.After; +import cucumber.api.java.Before; + +public class CassandraSetMailboxesMethodStepdefs { + private final SetMailboxesMethodStepdefs mainStepdefs; + private TemporaryFolder temporaryFolder = new TemporaryFolder(); + private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder); + private EmbeddedCassandra cassandra = EmbeddedCassandra.createStartServer(); + + public CassandraSetMailboxesMethodStepdefs(SetMailboxesMethodStepdefs mainStepdefs) { + this.mainStepdefs = mainStepdefs; + } + + @Before + public void init() throws Exception { + temporaryFolder.create(); + embeddedElasticSearch.before(); + mainStepdefs.jmapServer = new GuiceJamesServer<>(CassandraJamesServerMain.cassandraId) + .combineWith(CassandraJamesServerMain.cassandraServerModule) + .overrideWith(new CassandraJmapServerModule(temporaryFolder, embeddedElasticSearch, cassandra)); + mainStepdefs.awaitMethod = () -> embeddedElasticSearch.awaitForElasticSearch(); + mainStepdefs.init(); + } + + @After + public void tearDown() { + mainStepdefs.tearDown(); + embeddedElasticSearch.after(); + temporaryFolder.delete(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/0cb80385/server/protocols/jmap-integration-testing/jmap-integration-testing-common/pom.xml ---------------------------------------------------------------------- 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 73613d4..7adbda6 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 @@ -170,6 +170,16 @@ <scope>test</scope> </dependency> <dependency> + <groupId>info.cukes</groupId> + <artifactId>cucumber-java</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>info.cukes</groupId> + <artifactId>cucumber-junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/james-project/blob/0cb80385/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodStepdefs.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodStepdefs.java new file mode 100644 index 0000000..6782d4d --- /dev/null +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodStepdefs.java @@ -0,0 +1,174 @@ +/**************************************************************** + * 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 com.jayway.restassured.RestAssured.given; +import static com.jayway.restassured.RestAssured.with; +import static com.jayway.restassured.config.EncoderConfig.encoderConfig; +import static com.jayway.restassured.config.RestAssuredConfig.newConfig; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; + +import java.io.ByteArrayInputStream; +import java.util.Date; +import java.util.stream.IntStream; + +import javax.mail.Flags; + +import org.apache.james.GuiceJamesServer; +import org.apache.james.jmap.JmapAuthentication; +import org.apache.james.jmap.api.access.AccessToken; +import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.model.MailboxConstants; +import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.store.mail.model.Mailbox; + +import com.github.fge.lambdas.Throwing; +import com.google.common.base.Charsets; +import com.jayway.restassured.RestAssured; +import com.jayway.restassured.http.ContentType; + +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import cucumber.api.java.en.When; + +public class SetMailboxesMethodStepdefs { + private static final String NAME = "[0][0]"; + private static final String ARGUMENTS = "[0][1]"; + + public GuiceJamesServer<?> jmapServer; + public Runnable awaitMethod = () -> {}; + + private AccessToken accessToken; + private String username; + + public void init() throws Exception { + jmapServer.start(); + RestAssured.port = jmapServer.getJmapPort(); + RestAssured.config = newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)); + RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(); + } + + public void tearDown() { + jmapServer.stop(); + } + + + @Given("^a domain named \"([^\"]*)\"$") + public void createDomain(String domain) throws Throwable { + jmapServer.serverProbe().addDomain(domain); + } + + @Given("^a current user with username \"([^\"]*)\" and password \"([^\"]*)\"$") + public void createUserWithPasswordAndAuthenticate(String username, String password) throws Throwable { + this.username = username; + jmapServer.serverProbe().addUser(username, password); + accessToken = JmapAuthentication.authenticateJamesUser(username, password); + } + + @Given("^mailbox \"([^\"]*)\" with (\\d+) messages$") + public void mailboxWithMessages(String mailboxName, int messageCount) throws Throwable { + jmapServer.serverProbe().createMailbox("#private", username, mailboxName); + MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, username, mailboxName); + IntStream + .range(0, messageCount) + .forEach(Throwing.intConsumer(i -> appendMessage(mailboxPath, i))); + awaitMethod.run(); + } + + private void appendMessage(MailboxPath mailboxPath, int i) throws MailboxException { + String content = "Subject: test" + i + "\r\n\r\n" + + "testBody" + i; + jmapServer.serverProbe().appendMessage(username, mailboxPath, + new ByteArrayInputStream(content.getBytes()), new Date(), false, new Flags()); + } + + @When("^renaming mailbox \"([^\"]*)\" to \"([^\"]*)\"") + public void renamingMailbox(String actualMailboxName, String newMailboxName) throws Throwable { + Mailbox<?> mailbox = jmapServer.serverProbe().getMailbox("#private", username, actualMailboxName); + String mailboxId = mailbox.getMailboxId().serialize(); + String requestBody = + "[" + + " [ \"setMailboxes\"," + + " {" + + " \"update\": {" + + " \"" + mailboxId + "\" : {" + + " \"name\" : \"" + newMailboxName + "\"" + + " }" + + " }" + + " }," + + " \"#0\"" + + " ]" + + "]"; + + with() + .accept(ContentType.JSON) + .contentType(ContentType.JSON) + .header("Authorization", this.accessToken.serialize()) + .body(requestBody) + .post("/jmap"); + } + + @When("^moving mailbox \"([^\"]*)\" to \"([^\"]*)\"$") + public void movingMailbox(String actualMailboxPath, String newParentMailboxPath) throws Throwable { + Mailbox<?> mailbox = jmapServer.serverProbe().getMailbox("#private", username, actualMailboxPath); + String mailboxId = mailbox.getMailboxId().serialize(); + Mailbox<?> parent = jmapServer.serverProbe().getMailbox("#private", username, newParentMailboxPath); + String parentId = parent.getMailboxId().serialize(); + + String requestBody = + "[" + + " [ \"setMailboxes\"," + + " {" + + " \"update\": {" + + " \"" + mailboxId + "\" : {" + + " \"parentId\" : \"" + parentId + "\"" + + " }" + + " }" + + " }," + + " \"#0\"" + + " ]" + + "]"; + + with() + .accept(ContentType.JSON) + .contentType(ContentType.JSON) + .header("Authorization", this.accessToken.serialize()) + .body(requestBody) + .post("/jmap"); + } + + @Then("^mailbox \"([^\"]*)\" contains (\\d+) messages$") + public void mailboxContainsMessages(String mailboxName, int messageCount) throws Throwable { + Mailbox<?> mailbox = jmapServer.serverProbe().getMailbox("#private", username, mailboxName); + String mailboxId = mailbox.getMailboxId().serialize(); + given() + .accept(ContentType.JSON) + .contentType(ContentType.JSON) + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + mailboxId + "\"]}}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messageList")) + .body(ARGUMENTS + ".messageIds", hasSize(messageCount)); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/0cb80385/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/MailboxModification.feature ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/MailboxModification.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/MailboxModification.feature new file mode 100644 index 0000000..2de6a18 --- /dev/null +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/MailboxModification.feature @@ -0,0 +1,20 @@ +Feature: Mailbox modification + As a James user + I want a mailbox to be modified when I modify it + I want my mails to be kept when modifying a mailbox + + Background: + Given a domain named "domain.tld" + And a current user with username "[email protected]" and password "secret" + + Scenario: Renaming a mailbox should keep messages + Given mailbox "A" with 2 messages + When renaming mailbox "A" to "B" + Then mailbox "B" contains 2 messages + + Scenario: Moving a mailbox should keep messages + Given mailbox "A" with 2 messages + And mailbox "A.B" with 3 messages + And mailbox "B" with 4 messages + When moving mailbox "A.B" to "B" + Then mailbox "B.B" contains 3 messages http://git-wip-us.apache.org/repos/asf/james-project/blob/0cb80385/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/pom.xml ---------------------------------------------------------------------- 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 fcd0d61..4254a7e 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 @@ -171,6 +171,21 @@ <scope>test</scope> </dependency> <dependency> + <groupId>info.cukes</groupId> + <artifactId>cucumber-java</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>info.cukes</groupId> + <artifactId>cucumber-junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>info.cukes</groupId> + <artifactId>cucumber-picocontainer</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/james-project/blob/0cb80385/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodCucumberTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodCucumberTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodCucumberTest.java new file mode 100644 index 0000000..a856c0b --- /dev/null +++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodCucumberTest.java @@ -0,0 +1,31 @@ +/**************************************************************** + * 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.junit.runner.RunWith; + +import cucumber.api.CucumberOptions; +import cucumber.api.junit.Cucumber; + +@RunWith(Cucumber.class) +@CucumberOptions(features="classpath:cucumber/MailboxModification.feature", + glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.memory"}) +public class MemorySetMailboxesMethodCucumberTest { +} http://git-wip-us.apache.org/repos/asf/james-project/blob/0cb80385/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodStepdefs.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodStepdefs.java new file mode 100644 index 0000000..ecd21aa --- /dev/null +++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/MemorySetMailboxesMethodStepdefs.java @@ -0,0 +1,54 @@ +/**************************************************************** + * 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.MemoryJamesServerMain; +import org.apache.james.jmap.methods.integration.SetMailboxesMethodStepdefs; +import org.apache.james.jmap.servers.MemoryJmapServerModule; +import org.junit.rules.TemporaryFolder; + +import cucumber.api.java.After; +import cucumber.api.java.Before; + +public class MemorySetMailboxesMethodStepdefs { + private final SetMailboxesMethodStepdefs mainStepdefs; + private final TemporaryFolder temporaryFolder; + + public MemorySetMailboxesMethodStepdefs(SetMailboxesMethodStepdefs mainStepdefs) { + this.mainStepdefs = mainStepdefs; + this.temporaryFolder = new TemporaryFolder(); + } + + @Before + public void init() throws Exception { + temporaryFolder.create(); + mainStepdefs.jmapServer = new GuiceJamesServer<>(MemoryJamesServerMain.inMemoryId) + .combineWith(MemoryJamesServerMain.inMemoryServerModule) + .overrideWith(new MemoryJmapServerModule(temporaryFolder)); + mainStepdefs.init(); + } + + @After + public void tearDown() { + mainStepdefs.tearDown(); + temporaryFolder.delete(); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
