Search in sources :

Example 1 with HipChatEvent

use of com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent in project hub-alert by blackducksoftware.

the class ChannelTemplateManagerTest method testSendEvents.

@Test
public void testSendEvents() {
    final MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
    final AuditEntryRepositoryWrapper auditEntryRepositoryWrapper = Mockito.mock(AuditEntryRepositoryWrapper.class);
    Mockito.when(auditEntryRepositoryWrapper.save(Mockito.any(AuditEntryEntity.class))).thenReturn(mockAuditEntryEntity.createEntity());
    final ChannelTemplateManager channelTemplateManager = new ChannelTemplateManager(new Gson(), auditEntryRepositoryWrapper, null, null) {

        @Override
        public boolean hasTemplate(final String destination) {
            return true;
        }

        @Override
        public AbstractJmsTemplate getTemplate(final String destination) {
            testCount++;
            final AbstractJmsTemplate abstractJmsTemplate = Mockito.mock(AbstractJmsTemplate.class);
            Mockito.doNothing().when(abstractJmsTemplate).convertAndSend(Mockito.anyString(), Mockito.any(Object.class));
            return abstractJmsTemplate;
        }
    };
    testCount = 0;
    final ProjectData projectData = new ProjectData(DigestTypeEnum.DAILY, "test", "version", Arrays.asList(), null);
    final HipChatEvent slackEvent = new HipChatEvent(projectData, 1L);
    channelTemplateManager.sendEvents(Arrays.asList(slackEvent));
    assertEquals(1, testCount);
}
Also used : AbstractJmsTemplate(com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate) AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) Gson(com.google.gson.Gson) HipChatEvent(com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) Test(org.junit.Test)

Example 2 with HipChatEvent

use of com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent 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());
}
Also used : DigestTypeEnum(com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) ArrayList(java.util.ArrayList) HipChatEvent(com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent) ConfiguredProjectEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) Date(java.util.Date) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) DistributionProjectRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 3 with HipChatEvent

use of com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent 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());
}
Also used : DigestTypeEnum(com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) ArrayList(java.util.ArrayList) HipChatEvent(com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent) ConfiguredProjectEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) Date(java.util.Date) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) DistributionProjectRelation(com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Aggregations

HipChatEvent (com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent)3 Test (org.junit.Test)3 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)2 ConfiguredProjectEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)2 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)2 DistributionProjectRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)2 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)2 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)2 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)2 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)2 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 AbstractJmsTemplate (com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate)1 MockAuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity)1 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)1 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)1 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)1 Gson (com.google.gson.Gson)1