use of com.synopsys.integration.alert.api.event.NotificationReceivedEvent in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTest method handleEventTest.
@Test
void handleEventTest() throws IOException {
AlertNotificationModel alertNotificationModel = createAlertNotificationModel(1L, false);
List<AlertNotificationModel> alertNotificationModels = List.of(alertNotificationModel);
NotificationAccessor notificationAccessor = new MockNotificationAccessor(alertNotificationModels);
NotificationProcessor notificationProcessor = mockNotificationProcessor(notificationAccessor);
EventManager eventManager = mockEventManager();
NotificationReceivedEventHandler eventHandler = new NotificationReceivedEventHandler(notificationAccessor, notificationProcessor, eventManager);
try {
eventHandler.handle(new NotificationReceivedEvent());
} catch (RuntimeException e) {
fail("Unable to handle event", e);
}
}
use of com.synopsys.integration.alert.api.event.NotificationReceivedEvent in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTest method handleEventProcessingInterruptedTest.
@Test
void handleEventProcessingInterruptedTest() throws IOException {
NotificationAccessor notificationAccessor = Mockito.mock(NotificationAccessor.class);
Mockito.doAnswer(invocation -> {
throw new InterruptedException("Test: exception for thread");
}).when(notificationAccessor).getFirstPageOfNotificationsNotProcessed(Mockito.anyInt());
NotificationProcessor notificationProcessor = mockNotificationProcessor(notificationAccessor);
EventManager eventManager = mockEventManager();
NotificationReceivedEventHandler eventHandler = new NotificationReceivedEventHandler(notificationAccessor, notificationProcessor, eventManager);
try {
eventHandler.handle(new NotificationReceivedEvent());
} catch (RuntimeException e) {
fail("Unable to handle event", e);
}
}
use of com.synopsys.integration.alert.api.event.NotificationReceivedEvent in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTestIT method testHandleEventProcessedNotificationsWithPages.
@Test
void testHandleEventProcessedNotificationsWithPages() {
EventManager eventManagerSpy = Mockito.spy(eventManager);
int totalNotifications = 200;
List<AlertNotificationModel> notificationContent = new ArrayList<>();
for (int index = 0; index < totalNotifications; index++) {
notificationContent.add(createAlertNotificationModel(false));
}
List<AlertNotificationModel> savedModels = defaultNotificationAccessor.saveAllNotifications(notificationContent);
assertNotNull(savedModels);
NotificationProcessor notificationProcessor = createNotificationProcessor();
NotificationReceivedEventHandler notificationReceivedEventHandler = new NotificationReceivedEventHandler(defaultNotificationAccessor, notificationProcessor, eventManagerSpy);
notificationReceivedEventHandler.handle(new NotificationReceivedEvent());
Mockito.verify(eventManagerSpy, Mockito.atLeastOnce()).sendEvent(Mockito.any());
assertEquals(100, defaultNotificationAccessor.getFirstPageOfNotificationsNotProcessed(100).getModels().size());
}
use of com.synopsys.integration.alert.api.event.NotificationReceivedEvent in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTestIT method testHandleEventNotProcessedNotifications.
@Test
void testHandleEventNotProcessedNotifications() {
List<AlertNotificationModel> notificationContent = new ArrayList<>();
notificationContent.add(createAlertNotificationModel(false));
notificationContent.add(createAlertNotificationModel(false));
List<AlertNotificationModel> savedModels = defaultNotificationAccessor.saveAllNotifications(notificationContent);
assertNotNull(savedModels);
NotificationProcessor notificationProcessor = createNotificationProcessor();
NotificationReceivedEventHandler notificationReceivedEventHandler = new NotificationReceivedEventHandler(defaultNotificationAccessor, notificationProcessor, eventManager);
notificationReceivedEventHandler.handle(new NotificationReceivedEvent());
testAlertNotificationModels(savedModels);
}
use of com.synopsys.integration.alert.api.event.NotificationReceivedEvent in project hub-alert by blackducksoftware.
the class BlackDuckAccumulator method write.
private void write(List<AlertNotificationModel> contentList) {
logger.info("Writing {} notifications...", contentList.size());
List<AlertNotificationModel> savedNotifications = notificationAccessor.saveAllNotifications(contentList);
if (logger.isDebugEnabled()) {
List<Long> notificationIds = savedNotifications.stream().map(AlertNotificationModel::getId).collect(Collectors.toList());
String joinedIds = StringUtils.join(notificationIds, ", ");
notificationLogger.debug("Saved notifications: {}", joinedIds);
}
eventManager.sendEvent(new NotificationReceivedEvent());
}
Aggregations