Search in sources :

Example 6 with NotificationProcessor

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());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) EventManager(com.synopsys.integration.alert.api.event.EventManager) ArrayList(java.util.ArrayList) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with NotificationProcessor

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);
}
Also used : NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)

Example 8 with NotificationProcessor

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);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ArrayList(java.util.ArrayList) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 9 with NotificationProcessor

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();
}
Also used : DateRange(com.synopsys.integration.alert.common.message.model.DateRange) TaskManager(com.synopsys.integration.alert.api.task.TaskManager) DefaultNotificationAccessor(com.synopsys.integration.alert.database.api.DefaultNotificationAccessor) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) StaticJobAccessor(com.synopsys.integration.alert.database.api.StaticJobAccessor) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) TaskScheduler(org.springframework.scheduling.TaskScheduler) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator) Test(org.junit.jupiter.api.Test)

Example 10 with NotificationProcessor

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);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) DateRange(com.synopsys.integration.alert.common.message.model.DateRange) TaskManager(com.synopsys.integration.alert.api.task.TaskManager) DefaultNotificationAccessor(com.synopsys.integration.alert.database.api.DefaultNotificationAccessor) StaticJobAccessor(com.synopsys.integration.alert.database.api.StaticJobAccessor) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) TaskScheduler(org.springframework.scheduling.TaskScheduler) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator) Test(org.junit.jupiter.api.Test)

Aggregations

NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)14 Test (org.junit.jupiter.api.Test)13 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)10 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)8 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)8 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)7 ArrayList (java.util.ArrayList)6 EventManager (com.synopsys.integration.alert.api.event.EventManager)5 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)5 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)5 StaticJobAccessor (com.synopsys.integration.alert.database.api.StaticJobAccessor)5 TaskScheduler (org.springframework.scheduling.TaskScheduler)5 DateRange (com.synopsys.integration.alert.common.message.model.DateRange)4 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)4 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 StatefulAlertPage (com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage)2 ExecutionException (java.util.concurrent.ExecutionException)2 Gson (com.google.gson.Gson)1