@Override public List<MailboxPath> list(MailboxSession session) throws MailboxException { return mailboxSessionMapperFactory.getMailboxMapper(session) .list() .stream() .map(Mailbox::generateAssociatedPath) .collect(Guavate.toImmutableList()); }
@Override public List<MailboxMessage> find(Collection<MessageId> messageIds, MessageMapper.FetchType fetchType) { try { return mailboxMapper.list() .stream() .flatMap(Throwing.function(mailbox -> ImmutableList.copyOf( messageMapper.findInMailbox(mailbox, MessageRange.all(), fetchType, UNLIMITED)) .stream())) .filter(message -> messageIds.contains(message.getMessageId())) .collect(Guavate.toImmutableList()); } catch (MailboxException e) { throw new RuntimeException(e); } }
@After public void tearDown() throws MailboxException { mailboxMapper.list() .forEach(Throwing.consumer(mailboxMapper::delete)); }
@Test public void createMailboxShouldCreateAMailbox() throws Exception { mailboxManagerManagement.createMailbox(MailboxConstants.USER_NAMESPACE, USER, "name"); assertThat(mapperFactory.createMailboxMapper(session).list()).hasSize(1); assertThat(mapperFactory.createMailboxMapper(session).findMailboxByPath(MailboxPath.forUser(USER, "name"))).isNotNull(); }
@Test public void createMailboxShouldNotCreateAdditionalMailboxesIfMailboxAlreadyExists() throws Exception { MailboxPath path = MailboxPath.forUser(USER, "name"); Mailbox mailbox = new SimpleMailbox(path, UID_VALIDITY); mapperFactory.createMailboxMapper(session).save(mailbox); assertThat(mapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox); }
@Test public void deleteMailboxesShouldDeleteInbox() throws Exception { mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY)); mailboxManagerManagement.deleteMailboxes(USER); assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty(); }
@Test public void deleteMailboxesShouldNotDeleteMailboxesBelongingToOtherUsers() throws Exception { Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser("userbis", "name"), UID_VALIDITY); mapperFactory.createMailboxMapper(session).save(mailbox); mailboxManagerManagement.deleteMailboxes(USER); assertThat(mapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox); }
@Test public void deleteMailboxesShouldDeleteMailboxesWithEmptyNames() throws Exception { mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, ""), UID_VALIDITY)); mailboxManagerManagement.deleteMailboxes(USER); assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty(); }
@Test public void deleteMailboxesShouldDeleteMailboxes() throws Exception { mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY)); mailboxManagerManagement.deleteMailboxes(USER); assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty(); }
@Test public void deleteMailboxShouldDeleteGivenMailbox() throws Exception { mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY)); mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name"); assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty(); }
@Test public void deleteMailboxesShouldDeleteMailboxesChildren() throws Exception { mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY)); mailboxManagerManagement.deleteMailboxes(USER); assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty(); }
@Test public void deleteMailboxesShouldNotDeleteMailboxesBelongingToNotPrivateNamespace() throws Exception { Mailbox mailbox = new SimpleMailbox(new MailboxPath("#top", USER, "name"), UID_VALIDITY); mapperFactory.createMailboxMapper(session).save(mailbox); mailboxManagerManagement.deleteMailboxes(USER); assertThat(mapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox); }
@Test public void deleteMailboxShouldNotDeleteGivenMailboxIfWrongUser() throws Exception { Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser("userbis", "name"), UID_VALIDITY); mapperFactory.createMailboxMapper(session).save(mailbox); mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name"); assertThat(mapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox); }
@Test public void deleteMailboxShouldNotDeleteGivenMailboxIfWrongName() throws Exception { Mailbox mailbox = new SimpleMailbox(MailboxPath.forUser(USER, "wrong_name"), UID_VALIDITY); mapperFactory.createMailboxMapper(session).save(mailbox); mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name"); assertThat(mapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox); }
@Test public void deleteMailboxShouldNotDeleteGivenMailboxIfWrongNamespace() throws Exception { Mailbox mailbox = new SimpleMailbox(new MailboxPath("#top", USER, "name"), UID_VALIDITY); mapperFactory.createMailboxMapper(session).save(mailbox); mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER, "name"); assertThat(mapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox); }
@Test public void deleteMailboxesShouldDeleteMultipleMailboxes() throws Exception { mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY)); mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY)); mapperFactory.createMailboxMapper(session).save(new SimpleMailbox(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY)); mailboxManagerManagement.deleteMailboxes(USER); assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty(); }