Search in sources :

Example 1 with TestHttpResponse

use of org.robolectric.tester.org.apache.http.TestHttpResponse in project RoboZombie by sahan.

the class ResponseEndpointTest method testRawResponse.

/**
	 * <p>Test for a request which expects the raw {@link HttpResponse}.</p>
	 *
	 * @since 1.3.0
	 */
@Test
public final void testRawResponse() throws ParseException, IOException {
    String subpath = "/rawresponse";
    String url = "http://0.0.0.0:8080" + subpath;
    String body = "Welcome to the Republic of Genosha";
    Robolectric.addHttpResponseRule(HttpGet.METHOD_NAME, url, new TestHttpResponse(200, body));
    Object response = responseEndpoint.rawResponse();
    assertNotNull(response);
    assertTrue(response instanceof HttpResponse);
    assertEquals(EntityUtils.toString(((HttpResponse) response).getEntity()), body);
}
Also used : TestHttpResponse(org.robolectric.tester.org.apache.http.TestHttpResponse) TestHttpResponse(org.robolectric.tester.org.apache.http.TestHttpResponse) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 2 with TestHttpResponse

use of org.robolectric.tester.org.apache.http.TestHttpResponse in project RoboZombie by sahan.

the class ResponseEndpointTest method testRawEntity.

/**
	 * <p>Test for a request which expects the raw {@link HttpEntity}.</p>
	 *
	 * @since 1.3.0
	 */
@Test
public final void testRawEntity() throws ParseException, IOException {
    String subpath = "/rawentity";
    String url = "http://0.0.0.0:8080" + subpath;
    String body = "Hulk, make me a sandwich";
    Robolectric.addHttpResponseRule(HttpGet.METHOD_NAME, url, new TestHttpResponse(200, body));
    Object response = responseEndpoint.rawEntity();
    assertNotNull(response);
    assertTrue(response instanceof HttpEntity);
    assertEquals(EntityUtils.toString(((HttpEntity) response)), body);
}
Also used : TestHttpResponse(org.robolectric.tester.org.apache.http.TestHttpResponse) HttpEntity(org.apache.http.HttpEntity) Test(org.junit.Test)

Example 3 with TestHttpResponse

use of org.robolectric.tester.org.apache.http.TestHttpResponse in project RoboZombie by sahan.

the class ResponseEndpointTest method testNoDeserializer.

/**
	 * <p>Test for a request which expects the raw {@link HttpEntity}.</p>
	 *
	 * @since 1.3.0
	 */
@Test
public final void testNoDeserializer() {
    String subpath = "/nodeserializer";
    String url = "http://0.0.0.0:8080" + subpath;
    String body = new Gson().toJson(new User(1, "Cain", "Marko", 37, false));
    Robolectric.addHttpResponseRule(HttpGet.METHOD_NAME, url, new TestHttpResponse(200, body));
    expectedException.expect(Is.isA(InvocationException.class));
    responseEndpoint.noDeserializer();
}
Also used : User(com.lonepulse.robozombie.model.User) TestHttpResponse(org.robolectric.tester.org.apache.http.TestHttpResponse) InvocationException(com.lonepulse.robozombie.proxy.InvocationException) Gson(com.google.gson.Gson) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 TestHttpResponse (org.robolectric.tester.org.apache.http.TestHttpResponse)3 Gson (com.google.gson.Gson)1 User (com.lonepulse.robozombie.model.User)1 InvocationException (com.lonepulse.robozombie.proxy.InvocationException)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1