use of com.synopsys.integration.rest.response.Response in project hub-alert by blackducksoftware.
the class ExternalAlertRequestUtility method executeRequest.
private String executeRequest(String path, HttpMethod httpMethod, String requestBody, String error) throws IntegrationException {
BodyContent requestBodyContent = new StringBodyContent(requestBody, BodyContentConverter.DEFAULT);
Request.Builder requestBuilder = createRequestBuilder(path);
requestBuilder.method(httpMethod);
if (null != requestBody) {
requestBuilder.bodyContent(requestBodyContent);
}
Request request = requestBuilder.build();
Response response = client.execute(request);
if (response.isStatusCodeError()) {
intLogger.error(error);
response.throwExceptionForError();
}
return response.getContentString();
}
use of com.synopsys.integration.rest.response.Response in project hub-alert by blackducksoftware.
the class ExternalAlertRequestUtility method loginToExternalAlert.
public void loginToExternalAlert() throws IntegrationException {
String loginBody = "{\"alertUsername\":\"sysadmin\",\"alertPassword\":\"blackduck\"}";
BodyContent requestBody = new StringBodyContent(loginBody, BodyContentConverter.DEFAULT);
Request.Builder requestBuilder = createRequestBuilder("/api/login");
requestBuilder.method(HttpMethod.POST);
requestBuilder.bodyContent(requestBody);
Request request = requestBuilder.build();
Response response = client.execute(request);
if (response.isStatusCodeError()) {
intLogger.error("Could not log into Alert.");
response.throwExceptionForError();
}
String csrfToken = response.getHeaderValue("X-CSRF-TOKEN");
String cookie = response.getHeaderValue("Set-Cookie");
client.addCommonRequestHeader("X-CSRF-TOKEN", csrfToken);
client.addCommonRequestHeader("Cookie", cookie);
intLogger.info("Logged into Alert.");
}
use of com.synopsys.integration.rest.response.Response in project hub-alert by blackducksoftware.
the class RestChannelUtilityTest method sendMessageSuccessTest.
@Test
public void sendMessageSuccessTest() throws IntegrationException {
Response response = createMockResponse(HttpStatus.OK);
IntHttpClient intHttpClient = createMockHttpClientWithResponse(response);
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
try {
restChannelUtility.sendMessage(List.of(TEST_REQUEST, TEST_REQUEST), CLASS_NAME);
} catch (AlertException e) {
fail("Expected no exception to be thrown", e);
}
}
use of com.synopsys.integration.rest.response.Response in project hub-alert by blackducksoftware.
the class RestChannelUtilityTest method sendMessageAlertExceptionTest.
@Test
public void sendMessageAlertExceptionTest() throws IntegrationException {
Response response = createMockResponse(HttpStatus.BAD_REQUEST);
IntHttpClient intHttpClient = createMockHttpClientWithResponse(response);
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
try {
restChannelUtility.sendMessage(List.of(TEST_REQUEST, TEST_REQUEST), CLASS_NAME);
fail("Expected an exception to be thrown");
} catch (AlertException e) {
// Pass
}
}
use of com.synopsys.integration.rest.response.Response in project hub-alert by blackducksoftware.
the class RestChannelUtilityTest method createMockResponse.
private Response createMockResponse(HttpStatus httpStatus) {
Response response = Mockito.mock(Response.class);
Mockito.when(response.getStatusCode()).thenReturn(httpStatus.value());
Mockito.when(response.getStatusMessage()).thenReturn(httpStatus.name());
return response;
}
Aggregations