use of com.synopsys.integration.alert.processor.api.NotificationProcessor in project hub-alert by blackducksoftware.
the class ProcessingTaskTest method testRun.
@Test
void testRun() throws IOException {
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(true);
NotificationDetailExtractionDelegator extractionDelegator = new NotificationDetailExtractionDelegator(blackDuckResponseResolver, List.of());
JobNotificationMapper jobNotificationMapper = Mockito.mock(JobNotificationMapper.class);
StatefulAlertPage<FilteredJobNotificationWrapper, RuntimeException> statefulAlertPage = new StatefulAlertPage(AlertPagedDetails.emptyPage(), Mockito.mock(PageRetriever.class), BlackDuckNotificationRetriever.HAS_NEXT_PAGE);
Mockito.when(jobNotificationMapper.mapJobsToNotifications(Mockito.anyList(), Mockito.anyList())).thenReturn(statefulAlertPage);
NotificationProcessor notificationProcessor = Mockito.mock(NotificationProcessor.class);
ProcessingTask task = createTask(taskScheduler, notificationManager, notificationProcessor, taskManager, jobAccessor);
int expectedPages = 5;
int count = ProcessingTask.PAGE_SIZE * expectedPages;
List<AlertNotificationModel> allModels = new ArrayList<>(count);
for (int index = 0; index < count; index++) {
String notificationJson = TestResourceUtils.readFileToString("json/projectVersionNotification.json");
AlertNotificationModel model = new AlertNotificationModel(Integer.valueOf(index).longValue(), 1L, "BlackDuck", "BlackDuck_1", "PROJECT_VERSION", notificationJson, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), false);
allModels.add(model);
}
notificationManager.saveAllNotifications(allModels);
ProcessingTask processingTask = Mockito.spy(task);
processingTask.run();
Mockito.verify(processingTask).getDateRange();
Mockito.verify(processingTask, Mockito.times(expectedPages + 1)).read(Mockito.any(), Mockito.anyInt(), Mockito.anyInt());
}
use of com.synopsys.integration.alert.processor.api.NotificationProcessor in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTest method handleEventProcessingExceptionTest.
@Test
void handleEventProcessingExceptionTest() throws IOException {
NotificationAccessor notificationAccessor = Mockito.mock(NotificationAccessor.class);
Mockito.doAnswer((invocation) -> {
throw new ExecutionException(new RuntimeException("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.processor.api.NotificationProcessor in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTestIT method testHandleEventProcessedNotifications.
@Test
void testHandleEventProcessedNotifications() {
List<AlertNotificationModel> notificationContent = new ArrayList<>();
notificationContent.add(createAlertNotificationModel(true));
notificationContent.add(createAlertNotificationModel(true));
List<AlertNotificationModel> savedModels = defaultNotificationAccessor.saveAllNotifications(notificationContent);
assertNotNull(savedModels);
assertEquals(0, defaultNotificationAccessor.getFirstPageOfNotificationsNotProcessed(pageSize).getModels().size());
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 NotificationReceivedEventHandlerTestIT method testHandleEventMixedProcessedNotifications.
@Test
void testHandleEventMixedProcessedNotifications() {
List<AlertNotificationModel> notificationContent = new ArrayList<>();
notificationContent.add(createAlertNotificationModel(true));
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);
}
Aggregations