private List<MailboxAnnotation> getMailboxAnnotationsWithDepthZero(Set<MailboxAnnotationKey> keys, MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException { if (keys.isEmpty()) { return getMailboxManager().getAllAnnotations(mailboxPath, mailboxSession); } else { return getMailboxManager().getAnnotationsByKeys(mailboxPath, mailboxSession, keys); } }
@Test public void processShouldResponseNoWithGenericFailureWhenManagerThrowMailboxException() throws Exception { doThrow(MailboxException.class).when(mockMailboxManager).getAllAnnotations(eq(inbox), eq(mailboxSession)); when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class))) .thenReturn(statusResponse); processor.process(annotationRequestBuilder.build(), mockResponder, mockImapSession); verify(mockStatusResponseFactory, times(1)).taggedNo(any(String.class), any(ImapCommand.class), humanTextCaptor.capture()); verify(mockResponder).respond(statusResponse); verifyNoMoreInteractions(mockResponder); assertThat(humanTextCaptor.getAllValues()).containsOnly(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); }
@Test public void processShouldGetAnnotationsAndReturnCompleteResponseDoesNotTruncateDataByMaxsize() throws Exception { when(mockMailboxManager.getAllAnnotations(inbox, mailboxSession)).thenReturn(ImmutableList.of(PRIVATE_ANNOTATION, SHARED_ANNOTATION)); processor.process(annotationRequestBuilder.maxsize(Optional.of(100)).build(), mockResponder, mockImapSession); verify(mockStatusResponseFactory, times(1)).taggedOk(any(String.class), any(ImapCommand.class), humanTextCaptor.capture()); verify(mockResponder, times(2)).respond(captorAnnotationResponse.capture()); verifyNoMoreInteractions(mockResponder); assertThat(humanTextCaptor.getAllValues()).containsOnly(HumanReadableText.COMPLETED); }
@Test public void processShouldGetAnnotationsAndReturnCompleteResponseWithTruncateDataByLessThenOrEqualMaxsize() throws Exception { when(mockMailboxManager.getAllAnnotations(inbox, mailboxSession)).thenReturn(ImmutableList.of(PRIVATE_ANNOTATION, SHARED_ANNOTATION)); processor.process(annotationRequestBuilder.maxsize(Optional.of(15)).build(), mockResponder, mockImapSession); verify(mockMailboxManager, times(1)).getAllAnnotations(eq(inbox), eq(mailboxSession)); verify(mockStatusResponseFactory, times(1)).taggedOk(any(String.class), any(ImapCommand.class), humanTextCaptor.capture()); verify(mockResponder, times(2)).respond(captorAnnotationResponse.capture()); verifyNoMoreInteractions(mockResponder); AnnotationResponse resultAnnotation = captorAnnotationResponse.getAllValues().get(FIRST_ELEMENT_INDEX); assertThat(resultAnnotation.getMailboxAnnotations()).contains(PRIVATE_ANNOTATION, SHARED_ANNOTATION); }
@Test public void processShouldResponseNoWithFailureWhenMailboxDoesNotExist() throws Exception { doThrow(MailboxNotFoundException.class).when(mockMailboxManager).getAllAnnotations(eq(inbox), eq(mailboxSession)); when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(ResponseCode.class))) .thenReturn(statusResponse); processor.process(annotationRequestBuilder.build(), mockResponder, mockImapSession); verify(mockStatusResponseFactory, times(1)).taggedNo(any(String.class), any(ImapCommand.class), humanTextCaptor.capture(), captorResponsecode.capture()); verify(mockResponder).respond(statusResponse); verifyNoMoreInteractions(mockResponder); assertThat(humanTextCaptor.getAllValues()).containsOnly(HumanReadableText.FAILURE_NO_SUCH_MAILBOX); assertThat(captorResponsecode.getAllValues()).containsOnly(ResponseCode.tryCreate()); }
@Test public void processShouldGetAllAnnotationsAndReturnCompleteResponse() throws Exception { processor.process(annotationRequestBuilder.build(), mockResponder, mockImapSession); verify(mockMailboxManager, times(1)).getAllAnnotations(inbox, mailboxSession); verify(mockStatusResponseFactory, times(1)).taggedOk(any(String.class), any(ImapCommand.class), humanTextCaptor.capture()); verify(mockResponder, times(2)).respond(captorAnnotationResponse.capture()); verifyNoMoreInteractions(mockResponder); assertThat(humanTextCaptor.getAllValues()).containsOnly(HumanReadableText.COMPLETED); }
@Test public void processShouldGetAnnotationsAndReturnCompleteResponseDoesnotTruncateDataByMaxsizeWhenNoMoreOverSizeItem() throws Exception { when(mockMailboxManager.getAllAnnotations(inbox, mailboxSession)).thenReturn(ImmutableList.of(SHARED_ANNOTATION, PRIVATE_ANNOTATION, PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION)); processor.process(annotationRequestBuilder.maxsize(Optional.of(100)).build(), mockResponder, mockImapSession); verify(mockStatusResponseFactory, times(1)).taggedOk(any(String.class), any(ImapCommand.class), humanTextCaptor.capture()); verify(mockResponder, times(2)).respond(captorAnnotationResponse.capture()); verifyNoMoreInteractions(mockResponder); AnnotationResponse resultAnnotation = captorAnnotationResponse.getAllValues().get(FIRST_ELEMENT_INDEX); assertThat(resultAnnotation.getMailboxAnnotations()).contains(PRIVATE_ANNOTATION, SHARED_ANNOTATION, PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION); }
@Test public void processShouldGetAnnotationsAndReturnCompleteResponseWithTruncateDataByMaxsize() throws Exception { when(mockMailboxManager.getAllAnnotations(inbox, mailboxSession)).thenReturn(ImmutableList.of(SHARED_ANNOTATION, PRIVATE_ANNOTATION, PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION)); processor.process(annotationRequestBuilder.maxsize(Optional.of(15)).build(), mockResponder, mockImapSession); verify(mockStatusResponseFactory, times(1)).taggedOk(any(String.class), any(ImapCommand.class), humanTextCaptor.capture(), any(ResponseCode.class)); verify(mockResponder, times(2)).respond(captorAnnotationResponse.capture()); verifyNoMoreInteractions(mockResponder); AnnotationResponse resultAnnotation = captorAnnotationResponse.getAllValues().get(FIRST_ELEMENT_INDEX); assertThat(resultAnnotation.getMailboxAnnotations()).contains(PRIVATE_ANNOTATION, SHARED_ANNOTATION); }
@Test public void processShouldGetAnnotationsAndReturnCompleteResponseWithTheLongestEntryInfoWhenLimitMaxsize() throws Exception { when(mockMailboxManager.getAllAnnotations(inbox, mailboxSession)).thenReturn(ImmutableList.of(PRIVATE_ANNOTATION, SHARED_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION)); processor.process(annotationRequestBuilder.maxsize(Optional.of(10)).build(), mockResponder, mockImapSession); verify(mockStatusResponseFactory, times(1)).taggedOk(any(String.class), any(ImapCommand.class), humanTextCaptor.capture(), captorResponsecode.capture()); verify(mockResponder, times(2)).respond(captorAnnotationResponse.capture()); verifyNoMoreInteractions(mockResponder); assertThat(humanTextCaptor.getAllValues()).containsOnly(HumanReadableText.COMPLETED); assertThat(captorResponsecode.getAllValues()).containsOnly(ResponseCode.longestMetadataEntry(22)); }