use of com.synopsys.integration.alert.processor.api.NotificationProcessor 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.processor.api.NotificationProcessor in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTestIT method createNotificationProcessor.
private NotificationProcessor createNotificationProcessor() {
// We aren't testing the processor here since we have bad data. We just want to make sure the processor marks the notifications as processed to test the paging in the handler.
NotificationDetailExtractionDelegator notificationDetailExtractionDelegator = Mockito.mock(NotificationDetailExtractionDelegator.class);
Mockito.when(notificationDetailExtractionDelegator.wrapNotification(Mockito.any())).thenReturn(List.of());
return new NotificationProcessor(notificationDetailExtractionDelegator, jobNotificationMapper, notificationContentProcessor, providerMessageDistributor, lifecycleCaches, defaultNotificationAccessor);
}
use of com.synopsys.integration.alert.processor.api.NotificationProcessor 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.processor.api.NotificationProcessor in project hub-alert by blackducksoftware.
the class ProcessingTaskTest method testJobCountZero.
@Test
void testJobCountZero() {
TaskManager taskManager = Mockito.mock(TaskManager.class);
TaskScheduler taskScheduler = Mockito.mock(TaskScheduler.class);
NotificationAccessor notificationManager = new MockProcessingNotificationAccessor(List.of());
StaticJobAccessor jobAccessor = Mockito.mock(StaticJobAccessor.class);
Mockito.when(jobAccessor.hasJobsByFrequency(Mockito.any())).thenReturn(false);
NotificationDetailExtractionDelegator extractionDelegator = new NotificationDetailExtractionDelegator(blackDuckResponseResolver, List.of());
NotificationProcessor notificationProcessor = new NotificationProcessor(extractionDelegator, null, null, null, null, null);
ProcessingTask task = createTask(taskScheduler, notificationManager, notificationProcessor, taskManager, jobAccessor);
DateRange dateRange = task.getDateRange();
ProcessingTask processingTask = Mockito.spy(task);
processingTask.runTask();
Mockito.verify(processingTask, Mockito.times(0)).getDateRange();
}
use of com.synopsys.integration.alert.processor.api.NotificationProcessor in project hub-alert by blackducksoftware.
the class ProcessingTaskTest method testReadException.
@Test
void testReadException() {
TaskManager taskManager = Mockito.mock(TaskManager.class);
TaskScheduler taskScheduler = Mockito.mock(TaskScheduler.class);
DefaultNotificationAccessor notificationManager = Mockito.mock(DefaultNotificationAccessor.class);
StaticJobAccessor jobAccessor = Mockito.mock(StaticJobAccessor.class);
NotificationDetailExtractionDelegator extractionDelegator = new NotificationDetailExtractionDelegator(blackDuckResponseResolver, List.of());
NotificationProcessor notificationProcessor = new NotificationProcessor(extractionDelegator, null, null, null, null, null);
ProcessingTask task = createTask(taskScheduler, notificationManager, notificationProcessor, taskManager, jobAccessor);
DateRange dateRange = task.getDateRange();
Mockito.doThrow(new RuntimeException("Exception reading data")).when(notificationManager).findByCreatedAtBetween(dateRange.getStart(), dateRange.getEnd(), AlertPagedModel.DEFAULT_PAGE_NUMBER, AlertPagedModel.DEFAULT_PAGE_SIZE);
ProcessingTask processingTask = Mockito.spy(task);
List<AlertNotificationModel> actualModelList = processingTask.read(dateRange, AlertPagedModel.DEFAULT_PAGE_NUMBER, AlertPagedModel.DEFAULT_PAGE_SIZE).getModels();
assertEquals(Collections.emptyList(), actualModelList);
}
Aggregations