You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/10/04 10:49:33 UTC
[13/18] james-project git commit: JAMES-2553 Rewrite
FixingGhostMailboxTest test in JUNIT 5
JAMES-2553 Rewrite FixingGhostMailboxTest test in JUNIT 5
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/485122c5
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/485122c5
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/485122c5
Branch: refs/heads/master
Commit: 485122c526728efb68000336a9e769a7e1c98b78
Parents: e6ab27c
Author: Benoit Tellier <bt...@linagora.com>
Authored: Mon Oct 1 11:58:13 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Thu Oct 4 17:48:43 2018 +0700
----------------------------------------------------------------------
.../org/apache/james/CassandraExtension.java | 6 +-
.../apache/james/FixingGhostMailboxTest.java | 134 +++++++++----------
2 files changed, 70 insertions(+), 70 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/485122c5/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraExtension.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraExtension.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraExtension.java
index ef7280f..41767e3 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraExtension.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraExtension.java
@@ -28,7 +28,11 @@ class CassandraExtension implements GuiceModuleTestExtension {
private final DockerCassandraRule cassandra;
CassandraExtension() {
- this.cassandra = new DockerCassandraRule();
+ this(new DockerCassandraRule());
+ }
+
+ public CassandraExtension(DockerCassandraRule cassandra) {
+ this.cassandra = cassandra;
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/485122c5/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
----------------------------------------------------------------------
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 e5f5f42..51e1e7d 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
@@ -25,6 +25,7 @@ import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.with;
import static io.restassured.config.EncoderConfig.encoderConfig;
import static io.restassured.config.RestAssuredConfig.newConfig;
+import static org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
import static org.apache.james.jmap.HttpJmapAuthentication.authenticateJamesUser;
import static org.apache.james.jmap.JmapURIBuilder.baseUri;
import static org.assertj.core.api.Assertions.assertThat;
@@ -45,16 +46,18 @@ import org.apache.james.mailbox.MessageManager.AppendCommand;
import org.apache.james.mailbox.cassandra.mail.task.MailboxMergingTask;
import org.apache.james.mailbox.cassandra.table.CassandraMailboxPathV2Table;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.apache.james.mailbox.model.ComposedMessageId;
import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.probe.ACLProbe;
+import org.apache.james.mailbox.store.search.PDFTextExtractor;
import org.apache.james.mime4j.dom.Message;
import org.apache.james.modules.ACLProbeImpl;
import org.apache.james.modules.MailboxProbeImpl;
-import org.apache.james.probe.DataProbe;
+import org.apache.james.modules.TestJMAPServerModule;
import org.apache.james.server.CassandraProbe;
import org.apache.james.task.TaskManager;
import org.apache.james.utils.DataProbeImpl;
@@ -64,11 +67,9 @@ import org.apache.james.webadmin.WebAdminConfiguration;
import org.apache.james.webadmin.WebAdminUtils;
import org.apache.james.webadmin.routes.CassandraMailboxMergingRoutes;
import org.apache.james.webadmin.routes.TasksRoutes;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
@@ -79,23 +80,33 @@ import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
public class FixingGhostMailboxTest {
-
+ private static final int LIMIT_TO_10_MESSAGES = 10;
private static final String NAME = "[0][0]";
private static final String ARGUMENTS = "[0][1]";
private static final String FIRST_MAILBOX = ARGUMENTS + ".list[0]";
- @ClassRule
- public static DockerCassandraRule cassandra = new DockerCassandraRule();
-
- @Rule
- public CassandraJmapTestRule rule = CassandraJmapTestRule.defaultTestRule();
+ private static final String DOMAIN = "domain.tld";
+ private static final String CEDRIC = "cedric@" + DOMAIN;
+ private static final String BOB = "bob@" + DOMAIN;
+ private static final String ALICE = "alice@" + DOMAIN;
+ private static final String ALICE_SECRET = "aliceSecret";
+ private static final String BOB_SECRET = "bobSecret";
+
+ public static final DockerCassandraRule cassandra = new DockerCassandraRule();
+
+ @RegisterExtension
+ static JamesServerExtension testExtension = new JamesServerExtensionBuilder()
+ .extension(new EmbeddedElasticSearchExtension())
+ .extension(new CassandraExtension(cassandra))
+ .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(binder -> binder.bind(WebAdminConfiguration.class)
+ .toInstance(WebAdminConfiguration.TEST_CONFIGURATION)))
+ .build();
private AccessToken accessToken;
- private String domain;
- private String alice;
- private String bob;
- private String cedric;
- private GuiceJamesServer jmapServer;
private MailboxProbeImpl mailboxProbe;
private ACLProbe aclProbe;
private Session session;
@@ -103,45 +114,35 @@ public class FixingGhostMailboxTest {
private MailboxId aliceGhostInboxId;
private MailboxPath aliceInboxPath;
private ComposedMessageId message2;
- private WebAdminGuiceProbe webAdminProbe;
private RequestSpecification webadminSpecification;
- @Before
- public void setup() throws Throwable {
- jmapServer = rule.jmapServer(cassandra.getModule(),
- binder -> binder.bind(WebAdminConfiguration.class)
- .toInstance(WebAdminConfiguration.TEST_CONFIGURATION));
- jmapServer.start();
- webAdminProbe = jmapServer.getProbe(WebAdminGuiceProbe.class);
- mailboxProbe = jmapServer.getProbe(MailboxProbeImpl.class);
- aclProbe = jmapServer.getProbe(ACLProbeImpl.class);
+ @BeforeEach
+ void setup(GuiceJamesServer server) throws Throwable {
+ WebAdminGuiceProbe webAdminProbe = server.getProbe(WebAdminGuiceProbe.class);
+ mailboxProbe = server.getProbe(MailboxProbeImpl.class);
+ aclProbe = server.getProbe(ACLProbeImpl.class);
RestAssured.requestSpecification = new RequestSpecBuilder()
.setContentType(ContentType.JSON)
.setAccept(ContentType.JSON)
.setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)))
- .setPort(jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort())
+ .setPort(server.getProbe(JmapGuiceProbe.class).getJmapPort())
.build();
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
webadminSpecification = WebAdminUtils.buildRequestSpecification(webAdminProbe.getWebAdminPort())
.build();
- domain = "domain.tld";
- alice = "alice@" + domain;
- String alicePassword = "aliceSecret";
- bob = "bob@" + domain;
- cedric = "cedric@" + domain;
- DataProbe dataProbe = jmapServer.getProbe(DataProbeImpl.class);
- dataProbe.addDomain(domain);
- dataProbe.addUser(alice, alicePassword);
- dataProbe.addUser(bob, "bobSecret");
- accessToken = authenticateJamesUser(baseUri(jmapServer), alice, alicePassword);
+ server.getProbe(DataProbeImpl.class).fluent()
+ .addDomain(DOMAIN)
+ .addUser(ALICE, ALICE_SECRET)
+ .addUser(BOB, BOB_SECRET);
+ accessToken = authenticateJamesUser(baseUri(server), ALICE, ALICE_SECRET);
session = Cluster.builder()
.addContactPoint(cassandra.getIp())
.withPort(cassandra.getMappedPort(9042))
.build()
- .connect(jmapServer.getProbe(CassandraProbe.class).getKeyspace());
+ .connect(server.getProbe(CassandraProbe.class).getKeyspace());
simulateGhostMailboxBug();
}
@@ -149,16 +150,16 @@ public class FixingGhostMailboxTest {
private void simulateGhostMailboxBug() throws MailboxException, IOException {
// State before ghost mailbox bug
// Alice INBOX is delegated to Bob and contains one message
- aliceInboxPath = MailboxPath.forUser(alice, MailboxConstants.INBOX);
- aliceGhostInboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
- aclProbe.addRights(aliceInboxPath, bob, MailboxACL.FULL_RIGHTS);
- message1 = mailboxProbe.appendMessage(alice, aliceInboxPath, AppendCommand.from(generateMessageContent()));
- rule.await();
+ aliceInboxPath = MailboxPath.forUser(ALICE, MailboxConstants.INBOX);
+ aliceGhostInboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
+ aclProbe.addRights(aliceInboxPath, BOB, MailboxACL.FULL_RIGHTS);
+ message1 = mailboxProbe.appendMessage(ALICE, aliceInboxPath, AppendCommand.from(generateMessageContent()));
+ testExtension.await();
// Simulate ghost mailbox bug
session.execute(delete().from(CassandraMailboxPathV2Table.TABLE_NAME)
.where(eq(CassandraMailboxPathV2Table.NAMESPACE, MailboxConstants.USER_NAMESPACE))
- .and(eq(CassandraMailboxPathV2Table.USER, alice))
+ .and(eq(CassandraMailboxPathV2Table.USER, ALICE))
.and(eq(CassandraMailboxPathV2Table.MAILBOX_NAME, MailboxConstants.INBOX)));
// trigger provisioning
@@ -171,8 +172,8 @@ public class FixingGhostMailboxTest {
.statusCode(200);
// Received a new message
- message2 = mailboxProbe.appendMessage(alice, aliceInboxPath, AppendCommand.from(generateMessageContent()));
- rule.await();
+ message2 = mailboxProbe.appendMessage(ALICE, aliceInboxPath, AppendCommand.from(generateMessageContent()));
+ testExtension.await();
}
private Message generateMessageContent() throws IOException {
@@ -182,21 +183,16 @@ public class FixingGhostMailboxTest {
.build();
}
- @After
- public void teardown() {
- jmapServer.stop();
- }
-
@Test
- public void ghostMailboxBugShouldChangeMailboxId() throws Exception {
- MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
+ void ghostMailboxBugShouldChangeMailboxId() {
+ MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
assertThat(aliceGhostInboxId).isNotEqualTo(newAliceInbox);
}
@Test
- public void ghostMailboxBugShouldDiscardOldContent() throws Exception {
- MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
+ void ghostMailboxBugShouldDiscardOldContent() {
+ MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
given()
.header("Authorization", accessToken.serialize())
@@ -212,8 +208,8 @@ public class FixingGhostMailboxTest {
}
@Test
- public void webadminCanMergeTwoMailboxes() throws Exception {
- MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
+ void webadminCanMergeTwoMailboxes() {
+ MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
fixGhostMailboxes(newAliceInbox);
@@ -232,9 +228,9 @@ public class FixingGhostMailboxTest {
}
@Test
- public void webadminCanMergeTwoMailboxesRights() throws Exception {
- MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
- aclProbe.addRights(aliceInboxPath, cedric, MailboxACL.FULL_RIGHTS);
+ void webadminCanMergeTwoMailboxesRights() throws Exception {
+ MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
+ aclProbe.addRights(aliceInboxPath, CEDRIC, MailboxACL.FULL_RIGHTS);
fixGhostMailboxes(newAliceInbox);
@@ -246,14 +242,14 @@ public class FixingGhostMailboxTest {
.then()
.statusCode(200)
.body(NAME, equalTo("mailboxes"))
- .body(FIRST_MAILBOX + ".sharedWith", hasKey(bob))
- .body(FIRST_MAILBOX + ".sharedWith", hasKey(cedric));
+ .body(FIRST_MAILBOX + ".sharedWith", hasKey(BOB))
+ .body(FIRST_MAILBOX + ".sharedWith", hasKey(CEDRIC));
}
@Test
- public void oldGhostedMailboxShouldNoMoreBeAccessible() throws Exception {
- MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
- aclProbe.addRights(aliceInboxPath, cedric, MailboxACL.FULL_RIGHTS);
+ void oldGhostedMailboxShouldNoMoreBeAccessible() throws Exception {
+ MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
+ aclProbe.addRights(aliceInboxPath, CEDRIC, MailboxACL.FULL_RIGHTS);
fixGhostMailboxes(newAliceInbox);
@@ -269,8 +265,8 @@ public class FixingGhostMailboxTest {
}
@Test
- public void mergingMailboxTaskShouldBeInformative() {
- MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, alice, MailboxConstants.INBOX);
+ void mergingMailboxTaskShouldBeInformative() {
+ MailboxId newAliceInbox = mailboxProbe.getMailboxId(MailboxConstants.USER_NAMESPACE, ALICE, MailboxConstants.INBOX);
String taskId = fixGhostMailboxes(newAliceInbox);
@@ -308,7 +304,7 @@ public class FixingGhostMailboxTest {
.spec(webadminSpecification)
.basePath(TasksRoutes.BASE)
.get(taskId + "/await");
- rule.await();
+ testExtension.await();
return taskId;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org