use of com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper in project hub-alert by blackducksoftware.
the class NotificationProcessor method processAndDistribute.
private void processAndDistribute(List<AlertNotificationModel> notifications, List<FrequencyType> frequencies) {
List<DetailedNotificationContent> filterableNotifications = notifications.stream().map(notificationDetailExtractionDelegator::wrapNotification).flatMap(List::stream).collect(Collectors.toList());
StatefulAlertPage<FilteredJobNotificationWrapper, RuntimeException> statefulAlertPage = jobNotificationMapper.mapJobsToNotifications(filterableNotifications, frequencies);
// If there are elements to process in the current page or if there are more pages, keep looping.
while (!statefulAlertPage.isCurrentPageEmpty() || statefulAlertPage.hasNextPage()) {
for (FilteredJobNotificationWrapper jobNotificationWrapper : statefulAlertPage.getCurrentModels()) {
processAndDistribute(jobNotificationWrapper);
}
statefulAlertPage = statefulAlertPage.retrieveNextPage();
}
}
use of com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTest method mockNotificationProcessor.
private NotificationProcessor mockNotificationProcessor(NotificationAccessor notificationAccessor) {
NotificationDetailExtractionDelegator detailExtractionDelegator = new NotificationDetailExtractionDelegator(blackDuckResponseResolver, List.of());
JobNotificationMapper jobNotificationMapper = Mockito.mock(JobNotificationMapper.class);
Predicate<AlertPagedDetails> hasNextPage = page -> page.getCurrentPage() < (page.getTotalPages() - 1);
StatefulAlertPage<FilteredJobNotificationWrapper, RuntimeException> statefulAlertPage = new StatefulAlertPage(AlertPagedDetails.emptyPage(), Mockito.mock(PageRetriever.class), hasNextPage);
Mockito.when(jobNotificationMapper.mapJobsToNotifications(Mockito.anyList(), Mockito.anyList())).thenReturn(statefulAlertPage);
return new NotificationProcessor(detailExtractionDelegator, jobNotificationMapper, null, null, List.of(), notificationAccessor);
}
use of com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper 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());
}
Aggregations