Search in sources :

Example 21 with AlertException

use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.

the class HubDataActionsTest method testGetHubProjectsNullHubServicesFactory.

@Test
public void testGetHubProjectsNullHubServicesFactory() throws Exception {
    final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
    Mockito.when(globalProperties.createHubServicesFactory(Mockito.any(Logger.class))).thenReturn(null);
    final HubDataActions hubDataActions = new HubDataActions(globalProperties);
    try {
        hubDataActions.getHubProjects();
        fail();
    } catch (final AlertException e) {
        assertEquals("Missing global configuration.", e.getMessage());
    }
}
Also used : GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) Logger(org.slf4j.Logger) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) Test(org.junit.Test)

Example 22 with AlertException

use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.

the class CommonConfigHandlerTest method putWithInternalServerErrorTest.

@Test
public void putWithInternalServerErrorTest() throws IntegrationException {
    final CommonDistributionConfigActions configActions = Mockito.mock(CommonDistributionConfigActions.class);
    final CommonConfigHandler<CommonDistributionConfigEntity, CommonDistributionConfigRestModel, CommonDistributionRepositoryWrapper> handler = new CommonConfigHandler<>(CommonDistributionConfigEntity.class, CommonDistributionConfigRestModel.class, configActions, objectTransformer);
    Mockito.when(configActions.doesConfigExist(Mockito.anyString())).thenReturn(true);
    Mockito.doNothing().when(configActions).configurationChangeTriggers(Mockito.any());
    Mockito.when(configActions.saveNewConfigUpdateFromSavedConfig(Mockito.any())).thenThrow(new AlertException());
    final CommonDistributionConfigRestModel restModel = mockCommonDistributionRestModel.createRestModel();
    final ResponseEntity<String> response = handler.putConfig(restModel);
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
}
Also used : CommonDistributionConfigActions(com.blackducksoftware.integration.hub.alert.web.actions.distribution.CommonDistributionConfigActions) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) Test(org.junit.Test)

Example 23 with AlertException

use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.

the class ChannelRequestHelper method sendGenericRequest.

public Response sendGenericRequest(final Request request) throws IntegrationException {
    Response response = null;
    try {
        final HubService service = hubServicesFactory.createHubService();
        response = service.executeRequest(request);
        logger.trace("Response: " + response.toString());
        return response;
    } catch (final Exception generalException) {
        logger.error("Error sending request", generalException);
        throw new AlertException(generalException.getMessage());
    }
}
Also used : Response(com.blackducksoftware.integration.hub.request.Response) HubService(com.blackducksoftware.integration.hub.service.HubService) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Example 24 with AlertException

use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.

the class HubDataActions method getHubGroups.

public List<HubGroup> getHubGroups() throws IntegrationException {
    final HubServicesFactory hubServicesFactory = globalProperties.createHubServicesFactory(logger);
    if (hubServicesFactory != null) {
        final List<UserGroupView> rawGroups = hubServicesFactory.createHubService().getAllResponses(ApiDiscovery.USERGROUPS_LINK_RESPONSE);
        final List<HubGroup> groups = new ArrayList<>();
        for (final UserGroupView userGroupView : rawGroups) {
            final HubGroup hubGroup = new HubGroup(userGroupView.name, userGroupView.active, userGroupView._meta.href);
            groups.add(hubGroup);
        }
        return groups;
    } else {
        throw new AlertException("Missing global configuration.");
    }
}
Also used : UserGroupView(com.blackducksoftware.integration.hub.api.generated.view.UserGroupView) ArrayList(java.util.ArrayList) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) HubGroup(com.blackducksoftware.integration.hub.alert.hub.model.HubGroup) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Aggregations

AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)24 Test (org.junit.Test)9 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)8 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)8 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)6 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)5 ObjectTransformer (com.blackducksoftware.integration.hub.alert.web.ObjectTransformer)5 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)5 ArrayList (java.util.ArrayList)4 Logger (org.slf4j.Logger)4 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)3 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)3 DistributionChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity)3 GlobalChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity)3 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)3 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)3 Field (java.lang.reflect.Field)3 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)2