Search in sources :

Example 11 with WebDavMessage

use of com.fsck.k9.mail.store.webdav.WebDavMessage in project k-9 by k9mail.

the class WebDavFolderTest method folder_can_fetch_more_than_10_envelopes.

@Test
public void folder_can_fetch_more_than_10_envelopes() throws MessagingException {
    when(mockStore.processRequest(anyString(), anyString(), anyString(), anyMap())).thenReturn(mockDataSet);
    List<WebDavMessage> messages = new ArrayList<>();
    for (int i = 0; i < 15; i++) {
        WebDavMessage mockMessage = createWebDavMessage(i);
        messages.add(mockMessage);
    }
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.ENVELOPE);
    folder.fetch(messages, profile, listener, MAX_DOWNLOAD_SIZE);
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with WebDavMessage

use of com.fsck.k9.mail.store.webdav.WebDavMessage in project k-9 by k9mail.

the class WebDavFolderTest method appendWebDavMessages_replaces_messages_with_WebDAV_versions.

@Test
public void appendWebDavMessages_replaces_messages_with_WebDAV_versions() throws MessagingException, IOException {
    List<Message> existingMessages = new ArrayList<>();
    Message existingMessage = mock(Message.class);
    existingMessages.add(existingMessage);
    String messageUid = "testMessageUid";
    when(existingMessage.getUid()).thenReturn(messageUid);
    List<WebDavMessage> response = folder.appendWebDavMessages(existingMessages);
    assertEquals(1, response.size(), 1);
    assertEquals(WebDavMessage.class, response.get(0).getClass());
    assertEquals(messageUid, response.get(0).getUid());
}
Also used : Message(com.fsck.k9.mail.Message) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 13 with WebDavMessage

use of com.fsck.k9.mail.store.webdav.WebDavMessage in project k-9 by k9mail.

the class WebDavFolderTest method folder_can_fetch_less_than_20_flags.

@Test
public void folder_can_fetch_less_than_20_flags() throws MessagingException {
    when(mockStore.processRequest(anyString(), anyString(), anyString(), anyMap())).thenReturn(mockDataSet);
    List<WebDavMessage> messages = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        WebDavMessage mockMessage = createWebDavMessage(i);
        messages.add(mockMessage);
    }
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.FLAGS);
    folder.fetch(messages, profile, listener, MAX_DOWNLOAD_SIZE);
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with WebDavMessage

use of com.fsck.k9.mail.store.webdav.WebDavMessage in project k-9 by k9mail.

the class WebDavFolderTest method folder_ignores_exception_thrown_when_closing.

@Test
public void folder_ignores_exception_thrown_when_closing() throws MessagingException, IOException {
    setupStoreForMessageFetching();
    List<WebDavMessage> messages = setup25MessagesToFetch();
    when(mockHttpClient.executeOverride(any(HttpUriRequest.class), nullable(HttpContext.class))).thenAnswer(new Answer<HttpResponse>() {

        @Override
        public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
            HttpResponse httpResponse = mock(HttpResponse.class);
            StatusLine statusLine = mock(StatusLine.class);
            when(httpResponse.getStatusLine()).thenReturn(statusLine);
            when(statusLine.getStatusCode()).thenReturn(200);
            BasicHttpEntity httpEntity = new BasicHttpEntity();
            InputStream mockInputStream = mock(InputStream.class);
            when(mockInputStream.read(any(byte[].class), anyInt(), anyInt())).thenReturn(1).thenReturn(-1);
            doThrow(new IOException("Test")).when(mockInputStream).close();
            httpEntity.setContent(mockInputStream);
            when(httpResponse.getEntity()).thenReturn(httpEntity);
            return httpResponse;
        }
    });
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.BODY_SANE);
    folder.fetch(messages, profile, listener, MAX_DOWNLOAD_SIZE);
    verify(listener, times(25)).messageStarted(any(String.class), anyInt(), eq(25));
    verify(listener, times(25)).messageFinished(any(WebDavMessage.class), anyInt(), eq(25));
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) FetchProfile(com.fsck.k9.mail.FetchProfile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) IOException(java.io.IOException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatusLine(org.apache.http.StatusLine) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 15 with WebDavMessage

use of com.fsck.k9.mail.store.webdav.WebDavMessage in project k-9 by k9mail.

the class WebDavFolderTest method folder_does_not_notify_listener_twice_when_fetching_flags_and_bodies.

@Test
public void folder_does_not_notify_listener_twice_when_fetching_flags_and_bodies() throws MessagingException, IOException, URISyntaxException {
    setupStoreForMessageFetching();
    when(mockStore.processRequest(anyString(), anyString(), anyString(), anyMap())).thenReturn(mockDataSet);
    List<WebDavMessage> messages = setup25MessagesToFetch();
    when(mockHttpClient.executeOverride(any(HttpUriRequest.class), nullable(HttpContext.class))).thenAnswer(new Answer<HttpResponse>() {

        @Override
        public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
            HttpResponse httpResponse = mock(HttpResponse.class);
            StatusLine statusLine = mock(StatusLine.class);
            when(httpResponse.getStatusLine()).thenReturn(statusLine);
            when(statusLine.getStatusCode()).thenReturn(200);
            BasicHttpEntity httpEntity = new BasicHttpEntity();
            String body = "";
            httpEntity.setContent(new ByteArrayInputStream(body.getBytes("UTF-8")));
            when(httpResponse.getEntity()).thenReturn(httpEntity);
            return httpResponse;
        }
    });
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.FLAGS);
    profile.add(FetchProfile.Item.BODY);
    folder.fetch(messages, profile, listener, MAX_DOWNLOAD_SIZE);
    verify(listener, times(25)).messageStarted(any(String.class), anyInt(), anyInt());
    verify(listener, times(25)).messageFinished(any(WebDavMessage.class), anyInt(), anyInt());
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) FetchProfile(com.fsck.k9.mail.FetchProfile) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatusLine(org.apache.http.StatusLine) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Aggregations

FetchProfile (com.fsck.k9.mail.FetchProfile)11 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)9 WebDavMessage (com.fsck.k9.mail.store.webdav.WebDavMessage)7 HttpResponse (org.apache.http.HttpResponse)7 MessagingException (com.fsck.k9.mail.MessagingException)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 StatusLine (org.apache.http.StatusLine)4 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)4 HttpContext (org.apache.http.protocol.HttpContext)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Message (com.fsck.k9.mail.Message)3 WebDavFolder (com.fsck.k9.mail.store.webdav.WebDavFolder)3 URISyntaxException (java.net.URISyntaxException)3 Date (java.util.Date)3 BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)3 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)2 Flag (com.fsck.k9.mail.Flag)2