Search in sources :

Example 1 with AbstractJmsTemplate

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

the class ChannelTemplateManagerTest method testNotAbstractChannelEvent.

@Test
public void testNotAbstractChannelEvent() {
    final ChannelTemplateManager channelTemplateManager = new ChannelTemplateManager(new Gson(), null, null, null) {

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

        @Override
        public AbstractJmsTemplate getTemplate(final String destination) {
            final AbstractJmsTemplate abstractJmsTemplate = Mockito.mock(AbstractJmsTemplate.class);
            Mockito.doNothing().when(abstractJmsTemplate).convertAndSend(Mockito.anyString(), Mockito.any(Object.class));
            return abstractJmsTemplate;
        }
    };
    final DBStoreEvent dbStoreEvent = new DBStoreEvent(null);
    final boolean isTrue = channelTemplateManager.sendEvent(dbStoreEvent);
    assertTrue(isTrue);
}
Also used : AbstractJmsTemplate(com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate) Gson(com.google.gson.Gson) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent) Test(org.junit.Test)

Example 2 with AbstractJmsTemplate

use of com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate 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)

Example 3 with AbstractJmsTemplate

use of com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate 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)

Aggregations

AbstractJmsTemplate (com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate)3 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)2 Gson (com.google.gson.Gson)2 Test (org.junit.Test)2 MockAuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity)1 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)1 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)1 HipChatEvent (com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent)1 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)1 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)1 DBStoreEvent (com.blackducksoftware.integration.hub.alert.event.DBStoreEvent)1 Date (java.util.Date)1