@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 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 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 processShouldGetAnnotationsByOneDepthAndReturnCompleteResponseWithTruncateDataByMaxsize() throws Exception { when(mockMailboxManager.getAnnotationsByKeysWithOneDepth(inbox, mailboxSession, keys)).thenReturn(ImmutableList.of(PRIVATE_ANNOTATION, PRIVATE_CHILD_ANNOTATION)); processor.process(annotationRequestBuilder.maxsize(Optional.of(14)).depth(Depth.ONE).keys(keys).build(), mockResponder, mockImapSession); verify(mockMailboxManager, times(1)).getAnnotationsByKeysWithOneDepth(eq(inbox), eq(mailboxSession), eq(keys)); 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); }
@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 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)); }
@Test public void processShouldGetAnnotationsByInfinityDepthAndReturnCompleteResponseWithTruncateDataByMaxsize() throws Exception { when(mockMailboxManager.getAnnotationsByKeysWithAllDepth(inbox, mailboxSession, keys)).thenReturn(ImmutableList.of(PRIVATE_ANNOTATION, PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION)); processor.process(annotationRequestBuilder.maxsize(Optional.of(14)).depth(Depth.INFINITY).keys(keys).build(), mockResponder, mockImapSession); verify(mockMailboxManager, times(1)).getAnnotationsByKeysWithAllDepth(eq(inbox), eq(mailboxSession), eq(keys)); 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); }
@Test public void processShouldGetAnnotationsByKeysAndReturnCompleteResponse() throws Exception { processor.process(annotationRequestBuilder.keys(keys).build(), mockResponder, mockImapSession); verify(mockMailboxManager, times(1)).getAnnotationsByKeys(eq(inbox), eq(mailboxSession), eq(keys)); 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); }
private ImapMessage buildAnnotationRequest(ImapCommand command, ImapRequestLineReader requestReader, String tag) throws DecodingException { GetAnnotationRequest.Builder builder = GetAnnotationRequest.builder().tag(tag).command(command); builder.mailboxName(requestReader.mailbox()); consumeOptionsAndKeys(requestReader, builder); if (ENDOFLINE_PATTERN.matches(requestReader.nextNonSpaceChar())) { consumeKey(requestReader, builder); } return builder.build(); }
@Test public void processShouldGetAnnotationsByInfinityDepthAndReturnCompleteResponse() throws Exception { when(mockMailboxManager.getAnnotationsByKeysWithAllDepth(inbox, mailboxSession, keys)).thenReturn(ImmutableList.of(PRIVATE_ANNOTATION, PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION)); processor.process(annotationRequestBuilder.depth(Depth.INFINITY).keys(keys).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, PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION); }
@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 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); }