@Test public void getParentIdFromMailboxPathShouldReturnParentIdWhenChildOfChildMailbox() throws Exception { MailboxPath mailboxPath = MailboxPath.forUser(user, "inbox.children.mailbox"); mailboxManager.createMailbox(MailboxPath.forUser(user, "inbox"), mailboxSession); MailboxPath parentMailboxPath = MailboxPath.forUser(user, "inbox.children"); mailboxManager.createMailbox(parentMailboxPath, mailboxSession); MailboxId parentId = mailboxManager.getMailbox(parentMailboxPath, mailboxSession).getId(); mailboxManager.createMailbox(mailboxPath, mailboxSession); Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, Optional.empty(), mailboxSession); assertThat(id).contains(parentId); }
@Test public void getParentIdFromMailboxPathShouldWorkWhenUserMailboxesProvided() throws Exception { MailboxPath mailboxPath = MailboxPath.forUser(user, "inbox.children.mailbox"); mailboxManager.createMailbox(MailboxPath.forUser(user, "inbox"), mailboxSession); MailboxPath parentMailboxPath = MailboxPath.forUser(user, "inbox.children"); mailboxManager.createMailbox(parentMailboxPath, mailboxSession); MailboxId parentId = mailboxManager.getMailbox(parentMailboxPath, mailboxSession).getId(); mailboxManager.createMailbox(mailboxPath, mailboxSession); Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, Optional.of(ImmutableList.of(new SimpleMailboxMetaData(parentMailboxPath, parentId, DELIMITER))), mailboxSession); assertThat(id).contains(parentId); }
@Test public void getParentIdFromMailboxPathShouldReturnParentIdWhenChildMailbox() throws Exception { MailboxPath parentMailboxPath = MailboxPath.forUser(user, "inbox"); mailboxManager.createMailbox(parentMailboxPath, mailboxSession); MailboxId parentId = mailboxManager.getMailbox(parentMailboxPath, mailboxSession).getId(); MailboxPath mailboxPath = MailboxPath.forUser(user, "inbox.mailbox"); mailboxManager.createMailbox(mailboxPath, mailboxSession); Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, Optional.empty(), mailboxSession); assertThat(id).contains(parentId); }
@Test public void getParentIdFromMailboxPathShouldReturNullWhenRootMailbox() throws Exception { MailboxPath mailboxPath = MailboxPath.forUser(user, "mailbox"); mailboxManager.createMailbox(mailboxPath, mailboxSession); Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, Optional.empty(), mailboxSession); assertThat(id).isEmpty(); }
@Test public void getNamespaceShouldReturnPersonalNamespaceWhenUserMailboxPathAndUserMailboxSessionAreTheSame() throws Exception { MailboxPath inbox = MailboxPath.forUser(user, "inbox"); Optional<MailboxId> mailboxId = mailboxManager.createMailbox(inbox, mailboxSession); Mailbox retrievedMailbox = sut.builder() .id(mailboxId.get()) .session(mailboxSession) .build() .get(); assertThat(retrievedMailbox.getNamespace()) .isEqualTo(MailboxNamespace.personal()); }
@Test(expected = MailQueue.MailQueueException.class) public void doneShouldThrowWhenMailboxException() throws Exception { MessageIdManager messageIdManager = mock(MessageIdManager.class); testee = new PostDequeueDecorator(mockedMailQueueItem, mailboxManager, new InMemoryMessageId.Factory(), messageIdManager, new SystemMailboxesProviderImpl(mailboxManager)); MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession).get(); MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message), mailboxSession); mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize()); mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME); when(messageIdManager.getMessages(eq(ImmutableList.of(messageId.getMessageId())), eq(FetchGroupImpl.MINIMAL), any(MailboxSession.class))).thenThrow(MailboxException.class); testee.done(true); } }
@Test public void doneShouldNotMoveMailFromOutboxToSentWhenNoMetadataProvided() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); messageManager.appendMessage(AppendCommand.from(message), mailboxSession); testee.done(true); MessageManager mailbox = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); MessageResultIterator resultIterator = mailbox.getMessages(MessageRange.one(UID), FetchGroupImpl.FULL_CONTENT, mailboxSession); assertThat(resultIterator).hasSize(1); }
@Test public void mailboxFromMailboxIdShouldReturnPresentWhenExists() throws Exception { MailboxPath mailboxPath = MailboxPath.forUser(user, "myBox"); mailboxManager.createMailbox(mailboxPath, mailboxSession); MailboxId mailboxId = mailboxManager.getMailbox(mailboxPath, mailboxSession).getId(); Optional<Mailbox> mailbox = sut.builder() .id(mailboxId) .session(mailboxSession) .build(); assertThat(mailbox).isPresent(); assertThat(mailbox.get().getId()).isEqualTo(mailboxId); }
@Test public void doneShouldNotThrowWhenMessageIsNotInOutbox() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(SENT_MAILBOX_PATH, mailboxSession); ComposedMessageId sentMessageId = messageManager.appendMessage(AppendCommand.from(message), mailboxSession); mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, sentMessageId.getMessageId().serialize()); mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME); testee.done(true); }
@Test public void doneShouldNotMoveMailFromOutboxToSentWhenMessageIdNotProvided() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); messageManager.appendMessage(AppendCommand.from(message), mailboxSession); mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME); testee.done(true); MessageManager mailbox = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); MessageResultIterator resultIterator = mailbox.getMessages(MessageRange.one(UID), FetchGroupImpl.FULL_CONTENT, mailboxSession); assertThat(resultIterator).hasSize(1); }
@Test public void doneShouldNotMoveMailFromOutboxToSentWhenInvalidMessageIdProvided() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); messageManager.appendMessage(AppendCommand.from(message), mailboxSession); mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME); mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, "invalid"); testee.done(true); MessageManager mailbox = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); MessageResultIterator resultIterator = mailbox.getMessages(MessageRange.one(UID), FetchGroupImpl.FULL_CONTENT, mailboxSession); assertThat(resultIterator).hasSize(1); }
@Test public void getMailboxesShouldReturnInboxWithSortOrder10() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, "INBOX"); mailboxManager.createMailbox(mailboxPath, mailboxSession); GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) .extracting(JmapResponse::getResponse) .hasOnlyElementsOfType(GetMailboxesResponse.class) .extracting(GetMailboxesResponse.class::cast) .flatExtracting(GetMailboxesResponse::getList) .extracting(Mailbox::getSortOrder) .containsOnly(SortOrder.of(10)); }
@Test public void doneShouldNotMoveMailFromOutboxToSentWhenUsernameNotProvided() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message), mailboxSession); mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize()); testee.done(true); MessageManager mailbox = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); MessageResultIterator resultIterator = mailbox.getMessages(MessageRange.one(UID), FetchGroupImpl.FULL_CONTENT, mailboxSession); assertThat(resultIterator).hasSize(1); }
@Test public void getMailboxesShouldReturnSortOrder1000OnUnknownFolder() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, "unknown"); mailboxManager.createMailbox(mailboxPath, mailboxSession); GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) .extracting(JmapResponse::getResponse) .hasOnlyElementsOfType(GetMailboxesResponse.class) .extracting(GetMailboxesResponse.class::cast) .flatExtracting(GetMailboxesResponse::getList) .extracting(Mailbox::getSortOrder) .containsOnly(SortOrder.of(1000)); }
@Test public void getMailboxesShouldReturnInboxWithSortOrder10OnDifferenceCase() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, "InBoX"); mailboxManager.createMailbox(mailboxPath, mailboxSession); GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, mailboxSession).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) .extracting(JmapResponse::getResponse) .hasOnlyElementsOfType(GetMailboxesResponse.class) .extracting(GetMailboxesResponse.class::cast) .flatExtracting(GetMailboxesResponse::getList) .extracting(Mailbox::getSortOrder) .containsOnly(SortOrder.of(10)); }
@Test public void doneShouldNotMoveMailFromOutboxToSentWhenSuccessIsFalse() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message), mailboxSession); mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize()); mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME); testee.done(false); MessageManager mailbox = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); MessageResultIterator resultIterator = mailbox.getMessages(MessageRange.one(UID), FetchGroupImpl.FULL_CONTENT, mailboxSession); assertThat(resultIterator).hasSize(1); }
@Test public void doneShouldCopyMailFromOutboxToSentWhenSuccess() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message), mailboxSession); mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize()); mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME); testee.done(true); MessageManager sentMailbox = mailboxManager.getMailbox(SENT_MAILBOX_PATH, mailboxSession); MessageResultIterator resultIterator = sentMailbox.getMessages(MessageRange.one(UID), FetchGroupImpl.FULL_CONTENT, mailboxSession); assertThat(resultIterator).hasSize(1); }
@Test public void doneShouldDeleteMailFromOutboxWhenSuccess() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message), mailboxSession); mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize()); mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME); testee.done(true); MessageManager mailbox = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); MessageResultIterator resultIterator = mailbox.getMessages(MessageRange.one(UID), FetchGroupImpl.FULL_CONTENT, mailboxSession); assertThat(resultIterator).hasSize(0); }
@Test(expected = MailboxRoleNotFoundException.class) public void doneShouldThrowWhenSentDoesNotExist() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME); mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession); ComposedMessageId messageId = messageManager.appendMessage(AppendCommand.from(message), mailboxSession); mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize()); mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME); testee.done(true); }
@Test public void ownerShouldHaveFullRightsViaMayProperties() throws Exception { MailboxPath inbox = MailboxPath.forUser(user, "inbox"); Optional<MailboxId> mailboxId = mailboxManager.createMailbox(inbox, mailboxSession); Mailbox retrievedMailbox = sut.builder() .id(mailboxId.get()) .session(mailboxSession) .build() .get(); softly.assertThat(retrievedMailbox.isMayAddItems()).isTrue(); softly.assertThat(retrievedMailbox.isMayCreateChild()).isTrue(); softly.assertThat(retrievedMailbox.isMayDelete()).isTrue(); softly.assertThat(retrievedMailbox.isMayReadItems()).isTrue(); softly.assertThat(retrievedMailbox.isMayRemoveItems()).isTrue(); softly.assertThat(retrievedMailbox.isMayRename()).isTrue(); }