@Override public void update(MailboxSession session, Mailbox mailbox, List<UpdatedFlags> updatedFlagsList) throws MailboxException { try { elasticSearchIndexer.update(updatedFlagsList.stream() .map(updatedFlags -> createUpdatedDocumentPartFromUpdatedFlags(mailbox, updatedFlags)) .collect(Collectors.toList())); } catch (Exception e) { LOGGER.error("Error when updating index on mailbox {}", mailbox.getMailboxId().serialize(), e); } }
@Test public void updateShouldWork() throws Exception { //Given Mailbox mailbox = mock(Mailbox.class); Flags flags = new Flags(); UpdatedFlags updatedFlags = UpdatedFlags.builder() .uid(MESSAGE_UID) .modSeq(MODSEQ) .oldFlags(flags) .newFlags(flags) .build(); when(mailbox.getMailboxId()) .thenReturn(MAILBOX_ID); when(messageToElasticSearchJson.getUpdatedJsonMessagePart(any(Flags.class), any(Long.class))) .thenReturn("json updated content"); //When testee.update(session, mailbox, Lists.newArrayList(updatedFlags)); //Then ImmutableList<UpdatedRepresentation> expectedUpdatedRepresentations = ImmutableList.of(new UpdatedRepresentation(ELASTIC_SEARCH_ID, "json updated content")); verify(elasticSearchIndexer).update(expectedUpdatedRepresentations); }
@Test public void updateShouldNotPropagateExceptionWhenExceptionOccurs() throws Exception { //Given Mailbox mailbox = mock(Mailbox.class); Flags flags = new Flags(); UpdatedFlags updatedFlags = UpdatedFlags.builder() .uid(MESSAGE_UID) .modSeq(MODSEQ) .oldFlags(flags) .newFlags(flags) .build(); when(mailbox.getMailboxId()) .thenReturn(MAILBOX_ID); ImmutableList<UpdatedRepresentation> expectedUpdatedRepresentations = ImmutableList.of(new UpdatedRepresentation(ELASTIC_SEARCH_ID, "json updated content")); when(elasticSearchIndexer.update(expectedUpdatedRepresentations)) .thenThrow(new ElasticsearchException("")); //When testee.update(session, mailbox, Lists.newArrayList(updatedFlags)); //Then //No exception }