Search in sources :

Example 1 with NotificationProcessor

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

the class ProcessingTaskTest method testReadEmptyList.

@Test
void testReadEmptyList() {
    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());
    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);
    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) 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 2 with NotificationProcessor

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

the class ProcessingTaskTest method testPagedRead.

@Test
void testPagedRead() 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());
    NotificationProcessor notificationProcessor = new NotificationProcessor(extractionDelegator, null, null, null, null, null);
    ProcessingTask task = createTask(taskScheduler, notificationManager, notificationProcessor, taskManager, jobAccessor);
    int count = 20;
    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);
    DateRange dateRange = task.getDateRange();
    int pageSize = 5;
    int totalPages = count / pageSize;
    List<AlertNotificationModel> testModels = new ArrayList<>(count);
    for (int currentPage = 0; currentPage < totalPages; currentPage++) {
        AlertPagedModel<AlertNotificationModel> pagedModel = task.read(dateRange, currentPage, pageSize);
        assertEquals(totalPages, pagedModel.getTotalPages());
        assertEquals(currentPage, pagedModel.getCurrentPage());
        assertEquals(pageSize, pagedModel.getPageSize());
        testModels.addAll(pagedModel.getModels());
    }
    assertEquals(allModels.size(), testModels.size());
    assertTrue(allModels.containsAll(testModels));
}
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) TaskScheduler(org.springframework.scheduling.TaskScheduler) DateRange(com.synopsys.integration.alert.common.message.model.DateRange) TaskManager(com.synopsys.integration.alert.api.task.TaskManager) 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 NotificationProcessor

use of com.synopsys.integration.alert.processor.api.NotificationProcessor 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 4 with NotificationProcessor

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

the class NotificationReceivedEventHandlerTest method handleEventTest.

@Test
void handleEventTest() throws IOException {
    AlertNotificationModel alertNotificationModel = createAlertNotificationModel(1L, false);
    List<AlertNotificationModel> alertNotificationModels = List.of(alertNotificationModel);
    NotificationAccessor notificationAccessor = new MockNotificationAccessor(alertNotificationModels);
    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 : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) 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 5 with NotificationProcessor

use of com.synopsys.integration.alert.processor.api.NotificationProcessor 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)

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