use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project docker-java-api by amihaiemil.
the class AssertRequestTestCase method returnResponseIfRequestMeetsCondition.
/**
* Should return the given response if the request meets the given
* condition.
*
* @throws Exception Unexpected.
*/
@Test
public void returnResponseIfRequestMeetsCondition() throws Exception {
final HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_OK, "OK"));
MatcherAssert.assertThat(new AssertRequest(response, new Condition("", // @checkstyle LineLength (1 line)
r -> "http://some.test.com".equals(r.getRequestLine().getUri()))).execute(new HttpGet("http://some.test.com")), Matchers.is(response));
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project herd by FINRAOS.
the class MockHttpClientOperationsImpl method execute.
@Override
public CloseableHttpResponse execute(CloseableHttpClient httpClient, HttpUriRequest request) throws IOException, JAXBException {
LOGGER.debug("request = " + request);
ProtocolVersion protocolVersion = new ProtocolVersion("http", 1, 1);
StatusLine statusLine = new BasicStatusLine(protocolVersion, HttpStatus.SC_OK, "Success");
MockCloseableHttpResponse response = new MockCloseableHttpResponse(statusLine, false);
// Find out which API's are being called and build an appropriate response.
URI uri = request.getURI();
if (request instanceof HttpGet) {
if (uri.getPath().startsWith("/herd-app/rest/businessObjectData/")) {
if (uri.getPath().endsWith("s3KeyPrefix")) {
buildGetS3KeyPrefixResponse(response, uri);
} else if (uri.getPath().endsWith("versions")) {
buildGetBusinessObjectDataVersionsResponse(response, uri);
} else if (uri.getPath().startsWith("/herd-app/rest/businessObjectData/upload/credential")) {
getBusinessObjectDataUploadCredentialResponse(response, uri);
} else {
buildGetBusinessObjectDataResponse(response, uri);
}
} else if (uri.getPath().startsWith("/herd-app/rest/businessObjectDefinitions/")) {
checkHostname(request, HOSTNAME_THROW_IO_EXCEPTION);
buildGetBusinessObjectDefinitionResponse(response, uri);
} else if (uri.getPath().startsWith("/herd-app/rest/storages/")) {
checkHostname(request, HOSTNAME_THROW_IO_EXCEPTION_DURING_GET_STORAGE);
buildGetStorageResponse(response, uri);
} else if (uri.getPath().startsWith("/herd-app/rest/storageUnits/download/credential")) {
getStorageUnitDownloadCredentialResponse(response, uri);
}
} else if (request instanceof HttpPost) {
if (uri.getPath().startsWith("/herd-app/rest/businessObjectDataStorageFiles")) {
checkHostname(request, HOSTNAME_THROW_IO_EXCEPTION_DURING_ADD_STORAGE_FILES);
buildPostBusinessObjectDataStorageFilesResponse(response, uri);
} else if (uri.getPath().equals("/herd-app/rest/businessObjectData")) {
checkHostname(request, HOSTNAME_THROW_IO_EXCEPTION_DURING_REGISTER_BDATA);
buildPostBusinessObjectDataResponse(response, uri);
} else if (uri.getPath().equals("/herd-app/rest/businessObjectData/search")) {
checkHostname(request, HOSTNAME_THROW_IO_EXCEPTION);
buildSearchBusinessObjectDataResponse(response, uri);
} else if (uri.getPath().startsWith("/herd-app/rest/businessObjectData/destroy")) {
checkHostname(request, HOSTNAME_THROW_IO_EXCEPTION);
buildPostBusinessObjectDataResponse(response, uri);
}
} else if (request instanceof HttpPut) {
if (uri.getPath().startsWith("/herd-app/rest/businessObjectDataStatus/")) {
checkHostname(request, HOSTNAME_THROW_IO_EXCEPTION_DURING_UPDATE_BDATA_STATUS);
buildPutBusinessObjectDataStatusResponse(response, uri);
}
}
// If requested, set response content to an invalid XML.
if (HOSTNAME_RESPOND_WITH_STATUS_CODE_200_AND_INVALID_CONTENT.equals(request.getURI().getHost())) {
response.setEntity(new StringEntity("invalid xml"));
}
LOGGER.debug("response = " + response);
return response;
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project herd by FINRAOS.
the class DataBridgeWebClientTest method testGetBusinessObjectDataStorageFilesCreateResponse400BadContentThrows.
@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 {
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());
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project herd by FINRAOS.
the class DataBridgeWebClientTest method testGetBusinessObjectDataStorageFilesCreateResponse200ValidResponse.
@Test
public void testGetBusinessObjectDataStorageFilesCreateResponse200ValidResponse() throws Exception {
CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "testReasonPhrase"), false);
httpResponse.setEntity(new StringEntity(xmlHelper.objectToXml(new BusinessObjectDataStorageFilesCreateResponse())));
BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse = dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse);
assertNotNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse);
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project herd by FINRAOS.
the class DownloaderWebClientTest method testGetBusinessObjectDataDownloadCredentialAssertNoAuthorizationHeaderWhenNoSsl.
@Test
public void testGetBusinessObjectDataDownloadCredentialAssertNoAuthorizationHeaderWhenNoSsl() throws Exception {
HttpClientOperations mockHttpClientOperations = mock(HttpClientOperations.class);
HttpClientOperations originalHttpClientOperations = (HttpClientOperations) ReflectionTestUtils.getField(downloaderWebClient, "httpClientOperations");
ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", mockHttpClientOperations);
try {
CloseableHttpResponse closeableHttpResponse = mock(CloseableHttpResponse.class);
when(mockHttpClientOperations.execute(any(), any())).thenReturn(closeableHttpResponse);
when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "SUCCESS"));
when(closeableHttpResponse.getEntity()).thenReturn(new StringEntity(xmlHelper.objectToXml(new StorageUnitDownloadCredential())));
DownloaderInputManifestDto downloaderInputManifestDto = new DownloaderInputManifestDto();
String storageName = "storageName";
boolean useSsl = false;
downloaderWebClient.getRegServerAccessParamsDto().setUseSsl(useSsl);
downloaderWebClient.getStorageUnitDownloadCredential(downloaderInputManifestDto, storageName);
verify(mockHttpClientOperations).execute(any(), argThat(httpUriRequest -> httpUriRequest.getFirstHeader("Authorization") == null));
} finally {
ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", originalHttpClientOperations);
}
}
Aggregations