use of org.apache.http.client.HttpClient in project nhin-d by DirectProject.
the class UnsecureServiceRequestBase_callTest method testCall_nullRequest_assertServiceException.
@Test
public void testCall_nullRequest_assertServiceException() throws Exception {
HttpClient mockClient = mock(HttpClient.class);
StatusLine statLine = mock(StatusLine.class);
when(statLine.getStatusCode()).thenReturn(204);
HttpResponse resp = mock(HttpResponse.class);
when(resp.getStatusLine()).thenReturn(statLine);
when(mockClient.execute((HttpUriRequest) any())).thenReturn(resp);
MockServiceRequest req = new MockServiceRequest(mockClient, "http://service/svc", "");
boolean exceptionOccured = false;
try {
req.call();
} catch (ServiceException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.apache.http.client.HttpClient in project android_frameworks_base by DirtyUnicorns.
the class AbstractProxyTest method testParamPreferredOverSystemProperty.
private void testParamPreferredOverSystemProperty(ProxyConfig proxyConfig) throws Exception {
server.enqueue(new MockResponse().setBody("Via request parameter proxy!"));
server.play();
System.setProperty("http.proxyHost", "proxy.foo");
System.setProperty("http.proxyPort", "8080");
HttpClient client = newHttpClient();
HttpGet request = new HttpGet("http://origin.foo/bar");
proxyConfig.configure(server, client, request);
HttpResponse response = client.execute(request);
assertEquals("Via request parameter proxy!", contentToString(response));
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("GET http://origin.foo/bar HTTP/1.1", recordedRequest.getRequestLine());
}
use of org.apache.http.client.HttpClient in project android_frameworks_base by DirtyUnicorns.
the class CookiesTest method testCookiesWithNonMatchingCase.
/**
* Test that cookies aren't case-sensitive with respect to hostname.
* http://b/3167208
*/
public void testCookiesWithNonMatchingCase() throws Exception {
// use a proxy so we can manipulate the origin server's host name
server = new MockWebServer();
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=first; Domain=my.t-mobile.com").addHeader("Set-Cookie: b=second; Domain=.T-mobile.com").addHeader("Set-Cookie: c=third; Domain=.t-mobile.com").setBody("This response sets some cookies."));
server.enqueue(new MockResponse().setBody("This response gets those cookies back."));
server.play();
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost("localhost", server.getPort()));
HttpResponse getCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
getCookies.getEntity().consumeContent();
server.takeRequest();
HttpResponse sendCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
sendCookies.getEntity().consumeContent();
RecordedRequest sendCookiesRequest = server.takeRequest();
assertContains(sendCookiesRequest.getHeaders(), "Cookie: a=first; b=second; c=third");
}
use of org.apache.http.client.HttpClient in project android_frameworks_base by ParanoidAndroid.
the class BandwidthTestUtil method postFileToServer.
/**
* Post a given file for a given device and timestamp to the server.
* @param server {@link String} url of test server
* @param deviceId {@link String} device id that is uploading
* @param timestamp {@link String} timestamp
* @param file {@link File} to upload
* @return true if it succeeded
*/
public static boolean postFileToServer(String server, String deviceId, String timestamp, File file) {
try {
Log.d(LOG_TAG, "Uploading begining");
HttpClient httpClient = new DefaultHttpClient();
String uri = server;
if (!uri.endsWith("/")) {
uri += "/";
}
uri += "upload";
Log.d(LOG_TAG, "Upload url:" + uri);
HttpPost postRequest = new HttpPost(uri);
Part[] parts = { new StringPart("device_id", deviceId), new StringPart("timestamp", timestamp), new FilePart("file", file) };
MultipartEntity reqEntity = new MultipartEntity(parts, postRequest.getParams());
postRequest.setEntity(reqEntity);
HttpResponse res = httpClient.execute(postRequest);
res.getEntity().getContent().close();
} catch (IOException e) {
Log.e(LOG_TAG, "Could not upload file with error: " + e);
return false;
}
return true;
}
use of org.apache.http.client.HttpClient in project android_frameworks_base by AOSPA.
the class CookiesTest method testCookiesWithNonMatchingCase.
/**
* Test that cookies aren't case-sensitive with respect to hostname.
* http://b/3167208
*/
public void testCookiesWithNonMatchingCase() throws Exception {
// use a proxy so we can manipulate the origin server's host name
server = new MockWebServer();
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=first; Domain=my.t-mobile.com").addHeader("Set-Cookie: b=second; Domain=.T-mobile.com").addHeader("Set-Cookie: c=third; Domain=.t-mobile.com").setBody("This response sets some cookies."));
server.enqueue(new MockResponse().setBody("This response gets those cookies back."));
server.play();
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost("localhost", server.getPort()));
HttpResponse getCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
getCookies.getEntity().consumeContent();
server.takeRequest();
HttpResponse sendCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
sendCookies.getEntity().consumeContent();
RecordedRequest sendCookiesRequest = server.takeRequest();
assertContains(sendCookiesRequest.getHeaders(), "Cookie: a=first; b=second; c=third");
}
Aggregations