use of org.apache.http.message.BasicHttpResponse 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.apache.http.message.BasicHttpResponse 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.apache.http.message.BasicHttpResponse 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.apache.http.message.BasicHttpResponse 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.apache.http.message.BasicHttpResponse 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