Search in sources :

Example 6 with NotificationDetailExtractionDelegator

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

Example 7 with NotificationDetailExtractionDelegator

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

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

the class NotificationProcessorTest method processNotificationsWithMoreThanAPageOfJobsTest.

@Test
public // Passing case: A distribution event is sent
void processNotificationsWithMoreThanAPageOfJobsTest() {
    String projectName = "2468 - Test Project";
    String matchingProjectNamePattern = "2468.*";
    String nonMatchingProjectNamePattern = "13579asdf - DO NOT MATCH";
    String targetNotificationType = NotificationType.RULE_VIOLATION.name();
    String nonTargetNotificationType = NotificationType.LICENSE_LIMIT.name();
    RuleViolationNotificationView ruleViolationNotificationView = createRuleViolationNotificationView(projectName);
    String notificationContentString = GSON.toJson(ruleViolationNotificationView);
    AlertNotificationModel notification = createNotification(targetNotificationType, notificationContentString);
    FilteredDistributionJobResponseModel matchingJob = createJob(targetNotificationType, true, matchingProjectNamePattern);
    List<FilteredDistributionJobResponseModel> nonMatchingJobs = createNonMatchingJobs(250, nonTargetNotificationType, true, nonMatchingProjectNamePattern);
    // Only needs to handle the target notification type
    NotificationDetailExtractionDelegator extractionDelegator = new NotificationDetailExtractionDelegator(BLACK_DUCK_RESPONSE_RESOLVER, List.of(RULE_VIOLATION_NDE));
    ProcessingJobAccessor processingJobAccessor = new MockProcessingJobAccessor(nonMatchingJobs, matchingJob, 199);
    // This is needed to verify the notification is "sent"
    ProviderMessageDistributor distributor = Mockito.mock(ProviderMessageDistributor.class);
    Mockito.doNothing().when(distributor).distribute(Mockito.any(), Mockito.any());
    NotificationProcessor notificationProcessor = createNotificationProcessor(extractionDelegator, processingJobAccessor, distributor);
    notificationProcessor.processNotifications(List.of(notification), List.of(FrequencyType.REAL_TIME, FrequencyType.DAILY));
    // Exactly one distribution event should be sent
    Mockito.verify(distributor, Mockito.times(1)).distribute(Mockito.any(), Mockito.any());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) ProviderMessageDistributor(com.synopsys.integration.alert.processor.api.distribute.ProviderMessageDistributor) ProcessingJobAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProcessingJobAccessor) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator) RuleViolationNotificationView(com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView) Test(org.junit.jupiter.api.Test)

Example 9 with NotificationDetailExtractionDelegator

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

the class JobNotificationProcessorTest method processNotificationForJobTest.

@Test
public void processNotificationForJobTest() throws IntegrationException {
    // Set up dependencies for JobNotificationProcessor
    RuleViolationNotificationDetailExtractor ruleViolationNotificationDetailExtractor = new RuleViolationNotificationDetailExtractor();
    NotificationDetailExtractionDelegator notificationDetailExtractionDelegator = new NotificationDetailExtractionDelegator(RESPONSE_RESOLVER, List.of(ruleViolationNotificationDetailExtractor));
    RuleViolationNotificationMessageExtractor ruleViolationNotificationMessageExtractor = createRuleViolationNotificationMessageExtractor();
    ProviderMessageExtractionDelegator providerMessageExtractionDelegator = new ProviderMessageExtractionDelegator(List.of(ruleViolationNotificationMessageExtractor));
    ProjectMessageDigester projectMessageDigester = new ProjectMessageDigester();
    ProjectMessageSummarizer projectMessageSummarizer = new ProjectMessageSummarizer();
    NotificationContentProcessor notificationContentProcessor = new NotificationContentProcessor(providerMessageExtractionDelegator, projectMessageDigester, projectMessageSummarizer);
    MockProcessingAuditAccessor processingAuditAccessor = new MockProcessingAuditAccessor();
    EventManager eventManager = Mockito.mock(EventManager.class);
    ProviderMessageDistributor providerMessageDistributor = new ProviderMessageDistributor(processingAuditAccessor, eventManager);
    NotificationExtractorBlackDuckServicesFactoryCache lifecycleCaches = createNotificationExtractorBlackDuckServicesFactoryCache();
    // Create Requirements for processNotificationForJob
    ProcessedNotificationDetails processedNotificationDetails = new ProcessedNotificationDetails(uuid, CHANNEL_KEY, "JobName");
    AlertNotificationModel notificationModel = createNotification(NotificationType.RULE_VIOLATION.name());
    // Run test and verify notification saved by ProcessingAuditAccessor
    JobNotificationProcessor jobNotificationProcessor = new JobNotificationProcessor(notificationDetailExtractionDelegator, notificationContentProcessor, providerMessageDistributor, List.of(lifecycleCaches));
    jobNotificationProcessor.processNotificationForJob(processedNotificationDetails, ProcessingType.DEFAULT, List.of(notificationModel));
    Set<Long> auditNotificationIds = processingAuditAccessor.getNotificationIds(uuid);
    Mockito.verify(eventManager, Mockito.times(1)).sendEvent(Mockito.any());
    assertEquals(1, auditNotificationIds.size());
    assertTrue(auditNotificationIds.contains(notificationId));
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProviderMessageDistributor(com.synopsys.integration.alert.processor.api.distribute.ProviderMessageDistributor) ProjectMessageDigester(com.synopsys.integration.alert.processor.api.digest.ProjectMessageDigester) EventManager(com.synopsys.integration.alert.api.event.EventManager) RuleViolationNotificationDetailExtractor(com.synopsys.integration.alert.provider.blackduck.processor.detail.RuleViolationNotificationDetailExtractor) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) ProviderMessageExtractionDelegator(com.synopsys.integration.alert.processor.api.extract.ProviderMessageExtractionDelegator) ProjectMessageSummarizer(com.synopsys.integration.alert.processor.api.summarize.ProjectMessageSummarizer) RuleViolationNotificationMessageExtractor(com.synopsys.integration.alert.provider.blackduck.processor.message.RuleViolationNotificationMessageExtractor) ProcessedNotificationDetails(com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails) 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