GetAnnotationCommandParser extends AbstractImapCommandParser { @Override protected ImapMessage decode(ImapRequestLineReader requestReader, Tag tag, ImapSession session) throws DecodingException { try { return buildAnnotationRequest(requestReader, tag); } catch (NullPointerException | IllegalArgumentException | IllegalStateException e) { throw new DecodingException(HumanReadableText.ILLEGAL_ARGUMENTS, e.getMessage(), e); } } GetAnnotationCommandParser(StatusResponseFactory statusResponseFactory);   }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowsExceptionWhenCommandHasNotMailbox() throws DecodingException { InputStream inputStream = new ByteArrayInputStream(" \n".getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test public void decodeMessageShouldReturnRequestWhenCommandHasMailboxOnly() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); GetAnnotationRequest request = (GetAnnotationRequest) parser.decode(lineReader, TAG, session); assertThat(request.getTag()).isEqualTo(TAG); assertThat(request.getCommand()).isEqualTo(ImapConstants.GETANNOTATION_COMMAND); assertThat(request.getMailboxName()).isEqualTo(INBOX); assertThat(request.getKeys()).isEmpty(); assertThat(request.getDepth()).isEqualTo(Depth.ZERO); assertThat(request.getMaxsize()).isEmpty(); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasOneKeyButInWrongFormat() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " /private/comment extrastring \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test public void decodeMessageShouldReturnRequestWhenCommandHasOnlyOneKey() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " /private/comment \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); GetAnnotationRequest request = (GetAnnotationRequest) parser.decode(lineReader, TAG, session); assertThat(request.getTag()).isEqualTo(TAG); assertThat(request.getCommand()).isEqualTo(ImapConstants.GETANNOTATION_COMMAND); assertThat(request.getMailboxName()).isEqualTo(INBOX); assertThat(request.getKeys()).containsOnly(PRIVATE_KEY); assertThat(request.getDepth()).isEqualTo(Depth.ZERO); assertThat(request.getMaxsize()).isEmpty(); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasOneInvalidKey() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + "/shared/comment private/comment \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test public void decodeMessageShouldReturnRequestWhenCommandHasMultiKeys() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); GetAnnotationRequest request = (GetAnnotationRequest) parser.decode(lineReader, TAG, session); assertThat(request.getTag()).isEqualTo(TAG); assertThat(request.getCommand()).isEqualTo(ImapConstants.GETANNOTATION_COMMAND); assertThat(request.getMailboxName()).isEqualTo(INBOX); assertThat(request.getKeys()).contains(PRIVATE_KEY, SHARED_KEY); assertThat(request.getDepth()).isEqualTo(Depth.ZERO); assertThat(request.getMaxsize()).isEmpty(); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasMultiKeysButInWrongFormat() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (/shared/comment /private/comment) (/another/key/group)\n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasMultiKeysAndSingleKey() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (/shared/comment /private/comment) /another/key \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasMultiKeysButNotOpenQuote() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " /shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasMultiKeysButNotCloseQuote() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (/shared/comment /private/comment \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasMaxsizeOptButInWrongPlace() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (/shared/comment /private/comment) (MAXSIZE 1024) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasMaxsizeWithWrongValue() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (MAXSIZE invalid) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasMaxsizeWithoutValue() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (MAXSIZE) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasMaxsizeDoesNotInParenthesis() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " MAXSIZE 1024 (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasMaxsizeDoesNotInParenthesisAndNoValue() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " MAXSIZE (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test public void decodeMessageShouldReturnRequestWhenCommandHasMaxsizeOption() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (MAXSIZE 1024) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); GetAnnotationRequest request = (GetAnnotationRequest) parser.decode(lineReader, TAG, session); assertThat(request.getTag()).isEqualTo(TAG); assertThat(request.getCommand()).isEqualTo(ImapConstants.GETANNOTATION_COMMAND); assertThat(request.getMailboxName()).isEqualTo(INBOX); assertThat(request.getKeys()).contains(PRIVATE_KEY, SHARED_KEY); assertThat(request.getDepth()).isEqualTo(Depth.ZERO); assertThat(request.getMaxsize()).contains(1024); }
@Test(expected = DecodingException.class) public void decodeMessageShouldReturnRequestWhenCommandHasWrongMaxsizeOption() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (MAXSIZErr 1024) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldReturnRequestWhenCommandHasWrongMaxsizeValue() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (MAXSIZE 0) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldReturnRequestWhenCommandHasWrongDepthOption() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (DEPTH -1) (MAXSIZE 1024) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldReturnRequestWhenCommandHasWrongDepthOptionName() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (DEPTHerr 1) (MAXSIZE 1024) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldReturnRequestWhenCommandHasDepthOptionButNoValue() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (DEPTH) (MAXSIZE 1024) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldReturnRequestWhenCommandHasDepthOptionButInvalidValue() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (DEPTH invalid) (MAXSIZE 1024) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldReturnRequestWhenCommandHasDepthOptionButNotInParenthesis() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " DEPTH (MAXSIZE 1024) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldReturnRequestWhenCommandHasDepthOptionAndValueButNotInParenthesis() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " DEPTH 1 (MAXSIZE 1024) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test public void decodeMessageShouldReturnRequestWithZeroDepthOption() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (DEPTH 0) (MAXSIZE 1024) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); GetAnnotationRequest request = (GetAnnotationRequest)parser.decode(lineReader, TAG, null); assertThat(request.getTag()).isEqualTo(TAG); assertThat(request.getCommand()).isEqualTo(ImapConstants.GETANNOTATION_COMMAND); assertThat(request.getMailboxName()).isEqualTo(INBOX); assertThat(request.getDepth()).isEqualTo(Depth.ZERO); assertThat(request.getMaxsize()).contains(1024); assertThat(request.getKeys()).contains(SHARED_KEY, PRIVATE_KEY); }
@Test public void decodeMessageShouldReturnRequestWithOneDepthOption() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (DEPTH 1) (MAXSIZE 1024) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); GetAnnotationRequest request = (GetAnnotationRequest)parser.decode(lineReader, TAG, session); assertThat(request.getTag()).isEqualTo(TAG); assertThat(request.getCommand()).isEqualTo(ImapConstants.GETANNOTATION_COMMAND); assertThat(request.getMailboxName()).isEqualTo(INBOX); assertThat(request.getDepth()).isEqualTo(Depth.ONE); assertThat(request.getMaxsize()).contains(1024); assertThat(request.getKeys()).contains(SHARED_KEY, PRIVATE_KEY); }
@Test public void decodeMessageShouldReturnRequestWhenCommandHasOptionsInAnyOrder() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (MAXSIZE 1024) (DEPTH 1) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); GetAnnotationRequest request = (GetAnnotationRequest)parser.decode(lineReader, TAG, session); assertThat(request.getTag()).isEqualTo(TAG); assertThat(request.getCommand()).isEqualTo(ImapConstants.GETANNOTATION_COMMAND); assertThat(request.getMailboxName()).isEqualTo(INBOX); assertThat(request.getDepth()).isEqualTo(Depth.ONE); assertThat(request.getMaxsize()).contains(1024); assertThat(request.getKeys()).contains(SHARED_KEY, PRIVATE_KEY); }
@Test public void decodeMessageShouldReturnRequestWithInfinityDepthOption() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (DEPTH infinity) (MAXSIZE 1024) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); GetAnnotationRequest request = (GetAnnotationRequest)parser.decode(lineReader, TAG, session); assertThat(request.getTag()).isEqualTo(TAG); assertThat(request.getCommand()).isEqualTo(ImapConstants.GETANNOTATION_COMMAND); assertThat(request.getMailboxName()).isEqualTo(INBOX); assertThat(request.getDepth()).isEqualTo(Depth.INFINITY); assertThat(request.getMaxsize()).contains(1024); assertThat(request.getKeys()).contains(SHARED_KEY, PRIVATE_KEY); }
@Test public void decodeMessageShouldReturnRequestWithOnlyInfinityDepthOption() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (DEPTH infinity) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); GetAnnotationRequest request = (GetAnnotationRequest)parser.decode(lineReader, TAG, session); assertThat(request.getTag()).isEqualTo(TAG); assertThat(request.getCommand()).isEqualTo(ImapConstants.GETANNOTATION_COMMAND); assertThat(request.getMailboxName()).isEqualTo(INBOX); assertThat(request.getDepth()).isEqualTo(Depth.INFINITY); assertThat(request.getMaxsize()).isEmpty(); assertThat(request.getKeys()).contains(SHARED_KEY, PRIVATE_KEY); }
@Test public void decodeMessageShouldReturnRequestWithDefaultDepthOptionWhenCommandHasDoesNotHaveDepthOption() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (MAXSIZE 1024) (/shared/comment /private/comment) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); GetAnnotationRequest request = (GetAnnotationRequest)parser.decode(lineReader, TAG, session); assertThat(request.getTag()).isEqualTo(TAG); assertThat(request.getCommand()).isEqualTo(ImapConstants.GETANNOTATION_COMMAND); assertThat(request.getMailboxName()).isEqualTo(INBOX); assertThat(request.getDepth()).isEqualTo(Depth.ZERO); assertThat(request.getMaxsize()).contains(1024); assertThat(request.getKeys()).contains(SHARED_KEY, PRIVATE_KEY); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasOneDepthButWithoutKey() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (DEPTH 1) (MAXSIZE 1024) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasInfinityDepthButWithoutKey() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (DEPTH infinity) (MAXSIZE 1024) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }
@Test(expected = DecodingException.class) public void decodeMessageShouldThrowExceptionWhenCommandHasDepthOptionInWrongPlace() throws DecodingException { InputStream inputStream = new ByteArrayInputStream((INBOX + " (/shared/comment /private/comment) (DEPTH infinity) \n").getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); parser.decode(lineReader, TAG, session); }