Example usage for org.apache.http.message BasicStatusLine BasicStatusLine

List of usage examples for org.apache.http.message BasicStatusLine BasicStatusLine

Introduction

In this page you can find the example usage for org.apache.http.message BasicStatusLine BasicStatusLine.

Prototype

public BasicStatusLine(ProtocolVersion protocolVersion, int i, String str) 

Source Link

Usage

From source file:org.llorllale.youtrack.api.mock.http.response.MockBadRequestResponse.java

/**
 * Ctor./* w  w w  . j a  va  2  s.c  o  m*/
 * @since 1.0.0
 */
public MockBadRequestResponse() {
    this.statusLine = new BasicStatusLine(new HttpVersion(1, 1),
            // @checkstyle MagicNumber (1 line)
            400, "Bad Request");
}

From source file:org.llorllale.youtrack.api.mock.http.response.MockInternalErrorResponse.java

/**
 * Ctor./* w w w .j  a  va  2  s .com*/
 */
@SuppressWarnings("checkstyle:MagicNumber")
public MockInternalErrorResponse() {
    this.statusLine = new BasicStatusLine(new HttpVersion(1, 1), 500, "Internal Server Error");
}

From source file:bit.changepurse.wdk.http.MockedApacheResponse.java

@Override
public void setStatusLine(ProtocolVersion version, int statusCode) {
    statusLine = new BasicStatusLine(version, statusCode, "");
}

From source file:org.llorllale.youtrack.api.mock.http.response.MockUnauthorizedResponse.java

/**
 * Ctor.//from   w ww.j a  v  a  2  s .  c om
 * @since 1.0.0
 */
@SuppressWarnings("checkstyle:MagicNumber")
public MockUnauthorizedResponse() {
    this.statusLine = new BasicStatusLine(new HttpVersion(1, 1), 401, "Unauthorized");
}

From source file:gov.nasa.arc.geocam.memo.service.test.SiteAuthCookieImplementationTest.java

private void prepResponse(int statusCode, String content) throws Exception {
    StatusLine sl = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 0), statusCode, "some reason");
    HttpResponse response = new BasicHttpResponse(sl);
    InputStream is = new ByteArrayInputStream(content.getBytes());
    HttpEntity he = mock(HttpEntity.class);
    when(he.getContent()).thenReturn(is);
    response.setEntity(he);/*ww  w  . j ava2  s.c om*/

    Robolectric.addPendingHttpResponse(response);
}

From source file:com.github.mfriedenhagen.artifactorygo.JsonResponseHandlerTest.java

/**
 * Test of handleResponse method, of class JsonResponseHandler.
 *///from  w w w .  j av  a2 s. co m
@Test(expected = HttpResponseException.class)
public void testHandleResponseBadStatusCode() throws Exception {
    final BasicStatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_MULTIPLE_CHOICES,
            "Multiple Choices");
    when(mockedResponse.getStatusLine()).thenReturn(statusLine);

    sut.handleResponse(mockedResponse);
}

From source file:net.oneandone.shared.artifactory.JsonResponseHandlerTest.java

/**
 * Test of handleResponse method, of class JsonResponseHandler.
 *///from  w w w . j  a  v  a 2 s.  co  m
@Test(expected = HttpResponseException.class)
public void testHandleResponseBadStatusCode() throws Exception {
    final BasicStatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_MULTIPLE_CHOICES,
            "Multiple Choices");
    when(mockedResponse.getStatusLine()).thenReturn(statusLine);
    sut.handleResponse(mockedResponse);
}

From source file:org.elasticsearch.client.ResponseExceptionTests.java

public void testResponseException() throws IOException {
    ProtocolVersion protocolVersion = new ProtocolVersion("http", 1, 1);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 500, "Internal Server Error");
    HttpResponse httpResponse = new BasicHttpResponse(statusLine);

    String responseBody = "{\"error\":{\"root_cause\": {}}}";
    boolean hasBody = getRandom().nextBoolean();
    if (hasBody) {
        HttpEntity entity;//from   ww w . j  a  v  a 2s  .  c  o m
        if (getRandom().nextBoolean()) {
            entity = new StringEntity(responseBody, ContentType.APPLICATION_JSON);
        } else {
            //test a non repeatable entity
            entity = new InputStreamEntity(
                    new ByteArrayInputStream(responseBody.getBytes(StandardCharsets.UTF_8)),
                    ContentType.APPLICATION_JSON);
        }
        httpResponse.setEntity(entity);
    }

    RequestLine requestLine = new BasicRequestLine("GET", "/", protocolVersion);
    HttpHost httpHost = new HttpHost("localhost", 9200);
    Response response = new Response(requestLine, httpHost, httpResponse);
    ResponseException responseException = new ResponseException(response);

    assertSame(response, responseException.getResponse());
    if (hasBody) {
        assertEquals(responseBody, EntityUtils.toString(responseException.getResponse().getEntity()));
    } else {
        assertNull(responseException.getResponse().getEntity());
    }

    String message = response.getRequestLine().getMethod() + " " + response.getHost()
            + response.getRequestLine().getUri() + ": " + response.getStatusLine().toString();
    if (hasBody) {
        message += "\n" + responseBody;
    }
    assertEquals(message, responseException.getMessage());
}

From source file:org.envirocar.app.test.dao.TrackDecoderTest.java

public void testTotalTrackCount() throws TrackRetrievalException {
    BasicHttpResponse response = new BasicHttpResponse(createStatusLine());
    response.setHeader("Link",
            "<https://envirocar.org/api/stable/users/matthes/tracks?limit=1&page=7>;rel=last;type=application/json, <https://envirocar.org/api/stable/users/matthes/tracks?limit=1&page=2>;rel=next;type=application/json");
    Integer count = new TrackDecoder().resolveTrackCount(response);

    Assert.assertTrue(count.intValue() == 7);

    response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 204, ""));
    response.setHeader("Link", "<https://envirocar.org/api/stable/users/matthes/tracks?page=6>;rel=last");
    count = new TrackDecoder().resolveTrackCount(response);

    Assert.assertTrue(count.intValue() == 6);

}

From source file:bit.changepurse.wdk.http.MockedApacheResponse.java

@Override
public void setStatusLine(ProtocolVersion version, int statusCode, String reason) {
    statusLine = new BasicStatusLine(version, statusCode, reason);
}