Search in sources :

Example 6 with AlertException

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

the class CommonConfigHandlerTest method getConfigHandleExceptionTest.

@Test
public void getConfigHandleExceptionTest() throws AlertException {
    final CommonDistributionConfigActions configActions = Mockito.mock(CommonDistributionConfigActions.class);
    final CommonConfigHandler<CommonDistributionConfigEntity, CommonDistributionConfigRestModel, CommonDistributionRepositoryWrapper> handler = new CommonConfigHandler<>(CommonDistributionConfigEntity.class, CommonDistributionConfigRestModel.class, configActions, objectTransformer);
    Mockito.when(configActions.getConfig(Mockito.anyLong())).thenThrow(new AlertException());
    Exception thrownException = null;
    List<CommonDistributionConfigRestModel> list = null;
    try {
        list = handler.getConfig(1L);
    } catch (final Exception e) {
        thrownException = e;
    }
    assertNull(thrownException);
    assertEquals(Collections.emptyList(), list);
}
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) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Test(org.junit.Test)

Example 7 with AlertException

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

the class HubDataActionsTest method testGetHubGroupsNullHubServicesFactory.

@Test
public void testGetHubGroupsNullHubServicesFactory() 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.getHubGroups();
        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 8 with AlertException

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

the class ActionsTest method testSaveConfig.

@Test
public void testSaveConfig() throws Exception {
    final E expectedConfigEntity = getEntityMockUtil().createEntity();
    Mockito.when(configActions.getRepository().save(Mockito.any(getConfigEntityClass()))).thenReturn(expectedConfigEntity);
    Mockito.when(configActions.getCommonDistributionRepository().save(Mockito.any(CommonDistributionConfigEntity.class))).thenReturn(distributionMockUtils.createEntity());
    Mockito.when(configActions.getConfiguredProjectsActions().getConfiguredProjectsRepository().findByProjectName(projectMockUtils.getProjectOne())).thenReturn(projectMockUtils.getProjectOneEntity());
    Mockito.when(configActions.getConfiguredProjectsActions().getConfiguredProjectsRepository().findByProjectName(projectMockUtils.getProjectTwo())).thenReturn(projectMockUtils.getProjectTwoEntity());
    Mockito.when(configActions.getConfiguredProjectsActions().getConfiguredProjectsRepository().findByProjectName(projectMockUtils.getProjectThree())).thenReturn(projectMockUtils.getProjectThreeEntity());
    Mockito.when(configActions.getConfiguredProjectsActions().getConfiguredProjectsRepository().findByProjectName(projectMockUtils.getProjectFour())).thenReturn(projectMockUtils.getProjectFourEntity());
    Mockito.when(configActions.getNotificationTypesActions().getNotificationTypeRepository().findByType(notificationMockUtil.getType())).thenReturn(notificationMockUtil.createEntity());
    E actualConfigEntity = configActions.saveConfig(getRestMockUtil().createRestModel());
    assertNotNull(actualConfigEntity);
    assertEquals(expectedConfigEntity, actualConfigEntity);
    actualConfigEntity = configActions.saveConfig(null);
    assertNull(actualConfigEntity);
    Mockito.when(configActions.getRepository().save(Mockito.any(getConfigEntityClass()))).thenThrow(new RuntimeException("test"));
    try {
        actualConfigEntity = configActions.saveConfig(getRestMockUtil().createRestModel());
        fail();
    } catch (final AlertException e) {
        assertEquals("test", e.getMessage());
    }
    final ObjectTransformer transformer = Mockito.mock(ObjectTransformer.class);
    Mockito.when(transformer.configRestModelToDatabaseEntity(Mockito.any(), Mockito.any())).thenReturn(null);
    configActions = createMockedConfigActionsUsingObjectTransformer(transformer);
    actualConfigEntity = configActions.saveConfig(getRestMockUtil().createRestModel());
    assertNull(actualConfigEntity);
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) Test(org.junit.Test)

Example 9 with AlertException

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

the class GlobalActionsTest method testSaveConfig.

@Test
public void testSaveConfig() throws Exception {
    final GE expectedHipChatConfigEntity = getGlobalEntityMockUtil().createGlobalEntity();
    Mockito.when(configActions.getRepository().save(Mockito.any(getGlobalEntityClass()))).thenReturn(expectedHipChatConfigEntity);
    GE emailConfigEntity = configActions.saveConfig(getGlobalRestModelMockUtil().createGlobalRestModel());
    assertNotNull(emailConfigEntity);
    assertEquals(expectedHipChatConfigEntity, emailConfigEntity);
    emailConfigEntity = configActions.saveConfig(null);
    assertNull(emailConfigEntity);
    Mockito.when(configActions.getRepository().save(Mockito.any(getGlobalEntityClass()))).thenThrow(new RuntimeException("test"));
    try {
        emailConfigEntity = configActions.saveConfig(getGlobalRestModelMockUtil().createGlobalRestModel());
        fail();
    } catch (final AlertException e) {
        assertEquals("test", e.getMessage());
    }
    final ObjectTransformer transformer = Mockito.mock(ObjectTransformer.class);
    Mockito.when(transformer.configRestModelToDatabaseEntity(Mockito.any(), Mockito.any())).thenReturn(null);
    configActions = createMockedConfigActionsUsingObjectTransformer(transformer);
    emailConfigEntity = configActions.saveConfig(getGlobalRestModelMockUtil().createGlobalRestModel());
    assertNull(emailConfigEntity);
}
Also used : ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) Test(org.junit.Test)

Example 10 with AlertException

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

the class HubDataActions method getHubProjects.

public List<HubProject> getHubProjects() throws IntegrationException {
    final HubServicesFactory hubServicesFactory = globalProperties.createHubServicesFactory(logger);
    if (hubServicesFactory != null) {
        final List<ProjectView> rawProjects = hubServicesFactory.createHubService().getAllResponses(ApiDiscovery.PROJECTS_LINK_RESPONSE);
        final List<HubProject> projects = new ArrayList<>();
        for (final ProjectView projectView : rawProjects) {
            final HubProject project = new HubProject(projectView.name);
            projects.add(project);
        }
        return projects;
    } else {
        throw new AlertException("Missing global configuration.");
    }
}
Also used : ArrayList(java.util.ArrayList) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) ProjectView(com.blackducksoftware.integration.hub.api.generated.view.ProjectView) HubProject(com.blackducksoftware.integration.hub.alert.hub.model.HubProject) 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