use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.
the class DigestNotificationProcessorIT method processNotificationDataWithSameEventKeyTestIT.
@Test
public void processNotificationDataWithSameEventKeyTestIT() {
final Long distributionConfigId = 10L;
final String distributionType = SupportedChannels.HIPCHAT;
final String name = "Config Name";
final DigestTypeEnum frequency = DigestTypeEnum.REAL_TIME;
final Boolean filterByProject = true;
final String eventKey = "event_key";
final String projectName = "Test Hub Project Name";
final String projectVersionName = "Test Hub Project Version Name";
final CommonDistributionConfigEntity commonDistributionConfigEntity = commonDistributionRepository.save(new CommonDistributionConfigEntity(distributionConfigId, distributionType, name, frequency, filterByProject));
final ConfiguredProjectEntity configuredProjectEntity = configuredProjectsRepository.save(new ConfiguredProjectEntity(projectName));
distributionProjectRepository.save(new DistributionProjectRelation(commonDistributionConfigEntity.getId(), configuredProjectEntity.getId()));
final CommonDistributionConfigRestModel restModel = new CommonDistributionConfigRestModel(null, null, null, null, null, null, null, Arrays.asList("POLICY_VIOLATION"));
notificationActions.saveNotificationTypes(commonDistributionConfigEntity, restModel);
final List<NotificationModel> notificationList = new ArrayList<>();
final NotificationEntity applicableNotification = new NotificationEntity(eventKey, new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, projectName, "", projectVersionName, "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
final NotificationEntity otherApplicableNotification = new NotificationEntity(eventKey, new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, projectName, "", projectVersionName, "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
notificationList.add(new NotificationModel(applicableNotification, Collections.emptyList()));
notificationList.add(new NotificationModel(otherApplicableNotification, Collections.emptyList()));
final List<AbstractChannelEvent> eventsCreated = processor.processNotifications(DigestTypeEnum.REAL_TIME, notificationList);
assertEquals(1, eventsCreated.size());
final AbstractChannelEvent event = eventsCreated.get(0);
assertTrue(event instanceof HipChatEvent);
assertEquals(commonDistributionConfigEntity.getId(), event.getCommonDistributionConfigId());
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.
the class DigestNotificationProcessorIT method processNotificationDataWithNegatingTypesTestIT.
@Test
public void processNotificationDataWithNegatingTypesTestIT() {
final Long distributionConfigId = 10L;
final String distributionType = SupportedChannels.HIPCHAT;
final String name = "Config Name";
final DigestTypeEnum frequency = DigestTypeEnum.REAL_TIME;
final Boolean filterByProject = true;
final String eventKey = "event_key";
final String projectName = "Test Hub Project Name";
final String projectVersionName = "Test Hub Project Version Name";
final CommonDistributionConfigEntity commonDistributionConfigEntity = commonDistributionRepository.save(new CommonDistributionConfigEntity(distributionConfigId, distributionType, name, frequency, filterByProject));
final ConfiguredProjectEntity configuredProjectEntity = configuredProjectsRepository.save(new ConfiguredProjectEntity(projectName));
distributionProjectRepository.save(new DistributionProjectRelation(commonDistributionConfigEntity.getId(), configuredProjectEntity.getId()));
final CommonDistributionConfigRestModel restModel = new CommonDistributionConfigRestModel(null, null, null, null, null, null, null, Arrays.asList("POLICY_VIOLATION", "POLICY_VIOLATION_CLEARED"));
notificationActions.saveNotificationTypes(commonDistributionConfigEntity, restModel);
final List<NotificationModel> notificationList = new LinkedList<>();
final NotificationEntity applicableNotification = new NotificationEntity(eventKey, new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, projectName, "", projectVersionName, "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
final NotificationEntity nonApplicableNotification = new NotificationEntity(eventKey, new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION_CLEARED, projectName, "", projectVersionName, "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
notificationList.add(new NotificationModel(applicableNotification, Collections.emptyList()));
notificationList.add(new NotificationModel(nonApplicableNotification, Collections.emptyList()));
final List<AbstractChannelEvent> eventsCreated = processor.processNotifications(DigestTypeEnum.REAL_TIME, notificationList);
assertEquals(0, eventsCreated.size());
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.
the class DigestNotificationProcessorIT method processNotificationDataBasicTestIT.
@Test
public void processNotificationDataBasicTestIT() {
final Long distributionConfigId = 10L;
final String distributionType = SupportedChannels.HIPCHAT;
final String name = "Config Name";
final DigestTypeEnum frequency = DigestTypeEnum.REAL_TIME;
final Boolean filterByProject = true;
final String projectName = "Test Hub Project Name";
final CommonDistributionConfigEntity commonDistributionConfigEntity = commonDistributionRepository.save(new CommonDistributionConfigEntity(distributionConfigId, distributionType, name, frequency, filterByProject));
final ConfiguredProjectEntity configuredProjectEntity = configuredProjectsRepository.save(new ConfiguredProjectEntity(projectName));
distributionProjectRepository.save(new DistributionProjectRelation(commonDistributionConfigEntity.getId(), configuredProjectEntity.getId()));
final CommonDistributionConfigRestModel restModel = new CommonDistributionConfigRestModel(null, null, null, null, null, null, null, Arrays.asList("POLICY_VIOLATION"));
notificationActions.saveNotificationTypes(commonDistributionConfigEntity, restModel);
final List<NotificationModel> notificationList = new ArrayList<>();
final NotificationEntity applicableNotification = new NotificationEntity("event_key_1", new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, projectName, "", "", "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
final NotificationEntity nonApplicableNotification = new NotificationEntity("event_key_2", new Date(System.currentTimeMillis()), NotificationCategoryEnum.POLICY_VIOLATION, "Project that we don't care about", "", "", "", "Test Component", "Test Component Version", "Test Policy Rule Name", "Test Person");
notificationList.add(new NotificationModel(applicableNotification, Collections.emptyList()));
notificationList.add(new NotificationModel(nonApplicableNotification, Collections.emptyList()));
final List<AbstractChannelEvent> eventsCreated = processor.processNotifications(DigestTypeEnum.REAL_TIME, notificationList);
assertEquals(1, eventsCreated.size());
final AbstractChannelEvent event = eventsCreated.get(0);
assertTrue(event instanceof HipChatEvent);
assertEquals(commonDistributionConfigEntity.getId(), event.getCommonDistributionConfigId());
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity 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());
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity in project hub-alert by blackducksoftware.
the class CommonConfigHandlerTest method putWithInvalidConfigTest.
@Test
public void putWithInvalidConfigTest() throws AlertFieldException {
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.when(configActions.validateConfig(Mockito.any())).thenThrow(new AlertFieldException(Collections.emptyMap()));
Mockito.when(configActions.getObjectTransformer()).thenReturn(objectTransformer);
final CommonDistributionConfigRestModel restModel = mockCommonDistributionRestModel.createRestModel();
final ResponseEntity<String> response = handler.putConfig(restModel);
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
Aggregations