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.comcast.video.dawg.house.DawgHouseClientTest.java

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

    DawgHouseClient client = new DawgHouseClient();
    client.setClient(mockClient);/*from   w w w  . j a  v  a  2  s. co 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);

    String query = "";

    client.getByQuery(query);
}

From source file:com.joyent.manta.client.multipart.ServerSideMultipartManagerTest.java

public void canUploadPartAndFailOnMissingEtag() throws IOException {
    final UUID uploadId = UUID.randomUUID();
    final String partsDirectory = "/test/uploads/a/abcdef";
    final String path = "/test/stor/object";
    final ServerSideMultipartUpload upload = new ServerSideMultipartUpload(uploadId, path, partsDirectory);

    // while it isn't strictly necessary to configure the mock to return null, it's better to be explicit about
    // what's being tested
    final ServerSideMultipartManager mngr = buildMockManager(
            new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_NO_CONTENT, "No Content"), "",
            (response) -> when(response.getFirstHeader(HttpHeaders.ETAG)).thenReturn(null));

    final Exception e = Assert.expectThrows(MantaMultipartException.class, () -> {
        mngr.uploadPart(upload, 1, new byte[0]);
    });//from  w ww.j a  va  2 s. c  om

    Assert.assertTrue(e.getMessage().contains("ETag missing from part response"));
}

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

@Test
public void parseWriteResponse() throws Exception {
    final SentiloResponse response = SentiloResponse
            .build(new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_0, 200, "")));
    parser.writeResponse(response, getSubscriptions());
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ((ByteArrayEntity) response.getHttpResponse().getEntity()).writeTo(baos);
    final String expected = "{\"subscriptions\":[{\"endpoint\":\"htt://dev.connecta.cat\",\"type\":\"ALARM\",\"alert\":\"alarm1\"},{\"endpoint\":\"htt://dev.connecta.cat\",\"type\":\"ORDER\",\"provider\":\"prov2\"},{\"endpoint\":\"htt://dev.connecta.cat\",\"type\":\"DATA\",\"provider\":\"prov2\"},{\"endpoint\":\"htt://dev.connecta.cat\",\"type\":\"DATA\",\"provider\":\"prov2\",\"sensor\":\"sensor2\"}]}";
    assertEquals(expected, baos.toString());
}

From source file:org.sentilo.common.test.rest.RESTClientImplTest.java

@Test
public void post() throws Exception {
    final String path = "/data";
    final String body = "body";
    final String responseContent = "Lorem ipsum";
    final StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_0, HttpStatus.SC_OK, "");

    when(httpClient.execute(notNull(HttpPost.class))).thenReturn(httpResponse);
    when(httpResponse.getStatusLine()).thenReturn(statusLine);
    when(httpResponse.getEntity()).thenReturn(new StringEntity(responseContent));

    final String result = restClient.post(path, body);

    verify(httpClient).execute(any(HttpPost.class));
    Assert.assertEquals(responseContent, result);
}

From source file:org.finra.herd.tools.common.databridge.DataBridgeWebClientTest.java

@Test
public void testGetBusinessObjectDataStorageFilesCreateResponse400BadContentThrows() throws Exception {
    int expectedStatusCode = 400;
    String expectedReasonPhrase = "testReasonPhrase";
    String expectedErrorMessage = "invalid xml";

    CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(
            new BasicStatusLine(HttpVersion.HTTP_1_1, expectedStatusCode, expectedReasonPhrase), false);
    httpResponse.setEntity(new StringEntity(expectedErrorMessage));
    try {/*from w  ww  .j a v a  2  s.  co  m*/
        executeWithoutLogging(DataBridgeWebClient.class, () -> {
            dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse);
        });
        Assert.fail("expected HttpErrorResponseException, but no exception was thrown");
    } catch (Exception e) {
        assertEquals("thrown exception type", HttpErrorResponseException.class, e.getClass());

        HttpErrorResponseException httpErrorResponseException = (HttpErrorResponseException) e;
        assertEquals("httpErrorResponseException responseMessage", expectedErrorMessage,
                httpErrorResponseException.getResponseMessage());
        assertEquals("httpErrorResponseException statusCode", expectedStatusCode,
                httpErrorResponseException.getStatusCode());
        assertEquals("httpErrorResponseException statusDescription", expectedReasonPhrase,
                httpErrorResponseException.getStatusDescription());
        assertEquals("httpErrorResponseException message", "Failed to add storage files",
                httpErrorResponseException.getMessage());
    }
}

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

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

    when(response.getStatusLine())/*w ww  .  jav a  2 s.c o  m*/
            .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 500, "Expected Message"));
    transport.ping(new PingRequest());
}

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

@Test
public void testGetPackageDeep() throws ProtocolViolationException, IOException {
    // given/*ww  w . j  a  v  a  2s . 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.launchkey.sdk.transport.v1.ApacheHttpClientTransportPollTest.java

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

    when(response.getStatusLine())//from w  w  w.  j  a  v  a 2  s  .c  o  m
            .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 300, "Expected Message"));
    transport.poll(new PollRequest(null, 0L, null, null));
}

From source file:org.gbif.registry.metasync.protocols.digir.DigirMetadataSynchroniserTest.java

public 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.betfair.cougar.client.HttpClientExecutableTest.java

@Test
public void testFailingCall() throws IOException {
    generateEV(tsd, null);/* www .  j av  a2 s  . c  o m*/
    HttpUriRequest mockMethod = mock(HttpUriRequest.class);
    final BasicHttpResponse httpResponse = new BasicHttpResponse(
            new BasicStatusLine(HttpVersion.HTTP_1_1, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ""));
    when(mockHttpClient.execute(any(HttpUriRequest.class))).thenReturn(httpResponse);
    when(mockMethodFactory.create(anyString(), anyString(), any(Message.class), any(Marshaller.class),
            anyString(), any(ClientCallContext.class), any(TimeConstraints.class))).thenReturn(mockMethod);
    when(mockedHttpErrorTransformer.convert(any(InputStream.class), any(ExceptionFactory.class), anyInt()))
            .thenReturn(new CougarClientException(ServerFaultCode.RemoteCougarCommunicationFailure, "bang"));

    HttpParams mockParams = mock(HttpParams.class);
    when(mockMethod.getParams()).thenReturn(mockParams);

    ExecutionObserver mockedObserver = mock(ExecutionObserver.class);
    client.execute(createEC(null, null, false), TestServiceDefinition.TEST_MIXED,
            new Object[] { TEST_TEXT, TEST_TEXT }, mockedObserver, ev, DefaultTimeConstraints.NO_CONSTRAINTS);

    ArgumentCaptor<ExecutionResult> resultCaptor = ArgumentCaptor.forClass(ExecutionResult.class);
    verify(mockedObserver).onResult(resultCaptor.capture());
    ExecutionResult actual = resultCaptor.getValue();
    assertEquals(ExecutionResult.ResultType.Fault, actual.getResultType());
    assertNotNull(actual.getFault());
    assertNull(actual.getResult());
    assertNull(actual.getSubscription());
    assertEquals(0, ((ClientExecutionResult) actual).getResultSize());
}