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);
}
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);
}
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));
}
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);
}
}
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;
}
}
Aggregations