ReIndexerImpl implements ReIndexer { @Override public Task reIndex(MailboxPath path, RunningOptions runningOptions) throws MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession(path.getUser()); MailboxId mailboxId = mailboxManager.getMailbox(path, mailboxSession).getId(); return new SingleMailboxReindexingTask(reIndexerPerformer, mailboxId, runningOptions); } @Inject  ReIndexerImpl(ReIndexerPerformer reIndexerPerformer, MailboxManager mailboxManager, MailboxSessionMapperFactory mapperFactory); @Override Task reIndex(MailboxPath path, RunningOptions runningOptions); @Override Task reIndex(MailboxId mailboxId, RunningOptions runningOptions); @Override Task reIndex(RunningOptions runningOptions); @Override Task reIndex(Username username, RunningOptions runningOptions); @Override Task reIndex(MailboxPath path, MessageUid uid); @Override Task reIndex(MailboxId mailboxId, MessageUid uid); @Override Task reIndex(ReIndexingExecutionFailures previousFailures, RunningOptions runningOptions);  }
@Test void reIndexMailboxPathShouldCallMessageSearchIndex() throws Exception { MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME); MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get(); ComposedMessageId createdMessage = mailboxManager.getMailbox(INBOX, systemSession) .appendMessage( MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"), systemSession).getId(); reIndexer.reIndex(INBOX, RunningOptions.DEFAULT).run(); ArgumentCaptor<MailboxMessage> messageCaptor = ArgumentCaptor.forClass(MailboxMessage.class); ArgumentCaptor<MailboxId> mailboxCaptor1 = ArgumentCaptor.forClass(MailboxId.class); ArgumentCaptor<Mailbox> mailboxCaptor2 = ArgumentCaptor.forClass(Mailbox.class); verify(messageSearchIndex).deleteAll(any(MailboxSession.class), mailboxCaptor1.capture()); verify(messageSearchIndex).add(any(MailboxSession.class), mailboxCaptor2.capture(), messageCaptor.capture()); verifyNoMoreInteractions(messageSearchIndex); assertThat(mailboxCaptor1.getValue()).satisfies(capturedMailboxId -> assertThat(capturedMailboxId).isEqualTo(mailboxId)); assertThat(mailboxCaptor2.getValue()).satisfies(mailbox -> assertThat(mailbox.getMailboxId()).isEqualTo(mailboxId)); assertThat(messageCaptor.getValue()).satisfies(message -> { assertThat(message.getMailboxId()).isEqualTo(mailboxId); assertThat(message.getUid()).isEqualTo(createdMessage.getUid()); }); }
@Test void reIndexAllShouldCallMessageSearchIndex() throws Exception { MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME); MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get(); ComposedMessageId createdMessage = mailboxManager.getMailbox(INBOX, systemSession) .appendMessage( MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"), systemSession).getId(); reIndexer.reIndex(RunningOptions.DEFAULT).run(); ArgumentCaptor<MailboxMessage> messageCaptor = ArgumentCaptor.forClass(MailboxMessage.class); ArgumentCaptor<MailboxId> mailboxCaptor1 = ArgumentCaptor.forClass(MailboxId.class); ArgumentCaptor<Mailbox> mailboxCaptor2 = ArgumentCaptor.forClass(Mailbox.class); verify(messageSearchIndex).deleteAll(any(MailboxSession.class), mailboxCaptor1.capture()); verify(messageSearchIndex).add(any(MailboxSession.class), mailboxCaptor2.capture(), messageCaptor.capture()); verifyNoMoreInteractions(messageSearchIndex); assertThat(mailboxCaptor1.getValue()).satisfies(capturedMailboxId -> assertThat(capturedMailboxId).isEqualTo(mailboxId)); assertThat(mailboxCaptor2.getValue()).satisfies(mailbox -> assertThat(mailbox.getMailboxId()).isEqualTo(mailboxId)); assertThat(messageCaptor.getValue()).satisfies(message -> { assertThat(message.getMailboxId()).isEqualTo(mailboxId); assertThat(message.getUid()).isEqualTo(createdMessage.getUid()); }); }
@Test void userReIndexShouldCallMessageSearchIndex() throws Exception { MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME); MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get(); ComposedMessageId createdMessage = mailboxManager.getMailbox(INBOX, systemSession) .appendMessage( MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"), systemSession).getId(); reIndexer.reIndex(USERNAME, RunningOptions.DEFAULT).run(); ArgumentCaptor<MailboxMessage> messageCaptor = ArgumentCaptor.forClass(MailboxMessage.class); ArgumentCaptor<MailboxId> mailboxCaptor1 = ArgumentCaptor.forClass(MailboxId.class); ArgumentCaptor<Mailbox> mailboxCaptor2 = ArgumentCaptor.forClass(Mailbox.class); verify(messageSearchIndex).deleteAll(any(MailboxSession.class), mailboxCaptor1.capture()); verify(messageSearchIndex).add(any(MailboxSession.class), mailboxCaptor2.capture(), messageCaptor.capture()); verifyNoMoreInteractions(messageSearchIndex); assertThat(mailboxCaptor1.getValue()).satisfies(capturedMailboxId -> assertThat(capturedMailboxId).isEqualTo(mailboxId)); assertThat(mailboxCaptor2.getValue()).satisfies(mailbox -> assertThat(mailbox.getMailboxId()).isEqualTo(mailboxId)); assertThat(messageCaptor.getValue()).satisfies(message -> { assertThat(message.getMailboxId()).isEqualTo(mailboxId); assertThat(message.getUid()).isEqualTo(createdMessage.getUid()); }); }
@Test void messageReIndexShouldCallMessageSearchIndex() throws Exception { MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME); MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get(); ComposedMessageId createdMessage = mailboxManager.getMailbox(INBOX, systemSession) .appendMessage( MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"), systemSession).getId(); reIndexer.reIndex(INBOX, createdMessage.getUid()).run(); ArgumentCaptor<MailboxMessage> messageCaptor = ArgumentCaptor.forClass(MailboxMessage.class); ArgumentCaptor<Mailbox> mailboxCaptor = ArgumentCaptor.forClass(Mailbox.class); verify(messageSearchIndex).add(any(MailboxSession.class), mailboxCaptor.capture(), messageCaptor.capture()); verifyNoMoreInteractions(messageSearchIndex); assertThat(mailboxCaptor.getValue()).satisfies(mailbox -> assertThat(mailbox.getMailboxId()).isEqualTo(mailboxId)); assertThat(messageCaptor.getValue()).satisfies(message -> { assertThat(message.getMailboxId()).isEqualTo(mailboxId); assertThat(message.getUid()).isEqualTo(createdMessage.getUid()); }); }
@Test void messageReIndexUsingMailboxIdShouldCallMessageSearchIndex() throws Exception { MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME); MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get(); ComposedMessageId createdMessage = mailboxManager.getMailbox(INBOX, systemSession) .appendMessage( MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"), systemSession).getId(); reIndexer.reIndex(mailboxId, createdMessage.getUid()).run(); ArgumentCaptor<MailboxMessage> messageCaptor = ArgumentCaptor.forClass(MailboxMessage.class); ArgumentCaptor<Mailbox> mailboxCaptor = ArgumentCaptor.forClass(Mailbox.class); verify(messageSearchIndex).add(any(MailboxSession.class), mailboxCaptor.capture(), messageCaptor.capture()); verifyNoMoreInteractions(messageSearchIndex); assertThat(mailboxCaptor.getValue()).satisfies(mailbox -> assertThat(mailbox.getMailboxId()).isEqualTo(mailboxId)); assertThat(messageCaptor.getValue()).satisfies(message -> { assertThat(message.getMailboxId()).isEqualTo(mailboxId); assertThat(message.getUid()).isEqualTo(createdMessage.getUid()); }); }
@Test void messageReIndexUsingMailboxIdShouldDoNothingWhenUidNotFound() throws Exception { MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME); MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get(); MessageUid uid = MessageUid.of(36); reIndexer.reIndex(mailboxId, uid).run(); verifyNoMoreInteractions(messageSearchIndex); }
@Test void messageReIndexUsingMailboxIdShouldFailWhenMailboxNotFound() { MailboxId mailboxId = InMemoryId.of(42); MessageUid uid = MessageUid.of(36); assertThatThrownBy(() -> reIndexer.reIndex(mailboxId, uid)) .isInstanceOf(MailboxNotFoundException.class); }
@Test void mailboxIdReIndexShouldCallMessageSearchIndex() throws Exception { MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME); MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get(); ComposedMessageId createdMessage = mailboxManager.getMailbox(INBOX, systemSession) .appendMessage( MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"), systemSession).getId(); reIndexer.reIndex(mailboxId, RunningOptions.DEFAULT).run(); ArgumentCaptor<MailboxMessage> messageCaptor = ArgumentCaptor.forClass(MailboxMessage.class); ArgumentCaptor<MailboxId> mailboxIdCaptor = ArgumentCaptor.forClass(MailboxId.class); ArgumentCaptor<Mailbox> mailboxCaptor = ArgumentCaptor.forClass(Mailbox.class); verify(messageSearchIndex).deleteAll(any(MailboxSession.class), mailboxIdCaptor.capture()); verify(messageSearchIndex).add(any(MailboxSession.class), mailboxCaptor.capture(), messageCaptor.capture()); verifyNoMoreInteractions(messageSearchIndex); assertThat(mailboxCaptor.getValue()).satisfies(mailbox -> assertThat(mailbox.getMailboxId()).isEqualTo(mailboxId)); assertThat(mailboxIdCaptor.getValue()).satisfies(capturedMailboxId -> assertThat(capturedMailboxId).isEqualTo(mailboxId)); assertThat(messageCaptor.getValue()).satisfies(message -> { assertThat(message.getMailboxId()).isEqualTo(mailboxId); assertThat(message.getUid()).isEqualTo(createdMessage.getUid()); }); }
@Test void mailboxIdReIndexShouldOnlyDropSearchIndexWhenEmptyMailbox() throws Exception { MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME); MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get(); reIndexer.reIndex(mailboxId, RunningOptions.DEFAULT).run(); ArgumentCaptor<MailboxId> mailboxCaptor = ArgumentCaptor.forClass(MailboxId.class); verify(messageSearchIndex).deleteAll(any(MailboxSession.class), mailboxCaptor.capture()); verifyNoMoreInteractions(messageSearchIndex); assertThat(mailboxCaptor.getValue()).satisfies(capturedMailboxId -> assertThat(capturedMailboxId).isEqualTo(mailboxId)); }
@Test void mailboxIdReIndexShouldFailWhenMailboxNotFound() { MailboxId mailboxId = InMemoryId.of(42); assertThatThrownBy(() -> reIndexer.reIndex(mailboxId, RunningOptions.DEFAULT)) .isInstanceOf(MailboxNotFoundException.class); }