use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project herd by FINRAOS.
the class DownloaderWebClientTest method testGetBusinessObjectDataDownloadCredentialAssertThrowIOExceptionWhenClosingHttpClientThrowsIOException.
/**
* Asserts that the http client is closed and if an exception is thrown during closing of the http client, the same exception is bubbled up.
*/
@Test
public void testGetBusinessObjectDataDownloadCredentialAssertThrowIOExceptionWhenClosingHttpClientThrowsIOException() throws Exception {
HttpClientOperations mockHttpClientOperations = mock(HttpClientOperations.class);
HttpClientOperations originalHttpClientOperations = (HttpClientOperations) ReflectionTestUtils.getField(downloaderWebClient, "httpClientOperations");
ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", mockHttpClientOperations);
try {
CloseableHttpClient closeableHttpClient = mock(CloseableHttpClient.class);
when(mockHttpClientOperations.createHttpClient()).thenReturn(closeableHttpClient);
doThrow(IOException.class).when(closeableHttpClient).close();
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";
try {
downloaderWebClient.getStorageUnitDownloadCredential(downloaderInputManifestDto, storageName);
verify(closeableHttpClient).close();
fail();
} catch (Exception e) {
assertEquals(IOException.class, e.getClass());
}
} finally {
ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", originalHttpClientOperations);
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project scribejava by scribejava.
the class OauthAsyncCompletionHandlerTest method shouldReleaseLatchOnFailure.
@Test
public void shouldReleaseLatchOnFailure() throws Exception {
handler = new OAuthAsyncCompletionHandler<>(callback, ALL_GOOD_RESPONSE_CONVERTER);
final HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok"));
final BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream(new byte[0]));
response.setEntity(entity);
handler.failed(new RuntimeException());
assertNull(callback.getResponse());
assertNotNull(callback.getThrowable());
assertTrue(callback.getThrowable() instanceof RuntimeException);
// verify latch is released
try {
handler.getResult();
fail();
} catch (ExecutionException expected) {
// expected
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project scribejava by scribejava.
the class OauthAsyncCompletionHandlerTest method shouldReleaseLatchOnIOException.
@Test
public void shouldReleaseLatchOnIOException() throws Exception {
handler = new OAuthAsyncCompletionHandler<>(callback, EXCEPTION_RESPONSE_CONVERTER);
final HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("4", 1, 1), 200, "ok"));
final BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(new ByteArrayInputStream(new byte[0]));
response.setEntity(entity);
handler.completed(response);
assertNull(callback.getResponse());
assertNotNull(callback.getThrowable());
assertTrue(callback.getThrowable() instanceof IOException);
// verify latch is released
try {
handler.getResult();
fail();
} catch (ExecutionException expected) {
// expected
}
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project opencast by opencast.
the class JobUtilTest method testJobFromHttpResponse.
@Test
public void testJobFromHttpResponse() throws Exception {
BasicHttpResponse response = new BasicHttpResponse(new BasicStatusLine(new HttpVersion(1, 1), HttpStatus.SC_NO_CONTENT, "No message"));
Option<Job> job = JobUtil.jobFromHttpResponse.apply(response);
assertFalse(job.isSome());
JaxbJob jaxbJob = new JaxbJob(new JobImpl(32));
response.setEntity(new StringEntity(JobParser.toXml(jaxbJob), StandardCharsets.UTF_8));
job = JobUtil.jobFromHttpResponse.apply(response);
assertTrue(job.isSome());
assertEquals(jaxbJob.toJob(), job.get());
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.message.BasicStatusLine in project opencast by opencast.
the class TrustedHttpClientImplTest method testNotAcceptsUrlSigningService.
@Test
public void testNotAcceptsUrlSigningService() throws IOException {
String notAcceptsUrl = "http://notaccepts.com";
HttpGet get = new HttpGet(notAcceptsUrl);
// Setup signing service
UrlSigningService urlSigningService = EasyMock.createMock(UrlSigningService.class);
EasyMock.expect(urlSigningService.accepts(notAcceptsUrl)).andReturn(false);
EasyMock.replay(urlSigningService);
CredentialsProvider cp = EasyMock.createNiceMock(CredentialsProvider.class);
Capture<HttpUriRequest> request = EasyMock.newCapture();
// Setup Http Client
HttpClient httpClient = createMock("Request", HttpClient.class);
HttpParams httpParams = createNiceMock(HttpParams.class);
expect(httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000)).andReturn(httpParams);
expect(httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)).andReturn(httpParams);
replay(httpParams);
expect(httpClient.getParams()).andReturn(httpParams).anyTimes();
expect(httpClient.getCredentialsProvider()).andReturn(cp);
expect(httpClient.execute(EasyMock.capture(request))).andReturn(new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "ok")));
EasyMock.replay(httpClient);
// Setup DefaultHttpClientFactory
HttpClientFactory httpClientFactory = createMock(HttpClientFactory.class);
expect(httpClientFactory.makeHttpClient()).andReturn(httpClient).atLeastOnce();
replay(httpClientFactory);
client = new TrustedHttpClientImpl("user", "pass");
client.setHttpClientFactory(httpClientFactory);
client.setSecurityService(securityService);
client.setUrlSigningService(urlSigningService);
client.execute(get);
assertTrue(request.hasCaptured());
assertEquals(get.getURI().toString(), request.getValue().getURI().toString());
}
Aggregations