Search in sources :

Example 1 with CommonDistributionConfigRestModel

use of com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel in project hub-alert by blackducksoftware.

the class CommonDistributionConfigActionsTestIT method saveAndGetTestIT.

@Test
public void saveAndGetTestIT() throws AlertException {
    final String distributionType = null;
    final String name = "My Config";
    final String frequency = "DAILY";
    final String filterByProject = "true";
    final List<String> projectList = Arrays.asList("Project 1", "Project 2", "Project 3");
    final List<String> notificationTypeList = Arrays.asList("POLICY_VIOLATION", "VULNERABILITY");
    final Date lastRan = new Date(System.currentTimeMillis());
    final StatusEnum status = StatusEnum.SUCCESS;
    auditEntryRepository.save(new AuditEntryEntity(new Long(-1), lastRan, lastRan, status, "", ""));
    final CommonDistributionConfigRestModel commonDistributionConfigRestModel = new CommonDistributionConfigRestModel(null, null, distributionType, name, frequency, filterByProject, projectList, notificationTypeList);
    final CommonDistributionConfigActions commonDistributionConfigActions = new CommonDistributionConfigActions(commonDistributionRepository, auditEntryRepository, configuredProjectsActions, notificationTypesActions, objectTransformer);
    final CommonDistributionConfigEntity savedEntity = commonDistributionConfigActions.saveConfig(commonDistributionConfigRestModel);
    assertEquals(distributionType, savedEntity.getDistributionType());
    assertEquals(name, savedEntity.getName());
    assertEquals(frequency, savedEntity.getFrequency().name());
    assertEquals(filterByProject, savedEntity.getFilterByProject().toString());
    assertEquals(projectList.size(), configuredProjectsActions.getDistributionProjectRepository().count());
    assertEquals(projectList.size(), configuredProjectsActions.getConfiguredProjectsRepository().count());
    assertEquals(notificationTypeList.size(), notificationTypesActions.getDistributionNotificationTypeRepository().count());
    assertEquals(notificationTypeList.size(), notificationTypesActions.getNotificationTypeRepository().count());
    final CommonDistributionConfigRestModel updatedRestModel = objectTransformer.databaseEntityToConfigRestModel(savedEntity, CommonDistributionConfigRestModel.class);
    commonDistributionConfigActions.saveConfig(updatedRestModel);
    assertEquals(projectList.size(), configuredProjectsActions.getDistributionProjectRepository().count());
    assertEquals(projectList.size(), configuredProjectsActions.getConfiguredProjectsRepository().count());
    assertEquals(notificationTypeList.size(), notificationTypesActions.getDistributionNotificationTypeRepository().count());
    assertEquals(notificationTypeList.size(), notificationTypesActions.getNotificationTypeRepository().count());
    final List<CommonDistributionConfigRestModel> foundRestModels = commonDistributionConfigActions.getConfig(savedEntity.getId());
    assertEquals(1, foundRestModels.size());
    final CommonDistributionConfigRestModel foundRestModel = foundRestModels.get(0);
    assertEquals(savedEntity.getId(), objectTransformer.stringToLong(foundRestModel.getId()));
    assertEquals(savedEntity.getDistributionConfigId(), objectTransformer.stringToLong(foundRestModel.getDistributionConfigId()));
    assertEquals(savedEntity.getDistributionType(), foundRestModel.getDistributionType());
    assertEquals(savedEntity.getFilterByProject(), objectTransformer.stringToBoolean(foundRestModel.getFilterByProject()));
    assertEquals(projectList, foundRestModel.getConfiguredProjects());
}
Also used : StatusEnum(com.blackducksoftware.integration.hub.alert.enumeration.StatusEnum) CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) Date(java.util.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 2 with CommonDistributionConfigRestModel

use of com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel in project hub-alert by blackducksoftware.

the class CommonConfigHandlerTest method testConfigWithExceptionTest.

@Test
public void testConfigWithExceptionTest() throws Exception {
    final CommonDistributionConfigActions configActions = Mockito.mock(CommonDistributionConfigActions.class);
    final CommonConfigHandler<CommonDistributionConfigEntity, CommonDistributionConfigRestModel, CommonDistributionRepositoryWrapper> handler = new CommonConfigHandler<>(CommonDistributionConfigEntity.class, CommonDistributionConfigRestModel.class, configActions, objectTransformer);
    Mockito.when(configActions.testConfig(Mockito.any())).thenThrow(new NullPointerException());
    Mockito.when(configActions.getObjectTransformer()).thenReturn(objectTransformer);
    final CommonDistributionConfigRestModel restModel = mockCommonDistributionRestModel.createRestModel();
    final ResponseEntity<String> response = handler.testConfig(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) Test(org.junit.Test)

Example 3 with CommonDistributionConfigRestModel

use of com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel in project hub-alert by blackducksoftware.

the class CommonConfigHandlerTest method testConfigWithAlertFieldExceptionTest.

@Test
public void testConfigWithAlertFieldExceptionTest() throws Exception {
    final CommonDistributionConfigActions configActions = Mockito.mock(CommonDistributionConfigActions.class);
    final CommonConfigHandler<CommonDistributionConfigEntity, CommonDistributionConfigRestModel, CommonDistributionRepositoryWrapper> handler = new CommonConfigHandler<>(CommonDistributionConfigEntity.class, CommonDistributionConfigRestModel.class, configActions, objectTransformer);
    Mockito.when(configActions.testConfig(Mockito.any())).thenThrow(new AlertFieldException(Collections.emptyMap()));
    Mockito.when(configActions.getObjectTransformer()).thenReturn(objectTransformer);
    final CommonDistributionConfigRestModel restModel = mockCommonDistributionRestModel.createRestModel();
    final ResponseEntity<String> response = handler.testConfig(restModel);
    assertEquals(HttpStatus.BAD_REQUEST, 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) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) Test(org.junit.Test)

Example 4 with CommonDistributionConfigRestModel

use of com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel 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 5 with CommonDistributionConfigRestModel

use of com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel in project hub-alert by blackducksoftware.

the class CommonConfigHandlerTest method testConfigTest.

@Test
public void testConfigTest() {
    final CommonDistributionConfigActions configActions = Mockito.mock(CommonDistributionConfigActions.class);
    final CommonConfigHandler<CommonDistributionConfigEntity, CommonDistributionConfigRestModel, CommonDistributionRepositoryWrapper> handler = new CommonConfigHandler<>(CommonDistributionConfigEntity.class, CommonDistributionConfigRestModel.class, configActions, objectTransformer);
    final CommonDistributionConfigRestModel restModel = mockCommonDistributionRestModel.createRestModel();
    final ResponseEntity<String> response = handler.testConfig(restModel);
    assertEquals(HttpStatus.OK, 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) Test(org.junit.Test)

Aggregations

CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)24 Test (org.junit.Test)23 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)22 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)18 CommonDistributionConfigActions (com.blackducksoftware.integration.hub.alert.web.actions.distribution.CommonDistributionConfigActions)18 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)5 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)4 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)4 Date (java.util.Date)4 ConfiguredProjectEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)3 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)3 DistributionProjectRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)3 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)3 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)3 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)3 HipChatEvent (com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent)2 IntegrationRestException (com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException)2 ArrayList (java.util.ArrayList)2 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)1