Skip to content

Commit

Permalink
JAMES-2169 Various JMAP integration testing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
chibenwa committed Oct 4, 2017
1 parent 5edd32a commit 0f5a0f2
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 353 deletions.
Expand Up @@ -48,7 +48,6 @@
import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.mail.model.Mailbox;
import org.apache.james.mailbox.store.probe.MailboxProbe; import org.apache.james.mailbox.store.probe.MailboxProbe;
import org.apache.james.mime4j.dom.Message; import org.apache.james.mime4j.dom.Message;
import org.apache.james.mime4j.dom.MessageWriter; import org.apache.james.mime4j.dom.MessageWriter;
Expand Down Expand Up @@ -126,17 +125,15 @@ public void teardown() {


@Test @Test
public void getMessageListShouldNotDuplicateMessagesInSeveralMailboxes() throws Exception { public void getMessageListShouldNotDuplicateMessagesInSeveralMailboxes() throws Exception {
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); MailboxId mailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2"); MailboxId mailboxId2 = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2");
Mailbox mailbox = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
Mailbox mailbox2 = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2");


ComposedMessageId message = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ComposedMessageId message = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());


await(); await();


jmapServer.getProbe(JmapGuiceProbe.class).setInMailboxes(message.getMessageId(), username, mailbox.getMailboxId(), mailbox2.getMailboxId()); jmapServer.getProbe(JmapGuiceProbe.class).setInMailboxes(message.getMessageId(), username, mailboxId, mailboxId2);


given() given()
.header("Authorization", accessToken.serialize()) .header("Authorization", accessToken.serialize())
Expand Down Expand Up @@ -624,13 +621,11 @@ public void getMessageListShouldReturnAllMessagesOfCurrentUserOnlyWhenMultipleMa


@Test @Test
public void getMessageListShouldFilterMessagesWhenInMailboxesFilterMatches() throws Exception { public void getMessageListShouldFilterMessagesWhenInMailboxesFilterMatches() throws Exception {
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); MailboxId mailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
ComposedMessageId message = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ComposedMessageId message = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
await(); await();


MailboxId mailboxId = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox").getMailboxId();

given() given()
.header("Authorization", accessToken.serialize()) .header("Authorization", accessToken.serialize())
.body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + mailboxId.serialize() + "\"]}}, \"#0\"]]") .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + mailboxId.serialize() + "\"]}}, \"#0\"]]")
Expand All @@ -644,16 +639,13 @@ public void getMessageListShouldFilterMessagesWhenInMailboxesFilterMatches() thr


@Test @Test
public void getMessageListShouldFilterMessagesWhenMultipleInMailboxesFilterMatches() throws Exception { public void getMessageListShouldFilterMessagesWhenMultipleInMailboxesFilterMatches() throws Exception {
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); MailboxId mailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
ComposedMessageId message = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ComposedMessageId message = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());


mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2"); MailboxId mailboxId2 = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2");
await(); await();


MailboxId mailboxId = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox").getMailboxId();
MailboxId mailboxId2 = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2").getMailboxId();

given() given()
.header("Authorization", accessToken.serialize()) .header("Authorization", accessToken.serialize())
.body(String.format("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"%s\", \"%s\"]}}, \"#0\"]]", mailboxId.serialize(), mailboxId2.serialize())) .body(String.format("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"%s\", \"%s\"]}}, \"#0\"]]", mailboxId.serialize(), mailboxId2.serialize()))
Expand All @@ -667,12 +659,10 @@ public void getMessageListShouldFilterMessagesWhenMultipleInMailboxesFilterMatch


@Test @Test
public void getMessageListShouldFilterMessagesWhenNotInMailboxesFilterMatches() throws Exception { public void getMessageListShouldFilterMessagesWhenNotInMailboxesFilterMatches() throws Exception {
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); MailboxId mailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
MailboxId mailboxId = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox").getMailboxId();


mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2");
await(); await();


given() given()
Expand All @@ -688,15 +678,13 @@ public void getMessageListShouldFilterMessagesWhenNotInMailboxesFilterMatches()


@Test @Test
public void getMessageListShouldFilterMessagesWhenNotInMailboxesFilterMatchesTwice() throws Exception { public void getMessageListShouldFilterMessagesWhenNotInMailboxesFilterMatchesTwice() throws Exception {
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); MailboxId mailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
MailboxId mailboxId = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox").getMailboxId();


mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2"); MailboxId mailbox2Id = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2");
mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox2"), mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox2"),
new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
MailboxId mailbox2Id = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2").getMailboxId();
await(); await();


given() given()
Expand All @@ -712,10 +700,9 @@ public void getMessageListShouldFilterMessagesWhenNotInMailboxesFilterMatchesTwi


@Test @Test
public void getMessageListShouldFilterMessagesWhenIdenticalNotInMailboxesAndInmailboxesFilterMatch() throws Exception { public void getMessageListShouldFilterMessagesWhenIdenticalNotInMailboxesAndInmailboxesFilterMatch() throws Exception {
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); MailboxId mailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
MailboxId mailboxId = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox").getMailboxId();
await(); await();


given() given()
Expand All @@ -735,8 +722,7 @@ public void getMessageListShouldNotFilterMessagesWhenNotInMailboxesFilterDoesNot
ComposedMessageId message = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), ComposedMessageId message = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());


mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2"); MailboxId mailbox2Id = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2");
MailboxId mailbox2Id = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2").getMailboxId();
await(); await();


given() given()
Expand Down Expand Up @@ -772,9 +758,8 @@ public void getMessageListShouldNotFilterMessagesWhenEmptyNotInMailboxesFilter()


@Test @Test
public void getMessageListShouldFilterMessagesWhenInMailboxesFilterDoesntMatches() throws Exception { public void getMessageListShouldFilterMessagesWhenInMailboxesFilterDoesntMatches() throws Exception {
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "emptyMailbox"); MailboxId emptyMailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "emptyMailbox");
MailboxId emptyMailboxId = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, "emptyMailbox").getMailboxId();

mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
Expand Down

0 comments on commit 0f5a0f2

Please sign in to comment.