use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class HubDataHandlerTest method testGetHubGroupsThrowIntegrationException.
@Test
public void testGetHubGroupsThrowIntegrationException() throws Exception {
final ObjectTransformer objectTransformer = new ObjectTransformer();
final Gson gson = new Gson();
final HubDataActions hubDataActions = Mockito.mock(HubDataActions.class);
Mockito.when(hubDataActions.getHubGroups()).thenThrow(new IntegrationException("ErrorMessage"));
final HubDataHandler hubDataHandler = new HubDataHandler(objectTransformer, gson, hubDataActions);
final ResponseEntity<String> responseEntity = hubDataHandler.getHubGroups();
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
assertEquals("{\"id\":-1,\"message\":\"ErrorMessage\"}", responseEntity.getBody());
}
use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class LoginActionsTestIT method testValidateHubConfigurationException.
@Test
public void testValidateHubConfigurationException() {
mockLoginRestModel.setHubUsername(null);
final LoginActions loginActions = new LoginActions(new TestGlobalProperties());
try {
final boolean authenticated = loginActions.authenticateUser(mockLoginRestModel.createRestModel(), new Slf4jIntLogger(logger));
assertFalse(authenticated);
} catch (final IntegrationException e) {
fail();
}
}
use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class DistributionChannel method handleEvent.
public void handleEvent(final E event) {
final Long eventDistributionId = event.getCommonDistributionConfigId();
final CommonDistributionConfigEntity commonDistributionEntity = getCommonDistributionRepository().findOne(eventDistributionId);
if (event.getTopic().equals(commonDistributionEntity.getDistributionType())) {
try {
final Long channelDistributionConfigId = commonDistributionEntity.getDistributionConfigId();
final C channelDistributionEntity = distributionRepository.findOne(channelDistributionConfigId);
sendAuditedMessage(event, channelDistributionEntity);
} catch (final IntegrationException ex) {
logger.error("There was an error sending the message.", ex);
}
} else {
logger.warn("Received an event of type '{}', but the retrieved configuration was for an event of type '{}'.", event.getTopic(), commonDistributionEntity.getDistributionType());
}
}
use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class DistributionChannel method sendAuditedMessage.
public void sendAuditedMessage(final E event, final C config) throws IntegrationException {
try {
sendMessage(event, config);
setAuditEntrySuccess(event.getAuditEntryId());
} catch (final Exception e) {
setAuditEntryFailure(event.getAuditEntryId(), e.getMessage(), e);
if (e instanceof IntegrationRestException) {
logger.error(((IntegrationRestException) e).getHttpStatusCode() + ":" + ((IntegrationRestException) e).getHttpStatusMessage());
}
logger.error(e.getMessage(), e);
throw new AlertException(e.getMessage());
}
}
use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class HipChatChannel method testGlobalConfig.
@Override
public String testGlobalConfig(final GlobalHipChatConfigEntity entity) throws IntegrationException {
if (entity == null) {
return "The provided entity was null.";
}
if (StringUtils.isBlank(entity.getApiKey())) {
throw new IntegrationException("Invalid API key: API key not provided");
}
final RestConnection restConnection = channelRestConnectionFactory.createUnauthenticatedRestConnection(HIP_CHAT_API);
if (restConnection != null) {
try {
final String url = HIP_CHAT_API + "/v2/room/*/notification";
final Map<String, String> queryParameters = new HashMap<>();
queryParameters.put("auth_test", "true");
final Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("Authorization", "Bearer " + entity.getApiKey());
requestHeaders.put("Content-Type", "application/json");
// The {"message":"test"} is required to avoid a BAD_REQUEST (OkHttp issue: #854)
final ChannelRequestHelper channelRequestHelper = new ChannelRequestHelper(restConnection);
final Request request = channelRequestHelper.createPostMessageRequest(url, requestHeaders, queryParameters, "{\"message\":\"test\"}");
final Response response = channelRequestHelper.sendGenericRequest(request);
if (response.getStatusCode() >= 200 && response.getStatusCode() < 400) {
return "API key is valid.";
}
return "Invalid API key: " + response.getStatusMessage();
} catch (final IntegrationException e) {
restConnection.logger.error("Unable to create a response", e);
throw new IntegrationException("Invalid API key: " + e.getMessage());
}
}
return "Connection error: see logs for more information.";
}
Aggregations