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();
}
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();
}
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");
}
}
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);
}
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");
}
}
Aggregations