Search in sources :

Example 26 with BasicHeader

use of org.apache.http.message.BasicHeader in project robolectric by robolectric.

the class FakeHttpLayerTest method matches_shouldMatchHeaders.

@Test
public void matches_shouldMatchHeaders() throws Exception {
    requestMatcherBuilder.header("header1", "header one");
    HttpGet match = new HttpGet("example.com");
    HttpGet noMatch = new HttpGet("example.com");
    match.setHeader(new BasicHeader("header1", "header one"));
    noMatch.setHeader(new BasicHeader("header1", "header not a match"));
    assertThat(requestMatcherBuilder.matches(new HttpGet("example.com"))).isFalse();
    assertThat(requestMatcherBuilder.matches(noMatch)).isFalse();
    assertThat(requestMatcherBuilder.matches(match)).isTrue();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) BasicHeader(org.apache.http.message.BasicHeader) Test(org.junit.Test)

Example 27 with BasicHeader

use of org.apache.http.message.BasicHeader in project robolectric by robolectric.

the class TestHttpResponseTest method shouldSupportHeaderIterator.

@Test
public void shouldSupportHeaderIterator() throws Exception {
    HttpResponse resp = new TestHttpResponse(304, "REDIRECTED", new BasicHeader("Location", "http://bar.com"), new BasicHeader("Location", "http://zombo.com"));
    HeaderIterator it = resp.headerIterator();
    assertThat(it.hasNext()).isTrue();
    assertThat(it.nextHeader().getValue()).isEqualTo("http://bar.com");
    assertThat(it.nextHeader().getValue()).isEqualTo("http://zombo.com");
    assertThat(it.hasNext()).isFalse();
}
Also used : TestHttpResponse(org.robolectric.shadows.httpclient.TestHttpResponse) TestHttpResponse(org.robolectric.shadows.httpclient.TestHttpResponse) HttpResponse(org.apache.http.HttpResponse) HeaderIterator(org.apache.http.HeaderIterator) BasicHeader(org.apache.http.message.BasicHeader) Test(org.junit.Test)

Example 28 with BasicHeader

use of org.apache.http.message.BasicHeader in project robolectric by robolectric.

the class TestHttpResponseTest method shouldSupportGetFirstHeader.

@Test
public void shouldSupportGetFirstHeader() throws Exception {
    HttpResponse resp = new TestHttpResponse(304, "REDIRECTED", new BasicHeader("Location", "http://bar.com"));
    assertThat(resp.getFirstHeader("None")).isNull();
    assertThat(new TestHttpResponse(200, "OK").getFirstHeader("Foo")).isNull();
    for (String l : new String[] { "location", "Location" }) {
        assertThat(resp.getFirstHeader(l).getValue()).isEqualTo("http://bar.com");
    }
}
Also used : TestHttpResponse(org.robolectric.shadows.httpclient.TestHttpResponse) TestHttpResponse(org.robolectric.shadows.httpclient.TestHttpResponse) HttpResponse(org.apache.http.HttpResponse) BasicHeader(org.apache.http.message.BasicHeader) Test(org.junit.Test)

Example 29 with BasicHeader

use of org.apache.http.message.BasicHeader in project robolectric by robolectric.

the class ShadowDefaultRequestDirectorTest method shouldSupportBasicResponseHandlerHandleResponse.

@Test
public void shouldSupportBasicResponseHandlerHandleResponse() throws Exception {
    FakeHttp.addPendingHttpResponse(200, "OK", new BasicHeader("Content-Type", "text/plain"));
    DefaultHttpClient client = new DefaultHttpClient();
    HttpResponse response = client.execute(new HttpGet("http://www.nowhere.org"));
    assertThat(((HttpUriRequest) FakeHttp.getSentHttpRequest(0)).getURI()).isEqualTo(URI.create("http://www.nowhere.org"));
    Assert.assertNotNull(response);
    String responseStr = new BasicResponseHandler().handleResponse(response);
    Assert.assertEquals("OK", responseStr);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpGet(org.apache.http.client.methods.HttpGet) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) HttpResponse(org.apache.http.HttpResponse) BasicHeader(org.apache.http.message.BasicHeader) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Test(org.junit.Test)

Example 30 with BasicHeader

use of org.apache.http.message.BasicHeader in project robolectric by robolectric.

the class TestHttpResponseTest method shouldSupportGetLastHeader.

@Test
public void shouldSupportGetLastHeader() throws Exception {
    HttpResponse resp = new TestHttpResponse(304, "REDIRECTED", new BasicHeader("Location", "http://bar.com"), new BasicHeader("Location", "http://zombo.com"));
    assertThat(resp.getLastHeader("None")).isNull();
    for (String l : new String[] { "location", "Location" }) {
        assertThat(resp.getLastHeader(l).getValue()).isEqualTo("http://zombo.com");
    }
}
Also used : TestHttpResponse(org.robolectric.shadows.httpclient.TestHttpResponse) TestHttpResponse(org.robolectric.shadows.httpclient.TestHttpResponse) HttpResponse(org.apache.http.HttpResponse) BasicHeader(org.apache.http.message.BasicHeader) Test(org.junit.Test)

Aggregations

BasicHeader (org.apache.http.message.BasicHeader)233 Header (org.apache.http.Header)120 IOException (java.io.IOException)54 HttpResponse (org.apache.http.HttpResponse)50 Test (org.junit.Test)50 StringEntity (org.apache.http.entity.StringEntity)36 List (java.util.List)25 HashMap (java.util.HashMap)24 URISyntaxException (java.net.URISyntaxException)23 HttpGet (org.apache.http.client.methods.HttpGet)22 StatusLine (org.apache.http.StatusLine)20 HttpPost (org.apache.http.client.methods.HttpPost)20 BasicStatusLine (org.apache.http.message.BasicStatusLine)19 RestResponse (com.google.gerrit.acceptance.RestResponse)18 ArrayList (java.util.ArrayList)18 ProtocolVersion (org.apache.http.ProtocolVersion)18 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)17 File (java.io.File)17 HttpEntity (org.apache.http.HttpEntity)17 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)17