use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project gocd by gocd.
the class AgentWebSocketClientControllerTest method processBuildCommand.
@Test
public void processBuildCommand() throws Exception {
ArgumentCaptor<Message> currentStatusMessageCaptor = ArgumentCaptor.forClass(Message.class);
when(agentRegistry.uuid()).thenReturn(agentUuid);
CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
when(httpService.execute(any())).thenReturn(httpResponse);
agentController = createAgentController();
agentController.init();
BuildSettings build = new BuildSettings();
build.setBuildId("b001");
build.setConsoleUrl("http://foo.bar/console");
build.setArtifactUploadBaseUrl("http://foo.bar/artifacts");
build.setPropertyBaseUrl("http://foo.bar/properties");
build.setBuildLocator("build1");
build.setBuildLocatorForDisplay("build1ForDisplay");
build.setBuildCommand(BuildCommand.compose(BuildCommand.echo("building"), BuildCommand.reportCurrentStatus(JobState.Building)));
agentController.process(new Message(Action.build, MessageEncoding.encodeData(build)));
assertThat(agentController.getAgentRuntimeInfo().getRuntimeStatus(), is(AgentRuntimeStatus.Idle));
AgentRuntimeInfo agentRuntimeInfo = cloneAgentRuntimeInfo(agentController.getAgentRuntimeInfo());
agentRuntimeInfo.busy(new AgentBuildingInfo("build1ForDisplay", "build1"));
verify(webSocketSessionHandler, times(2)).sendAndWaitForAcknowledgement(currentStatusMessageCaptor.capture());
Message message = currentStatusMessageCaptor.getAllValues().get(0);
assertThat(message.getAcknowledgementId(), notNullValue());
assertThat(message.getAction(), is(Action.reportCurrentStatus));
assertThat(message.getData(), is(MessageEncoding.encodeData(new Report(agentRuntimeInfo, "b001", JobState.Building, null))));
Message jobCompletedMessage = currentStatusMessageCaptor.getAllValues().get(1);
assertThat(jobCompletedMessage.getAcknowledgementId(), notNullValue());
assertThat(jobCompletedMessage.getAction(), is(Action.reportCompleted));
assertThat(jobCompletedMessage.getData(), is(MessageEncoding.encodeData(new Report(agentRuntimeInfo, "b001", null, JobResult.Passed))));
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project gocd by gocd.
the class HttpServiceTest method shouldSetTheAcceptHeaderWhilePostingProperties.
@Test
public void shouldSetTheAcceptHeaderWhilePostingProperties() throws Exception {
HttpPost post = mock(HttpPost.class);
when(httpClientFactory.createPost("url")).thenReturn(post);
CloseableHttpResponse response = mock(CloseableHttpResponse.class);
when(response.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
when(httpClient.execute(post)).thenReturn(response);
ArgumentCaptor<UrlEncodedFormEntity> entityCaptor = ArgumentCaptor.forClass(UrlEncodedFormEntity.class);
service.postProperty("url", "value");
verify(post).setHeader("Confirm", "true");
verify(post).setEntity(entityCaptor.capture());
UrlEncodedFormEntity expected = new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair("value", "value")));
UrlEncodedFormEntity actual = entityCaptor.getValue();
assertEquals(IOUtils.toString(expected.getContent()), IOUtils.toString(actual.getContent()));
assertEquals(expected.getContentLength(), expected.getContentLength());
assertEquals(expected.getContentType(), expected.getContentType());
assertEquals(expected.getContentEncoding(), expected.getContentEncoding());
assertEquals(expected.isChunked(), expected.isChunked());
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project wildfly-camel by wildfly-extras.
the class HipchatConsumerIntegrationTest method sendInOnlyMultipleUsers.
@Test
public void sendInOnlyMultipleUsers() throws Exception {
CamelContext camelctx = createCamelContext();
MockEndpoint result = camelctx.getEndpoint("mock:result", MockEndpoint.class);
result.expectedMessageCount(1);
camelctx.start();
try {
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, ""));
result.assertIsSatisfied();
assertCommonResultExchange(result.getExchanges().get(0));
} finally {
camelctx.stop();
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project herd by FINRAOS.
the class DataBridgeWebClientTest method testGetBusinessObjectDataStorageFilesCreateResponse200BadContentReturnsNull.
@Test
public void testGetBusinessObjectDataStorageFilesCreateResponse200BadContentReturnsNull() throws Exception {
CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "testReasonPhrase"), false);
httpResponse.setEntity(new StringEntity("invalid xml"));
executeWithoutLogging(DataBridgeWebClient.class, () -> {
BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse = dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse);
assertNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse);
});
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project herd by FINRAOS.
the class DataBridgeWebClientTest method testGetBusinessObjectDataStorageFilesCreateResponse400Throws.
@Test
public void testGetBusinessObjectDataStorageFilesCreateResponse400Throws() throws Exception {
int expectedStatusCode = 400;
String expectedReasonPhrase = "testReasonPhrase";
String expectedErrorMessage = "testErrorMessage";
ErrorInformation errorInformation = new ErrorInformation();
errorInformation.setStatusCode(expectedStatusCode);
errorInformation.setMessage(expectedErrorMessage);
errorInformation.setStatusDescription(expectedReasonPhrase);
String requestContent = xmlHelper.objectToXml(errorInformation);
CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, expectedStatusCode, expectedReasonPhrase), false);
httpResponse.setEntity(new StringEntity(requestContent));
try {
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());
}
}
Aggregations