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:com.joyent.manta.client.multipart.ServerSideMultipartManagerTest.java

public void canCompleteMpu() throws IOException {
    StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_CREATED, "NO_CONTENT");
    ServerSideMultipartManager manager = buildMockManager(statusLine, null);

    UUID id = new UUID(0L, 0L);
    String partsDirectory = manager.uuidPrefixedPath(id);
    ServerSideMultipartUpload upload = new ServerSideMultipartUpload(id, "/test/stor/myobject", partsDirectory);

    MantaMultipartUploadTuple[] unsortedTuples = new MantaMultipartUploadTuple[] {
            new MantaMultipartUploadTuple(5, new UUID(0L, 5L)),
            new MantaMultipartUploadTuple(3, new UUID(0L, 3L)),
            new MantaMultipartUploadTuple(1, new UUID(0L, 1L)),
            new MantaMultipartUploadTuple(2, new UUID(0L, 2L)),
            new MantaMultipartUploadTuple(4, new UUID(0L, 4L)) };

    manager.complete(upload, Stream.of(unsortedTuples));
}

From source file:org.gbif.registry.metasync.protocols.biocase.BiocaseMetadataSynchroniserTest.java

/**
 * Prepares a {@link HttpResponse} with the given response status and the content of the file.
 *//*from   ww  w. j  a  v  a  2  s.  c  om*/
private HttpResponse prepareResponse(int responseStatus, String fileName) throws IOException {
    HttpResponse response = new BasicHttpResponse(
            new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), responseStatus, ""));
    response.setStatusCode(responseStatus);
    byte[] bytes = Resources.toByteArray(Resources.getResource(fileName));
    response.setEntity(new ByteArrayEntity(bytes));
    return response;
}

From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportPollTest.java

@Test
public void testResponseStatusCodeOf500ThrowsExpectedException() throws Exception {
    expectedException.expect(CommunicationErrorException.class);
    expectedException.expectMessage("Expected Message");

    when(response.getStatusLine())/*from   w w  w  . j ava 2 s.co  m*/
            .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 500, "Expected Message"));
    transport.poll(new PollRequest(null, 0L, null, null));
}

From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportUsersTest.java

@Test
public void testResponseStatusCodeOf500ThrowsExpectedException() throws Exception {
    expectedException.expect(CommunicationErrorException.class);
    expectedException.expectMessage("Expected Message");

    when(response.getStatusLine())/* w  w  w .ja  va 2 s.  c  o  m*/
            .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 500, "Expected Message"));
    transport.users(new UsersRequest(null, 0L, null));
}

From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportAuthsTest.java

@Test
public void testResponseStatusCodeOf100ThrowsExpectedException() throws Exception {
    expectedException.expect(CommunicationErrorException.class);
    expectedException.expectMessage("Expected Message");

    when(response.getStatusLine())//w  ww  .  ja v a 2  s .  c o  m
            .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 100, "Expected Message"));
    transport.auths(new AuthsRequest(null, 0L, null, null, 0, 0));
}

From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportLogsTest.java

@Test
public void testResponseStatusCodeOf401ThrowsExpectedException() throws Exception {
    when(response.getStatusLine())/* www . j  ava  2  s  . c  o m*/
            .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 401, "Status Message"));
    when(response.getEntity())
            .thenReturn(EntityBuilder.create()
                    .setStream(new ByteArrayInputStream(
                            "{\"message_code\": 70401, \"message\": \"Expected Message\"}".getBytes("UTF-8")))
                    .build());
    expectedException.expect(InvalidRequestException.class);
    expectedException.expectMessage("Expected Message");
    transport.logs(new LogsRequest("Authenticate", true, null, 0L, null, null));
}

From source file:com.launchkey.sdk.transport.v1.ApacheHttpClientTransportPingTest.java

@Test
public void testResponseStatusCodeOf400ReturnsHttpValuesWhenBodyNotParseable() throws Exception {
    expectedException.expect(CommunicationErrorException.class);
    expectedException.expectMessage("Expected Message");

    when(response.getStatusLine())//w w  w.  ja  v a 2  s . co  m
            .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 400, "Expected Message"));
    when(response.getEntity()).thenReturn(EntityBuilder.create()
            .setStream(new ByteArrayInputStream("Unparseable".getBytes("UTF-8"))).build());
    transport.ping(new PingRequest());
}

From source file:at.deder.ybr.test.server.SimpleHttpServerTest.java

@Test
public void testGetPackageNoLeadingDot() throws ProtocolViolationException, IOException {
    // given// w w w. ja  v  a2  s. c  om
    ServerManifest dummyManifest = MockUtils.getMockManifest();

    given(mockHttpClient.execute(Matchers.any(HttpGet.class))).willReturn(mockHttpResponse);
    given(mockHttpResponse.getEntity()).willReturn(mockHttpEntity);
    given(mockHttpResponse.getStatusLine())
            .willReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"));
    given(mockHttpEntity.getContent())
            .willReturn(new ByteArrayInputStream(dummyManifest.toString().getBytes("utf-8")));
    SimpleHttpServer instance = new SimpleHttpServer("none");
    instance.setHttpClient(mockHttpClient);

    // when
    RepositoryEntry result = instance.getPackage("com.java.io.file");

    // then
    RepositoryEntry root = dummyManifest.getRepository();
    RepositoryEntry expResult = root.getChildByName("com").getChildByName("java").getChildByName("io")
            .getChildByName("file");
    then(result).isEqualTo(expResult);
}

From source file:com.comcast.video.dawg.house.DawgHouseClientTest.java

@Test(expectedExceptions = NullPointerException.class)
public void testDeleteMetaStbWithNull() throws HttpException {
    RestClient mockClient = EasyMock.createMock(RestClient.class);

    DawgHouseClient client = new DawgHouseClient();
    client.setClient(mockClient);/*  w  ww . j  av a2 s  . c o m*/
    RestResponse response = new RestResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 0, 0), 0, null));
    EasyMock.expect(mockClient.execute((RestRequest) EasyMock.anyObject())).andReturn(response);
    EasyMock.replay(mockClient);

    MetaStb stb = null;

    client.delete(stb);
}

From source file:org.sentilo.platform.server.test.parser.DataParserTest.java

@Test
public void parseEmptySensorWriteResponse() throws Exception {
    final String[] parts = { "prov1", "sensor1" };
    when(resource.getParts()).thenReturn(parts);

    final List<Observation> subscriptionList = Collections.emptyList();
    final SentiloResponse response = SentiloResponse
            .build(new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_0, 200, "")));
    parser.writeResponse(sentiloRequest, response, subscriptionList);

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ((ByteArrayEntity) response.getHttpResponse().getEntity()).writeTo(baos);
    final String expected = "{\"observations\":[]}";
    assertEquals(expected, baos.toString());
}