Search in sources :

Example 6 with NotificationAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor in project hub-alert by blackducksoftware.

the class NotificationReceivedEventHandlerTest method handleEventProcessingInterruptedTest.

@Test
void handleEventProcessingInterruptedTest() throws IOException {
    NotificationAccessor notificationAccessor = Mockito.mock(NotificationAccessor.class);
    Mockito.doAnswer(invocation -> {
        throw new InterruptedException("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);
    }
}
Also used : EventManager(com.synopsys.integration.alert.api.event.EventManager) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) Test(org.junit.jupiter.api.Test)

Example 7 with NotificationAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor 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 8 with NotificationAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor 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 9 with NotificationAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor in project hub-alert by blackducksoftware.

the class NotificationProcessorTest method createNotificationAccessor.

private NotificationAccessor createNotificationAccessor() {
    NotificationAccessor notificationAccessor = Mockito.mock(NotificationAccessor.class);
    Mockito.doNothing().when(notificationAccessor).setNotificationsProcessed(Mockito.anyList());
    return notificationAccessor;
}
Also used : NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)

Example 10 with NotificationAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor 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);
    }
}
Also used : EventManager(com.synopsys.integration.alert.api.event.EventManager) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) ExecutionException(java.util.concurrent.ExecutionException) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)12 Test (org.junit.jupiter.api.Test)11 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)8 EventManager (com.synopsys.integration.alert.api.event.EventManager)5 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)5 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)5 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)5 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)4 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)4 StaticJobAccessor (com.synopsys.integration.alert.database.api.StaticJobAccessor)4 TaskScheduler (org.springframework.scheduling.TaskScheduler)4 DateRange (com.synopsys.integration.alert.common.message.model.DateRange)3 PageRetriever (com.synopsys.integration.alert.processor.api.filter.PageRetriever)3 Gson (com.google.gson.Gson)2 ProviderTaskPropertiesAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor)2 FilteredJobNotificationWrapper (com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper)2 JobNotificationMapper (com.synopsys.integration.alert.processor.api.filter.JobNotificationMapper)2 StatefulAlertPage (com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage)2 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)2 BlackDuckSystemValidator (com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator)2