Search in sources :

Example 1 with AbstractChannelEvent

use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.

the class RestDistributionChannelTest method sendMessageFailureTest.

@Test
public void sendMessageFailureTest() {
    final GlobalProperties globalProperties = new TestGlobalProperties();
    final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
    final RestDistributionChannel<AbstractChannelEvent, GlobalChannelConfigEntity, DistributionChannelConfigEntity> restChannel = new RestDistributionChannel<AbstractChannelEvent, GlobalChannelConfigEntity, DistributionChannelConfigEntity>(null, null, null, null, null, null, channelRestConnectionFactory) {

        @Override
        public String getApiUrl() {
            return null;
        }

        @Override
        public Request createRequest(final ChannelRequestHelper channelRequestHelper, final DistributionChannelConfigEntity config, final ProjectData projectData) throws AlertException {
            return new Request.Builder().uri("http://google.com").build();
        }
    };
    final SlackEvent event = new SlackEvent(createProjectData("Rest channel test"), 1L);
    final SlackDistributionConfigEntity config = new SlackDistributionConfigEntity("more garbage", "garbage", "garbage");
    Exception thrownException = null;
    try {
        restChannel.sendAuditedMessage(event, config);
    } catch (final IntegrationException ex) {
        thrownException = ex;
    }
    assertNotNull(thrownException);
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) SlackEvent(com.blackducksoftware.integration.hub.alert.channel.slack.SlackEvent) GlobalChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) DistributionChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity) SlackDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionConfigEntity) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 2 with AbstractChannelEvent

use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.

the class DailyDigestItemProcessorTest method testProcess.

@Test
public void testProcess() throws Exception {
    final DigestNotificationProcessor digestNotificationProcessor = Mockito.mock(DigestNotificationProcessor.class);
    final AbstractChannelEvent channelEvent = Mockito.mock(AbstractChannelEvent.class);
    Mockito.when(digestNotificationProcessor.processNotifications(Mockito.any(), Mockito.any())).thenReturn(Arrays.asList(channelEvent));
    final DailyDigestItemProcessor dailyDigestItemProcessor = new DailyDigestItemProcessor(digestNotificationProcessor);
    final List<AbstractChannelEvent> nonEmptyList = dailyDigestItemProcessor.process(Arrays.asList());
    assertTrue(!nonEmptyList.isEmpty());
    Mockito.when(digestNotificationProcessor.processNotifications(Mockito.any(), Mockito.any())).thenReturn(Arrays.asList());
    final List<AbstractChannelEvent> emptyList = dailyDigestItemProcessor.process(Arrays.asList());
    assertNull(emptyList);
}
Also used : AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) Test(org.junit.Test)

Example 3 with AbstractChannelEvent

use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.

the class DigestItemWriterTest method testWrite.

@Test
public void testWrite() throws Exception {
    final ChannelTemplateManager channelTemplateManager = Mockito.mock(ChannelTemplateManager.class);
    Mockito.doNothing().when(channelTemplateManager).sendEvents(Mockito.anyListOf(AbstractChannelEvent.class));
    final DigestItemWriter digestItemWriter = new DigestItemWriter(channelTemplateManager);
    final AbstractChannelEvent abstractChannelEvent = Mockito.mock(AbstractChannelEvent.class);
    final List<AbstractChannelEvent> channelList = Arrays.asList(abstractChannelEvent);
    digestItemWriter.write(Arrays.asList(channelList));
    Mockito.verify(channelTemplateManager).sendEvents(Mockito.anyListOf(AbstractChannelEvent.class));
}
Also used : ChannelTemplateManager(com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) Test(org.junit.Test)

Example 4 with AbstractChannelEvent

use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.

the class RealTimeListener method receiveMessage.

@JmsListener(destination = RealTimeEvent.TOPIC_NAME)
@Override
public void receiveMessage(final String message) {
    try {
        final RealTimeEvent event = getEvent(message);
        final Collection<ProjectData> projectDataCollection = projectDataFactory.createProjectDataCollection(event.getNotificationList(), DigestTypeEnum.REAL_TIME);
        final List<AbstractChannelEvent> events = eventManager.createChannelEvents(projectDataCollection);
        channelTemplateManager.sendEvents(events);
    } catch (final Exception e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : RealTimeEvent(com.blackducksoftware.integration.hub.alert.event.RealTimeEvent) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) JmsListener(org.springframework.jms.annotation.JmsListener)

Example 5 with AbstractChannelEvent

use of com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent in project hub-alert by blackducksoftware.

the class ChannelTemplateManager method sendEvent.

public boolean sendEvent(final AbstractEvent event) {
    final String destination = event.getTopic();
    if (hasTemplate(destination)) {
        if (event instanceof AbstractChannelEvent) {
            final AbstractChannelEvent channelEvent = (AbstractChannelEvent) event;
            AuditEntryEntity auditEntryEntity = null;
            if (channelEvent.getAuditEntryId() == null) {
                auditEntryEntity = new AuditEntryEntity(channelEvent.getCommonDistributionConfigId(), new Date(System.currentTimeMillis()), null, null, null, null);
            } else {
                auditEntryEntity = auditEntryRepository.findOne(channelEvent.getAuditEntryId());
            }
            auditEntryEntity.setStatus(StatusEnum.PENDING);
            final AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(auditEntryEntity);
            channelEvent.setAuditEntryId(savedAuditEntryEntity.getId());
            for (final Long notificationId : channelEvent.getProjectData().getNotificationIds()) {
                final AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(savedAuditEntryEntity.getId(), notificationId);
                auditNotificationRepository.save(auditNotificationRelation);
            }
            final String jsonMessage = gson.toJson(channelEvent);
            final AbstractJmsTemplate template = getTemplate(destination);
            template.convertAndSend(destination, jsonMessage);
        } else {
            final String jsonMessage = gson.toJson(event);
            final AbstractJmsTemplate template = getTemplate(destination);
            template.convertAndSend(destination, jsonMessage);
        }
        return true;
    } else {
        return false;
    }
}
Also used : AbstractJmsTemplate(com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) Date(java.util.Date) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)

Aggregations

AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)11 Test (org.junit.Test)8 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)5 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)4 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)4 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)4 Date (java.util.Date)4 ChannelTemplateManager (com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager)3 ConfiguredProjectEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)3 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)3 DistributionChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity)3 GlobalChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity)3 DistributionProjectRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)3 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)3 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)3 ArrayList (java.util.ArrayList)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)2 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)2 HipChatEvent (com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent)2