Search in sources :

Example 6 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project iosched by google.

the class MockHttpClient method execute.

// This is the only one we actually use.
@Override
public HttpResponse execute(HttpUriRequest request, HttpContext context) {
    requestExecuted = request;
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), mStatusCode, "");
    HttpResponse response = new BasicHttpResponse(statusLine);
    response.setEntity(mResponseEntity);
    return response;
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Example 7 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project camel by apache.

the class HipchatComponentConsumerTest method sendInOnly.

@Test
public void sendInOnly() throws Exception {
    result.expectedMessageCount(1);
    String expectedResponse = "{\n" + "  \"items\" : [\n" + "    {\n" + "      \"date\" : \"2015-01-19T22:07:11.030740+00:00\",\n" + "      \"from\" : {\n" + "        \"id\" : 1647095,\n" + "        \"links\" : {\n" + "          \"self\" : \"https://api.hipchat.com/v2/user/1647095\"\n" + "        },\n" + "        \"mention_name\" : \"notifier\",\n" + "        \"name\" : \"Message Notifier\"\n" + "      },\n" + "      \"id\" : \"6567c6f7-7c1b-43cf-bed0-792b1d092919\",\n" + "      \"mentions\" : [ ],\n" + "      \"message\" : \"Unit test Alert\",\n" + "      \"type\" : \"message\"\n" + "    }\n" + "  ],\n" + "  \"links\" : {\n" + "    \"self\" : \"https://api.hipchat.com/v2/user/%40ShreyasPurohit/history/latest\"\n" + "  },\n" + "  \"maxResults\" : 1,\n" + "  \"startIndex\" : 0\n" + "}";
    HttpEntity mockHttpEntity = mock(HttpEntity.class);
    when(mockHttpEntity.getContent()).thenReturn(new ByteArrayInputStream(expectedResponse.getBytes(StandardCharsets.UTF_8)));
    when(closeableHttpResponse.getEntity()).thenReturn(mockHttpEntity);
    when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, ""));
    assertMockEndpointsSatisfied();
    assertCommonResultExchange(result.getExchanges().get(0));
}
Also used : HttpEntity(org.apache.http.HttpEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 8 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project camel by apache.

the class HipchatComponentMultipleUsersTest method sendInOnlyMultipleUsers.

@Test
public void sendInOnlyMultipleUsers() throws Exception {
    result.expectedMessageCount(2);
    result.expectedHeaderValuesReceivedInAnyOrder(HipchatConstants.FROM_USER, Arrays.asList(new String[] { "@AUser", "@BUser" }));
    final String expectedResponse = "{\n" + "  \"items\" : [\n" + "    {\n" + "      \"date\" : \"2015-01-19T22:07:11.030740+00:00\",\n" + "      \"from\" : {\n" + "        \"id\" : 1647095,\n" + "        \"links\" : {\n" + "          \"self\" : \"https://api.hipchat.com/v2/user/1647095\"\n" + "        },\n" + "        \"mention_name\" : \"notifier\",\n" + "        \"name\" : \"Message Notifier\"\n" + "      },\n" + "      \"id\" : \"6567c6f7-7c1b-43cf-bed0-792b1d092919\",\n" + "      \"mentions\" : [ ],\n" + "      \"message\" : \"Unit test Alert\",\n" + "      \"type\" : \"message\"\n" + "    }\n" + "  ],\n" + "  \"links\" : {\n" + "    \"self\" : \"https://api.hipchat.com/v2/user/%40ShreyasPurohit/history/latest\"\n" + "  },\n" + "  \"maxResults\" : 1,\n" + "  \"startIndex\" : 0\n" + "}";
    HttpEntity mockHttpEntity = mock(HttpEntity.class);
    when(mockHttpEntity.getContent()).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            return new ByteArrayInputStream(expectedResponse.getBytes(StandardCharsets.UTF_8));
        }
    });
    when(closeableHttpResponse.getEntity()).thenReturn(mockHttpEntity);
    when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, ""));
    assertMockEndpointsSatisfied();
}
Also used : HttpEntity(org.apache.http.HttpEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 9 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project robovm by robovm.

the class DefaultHttpResponseFactory method newHttpResponse.

// non-javadoc, see interface HttpResponseFactory
public HttpResponse newHttpResponse(final ProtocolVersion ver, final int status, HttpContext context) {
    if (ver == null) {
        throw new IllegalArgumentException("HTTP version may not be null");
    }
    final Locale loc = determineLocale(context);
    final String reason = reasonCatalog.getReason(status, loc);
    StatusLine statusline = new BasicStatusLine(ver, status, reason);
    return new BasicHttpResponse(statusline, reasonCatalog, loc);
}
Also used : Locale(java.util.Locale) BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Example 10 with BasicStatusLine

use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project gocd by gocd.

the class SslInfrastructureServiceTest method shouldInvalidateKeystore.

@Test
public void shouldInvalidateKeystore() throws Exception {
    temporaryFolder.create();
    File configFile = temporaryFolder.newFile();
    when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("https", 1, 2), 200, null));
    when(httpResponse.getEntity()).thenReturn(new StringEntity(RegistrationJSONizer.toJson(createRegistration())));
    when(agentRegistry.guidPresent()).thenReturn(true);
    when(httpClient.execute(any(HttpRequestBase.class))).thenReturn(httpResponse);
    when(agentRegistry.tokenPresent()).thenReturn(true);
    shouldCreateSslInfrastructure();
    sslInfrastructureService.registerIfNecessary(new AgentAutoRegistrationPropertiesImpl(configFile));
    assertThat(GoAgentServerClientBuilder.AGENT_CERTIFICATE_FILE, exists());
    verify(httpClient, times(1)).execute(any(HttpRequestBase.class));
    sslInfrastructureService.registerIfNecessary(new AgentAutoRegistrationPropertiesImpl(configFile));
    verify(httpClient, times(1)).execute(any(HttpRequestBase.class));
    sslInfrastructureService.invalidateAgentCertificate();
    sslInfrastructureService.registerIfNecessary(new AgentAutoRegistrationPropertiesImpl(configFile));
    verify(httpClient, times(2)).execute(any(HttpRequestBase.class));
}
Also used : StringEntity(org.apache.http.entity.StringEntity) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) AgentAutoRegistrationPropertiesImpl(com.thoughtworks.go.agent.AgentAutoRegistrationPropertiesImpl) ProtocolVersion(org.apache.http.ProtocolVersion) File(java.io.File) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Aggregations

BasicStatusLine (org.apache.http.message.BasicStatusLine)118 ProtocolVersion (org.apache.http.ProtocolVersion)67 Test (org.junit.Test)56 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)54 StatusLine (org.apache.http.StatusLine)45 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)33 StringEntity (org.apache.http.entity.StringEntity)32 ByteArrayInputStream (java.io.ByteArrayInputStream)29 HttpResponse (org.apache.http.HttpResponse)27 IOException (java.io.IOException)19 HttpEntity (org.apache.http.HttpEntity)19 BasicHeader (org.apache.http.message.BasicHeader)19 URL (java.net.URL)17 HttpURLConnection (java.net.HttpURLConnection)16 List (java.util.List)16 Header (org.apache.http.Header)16 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)16 HashMap (java.util.HashMap)14 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)13 BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)12