use of org.apache.http.entity.BasicHttpEntity 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));
}
use of org.apache.http.entity.BasicHttpEntity 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());
}
use of org.apache.http.entity.BasicHttpEntity in project k-9 by k9mail.
the class WebDavStoreTest method createOkResponseWithForm.
private BasicHttpResponse createOkResponseWithForm() {
BasicHttpResponse okayResponseWithForm = createOkResponse();
BasicHttpEntity okayResponseWithFormEntity = new BasicHttpEntity();
String form = "<form action=\"owaauth.dll\"></form>";
okayResponseWithFormEntity.setContent(new ByteArrayInputStream(form.getBytes()));
okayResponseWithForm.setEntity(okayResponseWithFormEntity);
return okayResponseWithForm;
}
use of org.apache.http.entity.BasicHttpEntity in project TaEmCasa by Dionen.
the class HurlStack method entityFromConnection.
/**
* Initializes an {@link HttpEntity} from the given {@link HttpURLConnection}.
* @param connection
* @return an HttpEntity populated with data from <code>connection</code>.
*/
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
BasicHttpEntity entity = new BasicHttpEntity();
InputStream inputStream;
try {
inputStream = connection.getInputStream();
} catch (IOException ioe) {
inputStream = connection.getErrorStream();
}
entity.setContent(inputStream);
entity.setContentLength(connection.getContentLength());
entity.setContentEncoding(connection.getContentEncoding());
entity.setContentType(connection.getContentType());
return entity;
}
use of org.apache.http.entity.BasicHttpEntity in project SmartAndroidSource by jaychou2012.
the class HurlStack method entityFromConnection.
/**
* Initializes an {@link HttpEntity} from the given {@link HttpURLConnection}.
* @param connection
* @return an HttpEntity populated with data from <code>connection</code>.
*/
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
BasicHttpEntity entity = new BasicHttpEntity();
InputStream inputStream;
try {
inputStream = connection.getInputStream();
} catch (IOException ioe) {
inputStream = connection.getErrorStream();
}
entity.setContent(inputStream);
entity.setContentLength(connection.getContentLength());
entity.setContentEncoding(connection.getContentEncoding());
entity.setContentType(connection.getContentType());
return entity;
}
Aggregations