Search in sources :

Example 1 with StatefulAlertPage

use of com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage 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);
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) JobNotificationMapper(com.synopsys.integration.alert.processor.api.filter.JobNotificationMapper) PageRetriever(com.synopsys.integration.alert.processor.api.filter.PageRetriever) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) AlertPagedDetails(com.synopsys.integration.alert.common.rest.model.AlertPagedDetails) FilteredJobNotificationWrapper(com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper) Predicate(java.util.function.Predicate) BlackDuckResponseResolver(com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver) IOException(java.io.IOException) StatefulAlertPage(com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage) TestResourceUtils(com.synopsys.integration.alert.test.common.TestResourceUtils) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) Gson(com.google.gson.Gson) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator) JmsTemplate(org.springframework.jms.core.JmsTemplate) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) DateUtils(com.synopsys.integration.alert.common.util.DateUtils) EventManager(com.synopsys.integration.alert.api.event.EventManager) StatefulAlertPage(com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage) PageRetriever(com.synopsys.integration.alert.processor.api.filter.PageRetriever) JobNotificationMapper(com.synopsys.integration.alert.processor.api.filter.JobNotificationMapper) AlertPagedDetails(com.synopsys.integration.alert.common.rest.model.AlertPagedDetails) FilteredJobNotificationWrapper(com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)

Example 2 with StatefulAlertPage

use of com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage 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());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) DefaultNotificationAccessor(com.synopsys.integration.alert.database.api.DefaultNotificationAccessor) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) ArrayList(java.util.ArrayList) FilteredJobNotificationWrapper(com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper) TaskScheduler(org.springframework.scheduling.TaskScheduler) StatefulAlertPage(com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage) TaskManager(com.synopsys.integration.alert.api.task.TaskManager) PageRetriever(com.synopsys.integration.alert.processor.api.filter.PageRetriever) JobNotificationMapper(com.synopsys.integration.alert.processor.api.filter.JobNotificationMapper) StaticJobAccessor(com.synopsys.integration.alert.database.api.StaticJobAccessor) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator) Test(org.junit.jupiter.api.Test)

Example 3 with StatefulAlertPage

use of com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage in project hub-alert by blackducksoftware.

the class BlackDuckAccumulatorTest method createMockNotificationPage.

private StatefulAlertPage<NotificationUserView, IntegrationException> createMockNotificationPage(PageRetriever pageRetriever) throws IntegrationException {
    NotificationUserView notificationView = createMockNotificationView();
    AlertPagedDetails<NotificationUserView> alertPagedDetails = new AlertPagedDetails<>(1, 0, 1, List.of(notificationView));
    return new StatefulAlertPage<>(alertPagedDetails, pageRetriever, BlackDuckNotificationRetriever.HAS_NEXT_PAGE);
}
Also used : StatefulAlertPage(com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage) AlertPagedDetails(com.synopsys.integration.alert.common.rest.model.AlertPagedDetails) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)

Aggregations

StatefulAlertPage (com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage)3 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)2 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)2 AlertPagedDetails (com.synopsys.integration.alert.common.rest.model.AlertPagedDetails)2 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)2 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)2 FilteredJobNotificationWrapper (com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper)2 JobNotificationMapper (com.synopsys.integration.alert.processor.api.filter.JobNotificationMapper)2 PageRetriever (com.synopsys.integration.alert.processor.api.filter.PageRetriever)2 Test (org.junit.jupiter.api.Test)2 Gson (com.google.gson.Gson)1 EventManager (com.synopsys.integration.alert.api.event.EventManager)1 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)1 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)1 DateUtils (com.synopsys.integration.alert.common.util.DateUtils)1 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)1 StaticJobAccessor (com.synopsys.integration.alert.database.api.StaticJobAccessor)1 TestResourceUtils (com.synopsys.integration.alert.test.common.TestResourceUtils)1 NotificationUserView (com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)1 BlackDuckResponseResolver (com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver)1