MessageFastViewFactory implements MessageViewFactory<MessageFastView> { @Override public Flux<MessageFastView> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession) { ImmutableSet<MessageId> messageIdSet = ImmutableSet.copyOf(messageIds); return Mono.from(fastViewProjection.retrieve(messageIds)) .flatMapMany(fastProjections -> gatherMessageViews(messageIdSet, mailboxSession, fastProjections)); } @Inject @VisibleForTesting  MessageFastViewFactory(BlobManager blobManager, MessageIdManager messageIdManager, MessageFastViewProjection fastViewProjection,
                                  MessageFullViewFactory messageFullViewFactory); @Override Flux<MessageFastView> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession);  }
@Test void fromMessageIdsShouldReturnAMessageWithComputedFastProperties() throws Exception { MessageFastView actual = messageFastViewFactory.fromMessageIds(ImmutableList.of(previewComputedMessage1.getMessageId()), session).collectList().block().get(0); SoftAssertions.assertSoftly(softly -> { softly.assertThat(actual.getId()).isEqualTo(previewComputedMessage1.getMessageId()); softly.assertThat(actual.getMailboxIds()).containsExactly(bobInbox.getId()); softly.assertThat(actual.getThreadId()).isEqualTo(previewComputedMessage1.getMessageId().serialize()); softly.assertThat(actual.getSize()).isEqualTo(Number.fromLong(2255)); softly.assertThat(actual.getKeywords()).isEqualTo(Keywords.strictFactory().from(Keyword.SEEN).asMap()); softly.assertThat(actual.getBlobId()).isEqualTo(BlobId.of(previewComputedMessage1.getMessageId().serialize())); softly.assertThat(actual.getInReplyToMessageId()).isEqualTo(Optional.of(BOB.asString())); softly.assertThat(actual.getHeaders()).isEqualTo(HEADERS_MAP); softly.assertThat(actual.getFrom()).isEqualTo(Optional.of(ALICE_EMAIL)); softly.assertThat(actual.getTo()).isEqualTo(ImmutableList.of(BOB_EMAIL)); softly.assertThat(actual.getCc()).isEqualTo(ImmutableList.of(JACK_EMAIL, JACOB_EMAIL)); softly.assertThat(actual.getBcc()).isEqualTo(ImmutableList.of(ALICE_EMAIL)); softly.assertThat(actual.getReplyTo()).isEqualTo(ImmutableList.of(ALICE_EMAIL)); softly.assertThat(actual.getSubject()).isEqualTo("Full message"); softly.assertThat(actual.getDate()).isEqualTo("2016-06-07T14:23:37Z"); softly.assertThat(actual.isHasAttachment()).isTrue(); softly.assertThat(actual.getPreview()).isEqualTo(PreviewDTO.of(PREVIEW_1_STRING)); }); }
@Test void fromMessageIdsShouldReturnAMessageWithPropertiesComputedFromFullMessageWhenNotPreComputed() throws Exception { MessageFastView actual = messageFastViewFactory.fromMessageIds(ImmutableList.of(missingPreviewComputedMessage1.getMessageId()), session).collectList().block().get(0); SoftAssertions.assertSoftly(softly -> { softly.assertThat(actual.getId()).isEqualTo(missingPreviewComputedMessage1.getMessageId()); softly.assertThat(actual.getMailboxIds()).containsExactly(bobInbox.getId()); softly.assertThat(actual.getThreadId()).isEqualTo(missingPreviewComputedMessage1.getMessageId().serialize()); softly.assertThat(actual.getSize()).isEqualTo(Number.fromLong(2255)); softly.assertThat(actual.getKeywords()).isEqualTo(Keywords.strictFactory().from(Keyword.SEEN).asMap()); softly.assertThat(actual.getBlobId()).isEqualTo(BlobId.of(missingPreviewComputedMessage1.getMessageId().serialize())); softly.assertThat(actual.getInReplyToMessageId()).isEqualTo(Optional.of(BOB.asString())); softly.assertThat(actual.getHeaders()).isEqualTo(HEADERS_MAP); softly.assertThat(actual.getFrom()).isEqualTo(Optional.of(ALICE_EMAIL)); softly.assertThat(actual.getTo()).isEqualTo(ImmutableList.of(BOB_EMAIL)); softly.assertThat(actual.getCc()).isEqualTo(ImmutableList.of(JACK_EMAIL, JACOB_EMAIL)); softly.assertThat(actual.getBcc()).isEqualTo(ImmutableList.of(ALICE_EMAIL)); softly.assertThat(actual.getReplyTo()).isEqualTo(ImmutableList.of(ALICE_EMAIL)); softly.assertThat(actual.getSubject()).isEqualTo("Full message"); softly.assertThat(actual.getDate()).isEqualTo("2016-06-07T14:23:37Z"); softly.assertThat(actual.isHasAttachment()).isTrue(); softly.assertThat(actual.getPreview()).isEqualTo(PreviewDTO.of(DEFAULT_PREVIEW_STRING)); }); }
@Test void fromMessageIdsShouldReturnMessagesWithPreviews() throws Exception { List<MessageFastView> actual = messageFastViewFactory .fromMessageIds(ImmutableList.of( previewComputedMessage2.getMessageId(), previewComputedMessage3.getMessageId(), missingPreviewComputedMessage1.getMessageId(), previewComputedMessage1.getMessageId()), session).collectList().block(); assertThat(actual) .hasSize(4) .extracting(MessageFastView::getPreview) .containsOnly( PreviewDTO.of(PREVIEW_3_STRING), PreviewDTO.of(PREVIEW_4_STRING), PreviewDTO.of(DEFAULT_PREVIEW_STRING), PreviewDTO.of(PREVIEW_1_STRING)); }
@Test void fromMessageIdsShouldKeepProcessingEvenWhenFetchingFail() { doReturn(Flux.error(new MailboxException("mock exception"))) .doCallRealMethod() .when(messageIdManager).getMessagesReactive(any(), any(), any()); List<MessageFastView> actual = messageFastViewFactory .fromMessageIds(ImmutableList.of( missingPreviewComputedMessage1.getMessageId(), previewComputedMessage1.getMessageId()), session) .collectList().block(); assertThat(actual) .hasSize(1) .extracting(MessageFastView::getId) .containsAnyOf(missingPreviewComputedMessage1.getMessageId(), previewComputedMessage1.getMessageId()); }