use of org.apache.http.StatusLine in project nhin-d by DirectProject.
the class UnsecureServiceRequestBase_callTest method testCall_callWithNoReturnValue.
@Test
public void testCall_callWithNoReturnValue() throws Exception {
HttpClient mockClient = mock(HttpClient.class);
StatusLine statLine = mock(StatusLine.class);
when(statLine.getStatusCode()).thenReturn(204);
HttpResponse resp = mock(HttpResponse.class);
when(resp.getStatusLine()).thenReturn(statLine);
when(mockClient.execute((HttpUriRequest) any())).thenReturn(resp);
MockServiceRequest req = new MockServiceRequest(mockClient, "http://service/svc", "Test");
assertNull(req.call());
}
use of org.apache.http.StatusLine in project nhin-d by DirectProject.
the class UnsecureServiceRequestBase_callTest method testCall_nullRequest_assertServiceException.
@Test
public void testCall_nullRequest_assertServiceException() throws Exception {
HttpClient mockClient = mock(HttpClient.class);
StatusLine statLine = mock(StatusLine.class);
when(statLine.getStatusCode()).thenReturn(204);
HttpResponse resp = mock(HttpResponse.class);
when(resp.getStatusLine()).thenReturn(statLine);
when(mockClient.execute((HttpUriRequest) any())).thenReturn(resp);
MockServiceRequest req = new MockServiceRequest(mockClient, "http://service/svc", "");
boolean exceptionOccured = false;
try {
req.call();
} catch (ServiceException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
use of org.apache.http.StatusLine in project c4sg-services by Code4SocialGood.
the class StringResponseHandler method handleResponse.
@Override
public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
final StatusLine statusLine = response.getStatusLine();
int status = statusLine.getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
} else {
throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
}
use of org.apache.http.StatusLine in project wildfly by wildfly.
the class WebSecurityCERTTestCase method makeCall.
protected void makeCall(String alias, int expectedStatusCode) throws Exception {
try (CloseableHttpClient httpclient = getHttpsClient(alias)) {
HttpGet httpget = new HttpGet("https://" + mgmtClient.getMgmtAddress() + ":8380/web-secure-client-cert/secured/");
HttpResponse response = httpclient.execute(httpget);
StatusLine statusLine = response.getStatusLine();
assertEquals(expectedStatusCode, statusLine.getStatusCode());
}
}
use of org.apache.http.StatusLine in project wildfly by wildfly.
the class WebSecurityExternalAuthTestCase method makeCall.
protected void makeCall(String user, int expectedStatusCode) throws Exception {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpget = new HttpGet(url.toExternalForm() + "secured/");
httpget.addHeader("User", user);
HttpResponse response = httpClient.execute(httpget);
HttpEntity entity = response.getEntity();
StatusLine statusLine = response.getStatusLine();
assertEquals(expectedStatusCode, statusLine.getStatusCode());
EntityUtils.consume(entity);
}
}
Aggregations