Search in sources :

Example 1 with DefaultRequestDirector

use of org.apache.http.impl.client.DefaultRequestDirector in project robolectric by robolectric.

the class FakeHttpTest method makeRequest.

private void makeRequest(String uri) throws HttpException, IOException {
    FakeHttp.addPendingHttpResponse(200, "a happy response body");
    ConnectionKeepAliveStrategy connectionKeepAliveStrategy = new ConnectionKeepAliveStrategy() {

        @Override
        public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) {
            return 0;
        }
    };
    DefaultRequestDirector requestDirector = new DefaultRequestDirector(null, null, null, connectionKeepAliveStrategy, null, null, null, null, null, null, null, null);
    requestDirector.execute(null, new HttpGet(uri), null);
}
Also used : ConnectionKeepAliveStrategy(org.apache.http.conn.ConnectionKeepAliveStrategy) HttpGet(org.apache.http.client.methods.HttpGet) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) DefaultRequestDirector(org.apache.http.impl.client.DefaultRequestDirector)

Example 2 with DefaultRequestDirector

use of org.apache.http.impl.client.DefaultRequestDirector in project robolectric by robolectric.

the class ShadowDefaultRequestDirectorTest method shouldRecordExtendedRequestData.

@Test
public void shouldRecordExtendedRequestData() throws Exception {
    FakeHttp.addPendingHttpResponse(200, "a happy response body");
    HttpGet httpGet = new HttpGet("http://example.com");
    requestDirector.execute(null, httpGet, null);
    assertSame(FakeHttp.getSentHttpRequestInfo(0).getHttpRequest(), httpGet);
    ConnectionKeepAliveStrategy strategy = shadowOf((DefaultRequestDirector) FakeHttp.getSentHttpRequestInfo(0).getRequestDirector()).getConnectionKeepAliveStrategy();
    assertSame(strategy, connectionKeepAliveStrategy);
}
Also used : ConnectionKeepAliveStrategy(org.apache.http.conn.ConnectionKeepAliveStrategy) HttpGet(org.apache.http.client.methods.HttpGet) DefaultRequestDirector(org.apache.http.impl.client.DefaultRequestDirector) Test(org.junit.Test)

Example 3 with DefaultRequestDirector

use of org.apache.http.impl.client.DefaultRequestDirector in project robolectric by robolectric.

the class ShadowDefaultRequestDirectorTest method setUp_EnsureStaticStateIsReset.

@Before
public void setUp_EnsureStaticStateIsReset() {
    FakeHttpLayer fakeHttpLayer = FakeHttp.getFakeHttpLayer();
    assertFalse(fakeHttpLayer.hasPendingResponses());
    assertFalse(fakeHttpLayer.hasRequestInfos());
    assertFalse(fakeHttpLayer.hasResponseRules());
    connectionKeepAliveStrategy = new ConnectionKeepAliveStrategy() {

        @Override
        public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) {
            return 0;
        }
    };
    requestDirector = new DefaultRequestDirector(null, null, null, connectionKeepAliveStrategy, null, null, null, null, null, null, null, null);
}
Also used : ConnectionKeepAliveStrategy(org.apache.http.conn.ConnectionKeepAliveStrategy) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) DefaultRequestDirector(org.apache.http.impl.client.DefaultRequestDirector) Before(org.junit.Before)

Aggregations

ConnectionKeepAliveStrategy (org.apache.http.conn.ConnectionKeepAliveStrategy)3 DefaultRequestDirector (org.apache.http.impl.client.DefaultRequestDirector)3 HttpResponse (org.apache.http.HttpResponse)2 HttpGet (org.apache.http.client.methods.HttpGet)2 HttpContext (org.apache.http.protocol.HttpContext)2 Before (org.junit.Before)1 Test (org.junit.Test)1