Search in sources :

Example 1 with NotificationDetailExtractionDelegator

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

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

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

use of com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator 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 5 with NotificationDetailExtractionDelegator

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

Aggregations

NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)9 Test (org.junit.jupiter.api.Test)8 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)7 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)7 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)5 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)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 EventManager (com.synopsys.integration.alert.api.event.EventManager)2 ProviderMessageDistributor (com.synopsys.integration.alert.processor.api.distribute.ProviderMessageDistributor)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 StatefulAlertPage (com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage)2 ArrayList (java.util.ArrayList)2 Gson (com.google.gson.Gson)1 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)1 ProcessingJobAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProcessingJobAccessor)1