use of com.blackducksoftware.integration.hub.alert.event.RealTimeEvent in project hub-alert by blackducksoftware.
the class RealTimeListenerTest method testReceiveMessageException.
@SuppressWarnings("unchecked")
@Test
public void testReceiveMessageException() throws IOException, Exception {
try (OutputLogger outputLogger = new OutputLogger()) {
final Gson gson = new Gson();
final MockNotificationEntity notificationEntity = new MockNotificationEntity();
final NotificationModel model = new NotificationModel(notificationEntity.createEntity(), Collections.emptyList());
final ChannelTemplateManager channelTemplateManager = Mockito.mock(ChannelTemplateManager.class);
final ProjectDataFactory projectDataFactory = Mockito.mock(ProjectDataFactory.class);
final NotificationEventManager eventManager = Mockito.mock(NotificationEventManager.class);
Mockito.doNothing().when(channelTemplateManager).sendEvents(Mockito.any());
Mockito.doThrow(new NullPointerException("null error")).when(projectDataFactory).createProjectDataCollection(Mockito.anyCollection(), Mockito.any());
final RealTimeListener realTimeListener = new RealTimeListener(gson, channelTemplateManager, projectDataFactory, eventManager);
final RealTimeEvent realTimeEvent = new RealTimeEvent(Arrays.asList(model));
final String realTimeEventString = gson.toJson(realTimeEvent);
realTimeListener.receiveMessage(realTimeEventString);
assertTrue(outputLogger.isLineContainingText("null"));
}
}
use of com.blackducksoftware.integration.hub.alert.event.RealTimeEvent in project hub-alert by blackducksoftware.
the class AccumulatorWriter method write.
@Override
public void write(final List<? extends DBStoreEvent> itemList) throws Exception {
try {
if (itemList != null && !itemList.isEmpty()) {
logger.info("Writing {} notifications", itemList.size());
itemList.forEach(item -> {
final List<NotificationEvent> notificationList = item.getNotificationList();
final List<NotificationModel> entityList = new ArrayList<>();
notificationList.forEach(notification -> {
final String eventKey = notification.getEventKey();
final NotificationContentItem content = (NotificationContentItem) notification.getDataSet().get(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT);
final Date createdAt = content.getCreatedAt();
final NotificationCategoryEnum notificationType = notification.getCategoryType();
final String projectName = content.getProjectVersion().getProjectName();
final String projectUrl = content.getProjectVersion().getProjectLink();
final String projectVersion = content.getProjectVersion().getProjectVersionName();
final String projectVersionUrl = content.getProjectVersion().getUrl();
final String componentName = content.getComponentName();
final String componentVersion = content.getComponentVersion().versionName;
final String policyRuleName = getPolicyRule(notification);
final String person = getPerson(notification);
final NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
final Collection<VulnerabilityEntity> vulnerabilityList = getVulnerabilities(notification, entity);
NotificationModel model = new NotificationModel(entity, vulnerabilityList);
model = notificationManager.saveNotification(model);
entityList.add(model);
});
final RealTimeEvent realTimeEvent = new RealTimeEvent(entityList);
channelTemplateManager.sendEvent(realTimeEvent);
});
} else {
logger.info("No notifications to write");
}
} catch (final Exception ex) {
logger.error("Error occurred writing notification data", ex);
}
}
use of com.blackducksoftware.integration.hub.alert.event.RealTimeEvent 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.RealTimeEvent in project hub-alert by blackducksoftware.
the class RealTimeListenerTest method testReceiveMessage.
@Test
public void testReceiveMessage() {
final Gson gson = new Gson();
final MockNotificationEntity notificationEntity = new MockNotificationEntity();
final NotificationModel model = new NotificationModel(notificationEntity.createEntity(), Collections.emptyList());
final ChannelTemplateManager channelTemplateManager = Mockito.mock(ChannelTemplateManager.class);
final ProjectDataFactory projectDataFactory = Mockito.mock(ProjectDataFactory.class);
final NotificationEventManager eventManager = Mockito.mock(NotificationEventManager.class);
final RealTimeListener realTimeListener = new RealTimeListener(gson, channelTemplateManager, projectDataFactory, eventManager);
final RealTimeEvent realTimeEvent = new RealTimeEvent(Arrays.asList(model));
final String realTimeEventString = gson.toJson(realTimeEvent);
realTimeListener.receiveMessage(realTimeEventString);
Mockito.doNothing().when(channelTemplateManager).sendEvents(Mockito.any());
Mockito.verify(channelTemplateManager).sendEvents(Mockito.any());
}
Aggregations