Search in sources :

Example 6 with IntegrationException

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());
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 7 with IntegrationException

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();
    }
}
Also used : Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test) HubConnectionTest(com.blackducksoftware.integration.test.annotation.HubConnectionTest)

Example 8 with IntegrationException

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());
    }
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException)

Example 9 with IntegrationException

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());
    }
}
Also used : IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Example 10 with IntegrationException

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.";
}
Also used : Response(com.blackducksoftware.integration.hub.request.Response) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) HashMap(java.util.HashMap) Request(com.blackducksoftware.integration.hub.request.Request) ChannelRequestHelper(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRequestHelper)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)24 Test (org.junit.Test)12 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)5 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)5 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)4 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)4 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)3 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 GlobalHipChatConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity)3 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)3 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)3 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)3 Request (com.blackducksoftware.integration.hub.request.Request)3 UserGroupService (com.blackducksoftware.integration.hub.service.UserGroupService)3 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)3 HashMap (java.util.HashMap)3 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)2 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)2 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)2