Search in sources :

Example 86 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel 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 87 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel 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)

Example 88 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class JobNotificationFilterUtilsTest method doesNotificationApplyToJobDefaultTest.

@Test
public void doesNotificationApplyToJobDefaultTest() {
    NotificationContentComponent notificationContent = Mockito.mock(NotificationContentComponent.class);
    AlertNotificationModel notificationModel = createAlertNotificationModel(NotificationType.LICENSE_LIMIT);
    DetailedNotificationContent detailedNotificationContent = DetailedNotificationContent.projectless(notificationModel, notificationContent);
    FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(List.of(NotificationType.LICENSE_LIMIT.name()), List.of(), List.of(), List.of(), false, "", "");
    assertTrue(JobNotificationFilterUtils.doesNotificationApplyToJob(jobResponseModel, detailedNotificationContent));
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) NotificationContentComponent(com.synopsys.integration.blackduck.api.manual.component.NotificationContentComponent) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) Test(org.junit.jupiter.api.Test)

Example 89 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class NotificationRemovalTest method createABatchOfNotifications.

private void createABatchOfNotifications(ConfigurationModel providerConfig, OffsetDateTime notificationCreationTime, boolean batchOfProcessedNotifications) {
    int count = BATCH_SIZE;
    List<AlertNotificationModel> notifications = new ArrayList<>(BATCH_SIZE);
    ProviderDetails providerDetails = new ProviderDetails(providerConfig.getConfigurationId(), new LinkableItem("Black Duck", "bd-server", BLACKDUCK_PROVIDER_URL));
    for (int index = 0; index < count; index++) {
        RuleViolationNotificationView ruleViolationNotificationView = createRuleViolationNotificationView(PROJECT_NAME);
        String notificationContentString = GSON.toJson(ruleViolationNotificationView);
        notifications.add(createNotification(providerDetails, NotificationType.RULE_VIOLATION.name(), notificationContentString, notificationCreationTime, batchOfProcessedNotifications));
    }
    notifications = notificationAccessor.saveAllNotifications(notifications);
    createAuditEntries(notifications);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ArrayList(java.util.ArrayList) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) RuleViolationNotificationView(com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView)

Example 90 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class JobNotificationMapperTestIT method createNotificationWrappers.

private List<DetailedNotificationContent> createNotificationWrappers() {
    AlertNotificationModel alertNotificationModel = createAlertNotificationModel(NotificationType.VULNERABILITY);
    DetailedNotificationContent test_project = DetailedNotificationContent.vulnerability(alertNotificationModel, createVulnerabilityUniqueProjectNotificationContent(PROJECT_NAME_1), PROJECT_NAME_1, PROJECT_VERSION_NAME_1, List.of(VulnerabilitySeverityType.LOW.name()));
    String projectName1 = "test_project1";
    DetailedNotificationContent test_project2 = DetailedNotificationContent.vulnerability(alertNotificationModel, createVulnerabilityUniqueProjectNotificationContent(projectName1), projectName1, "version1", List.of(VulnerabilitySeverityType.HIGH.name()));
    String projectName2 = "test_project2";
    DetailedNotificationContent test_project3 = DetailedNotificationContent.vulnerability(alertNotificationModel, createVulnerabilityUniqueProjectNotificationContent(projectName2), projectName2, "version2", List.of(VulnerabilitySeverityType.LOW.name(), VulnerabilitySeverityType.HIGH.name()));
    AlertNotificationModel alertPolicyNotificationModel = createAlertNotificationModel(NotificationType.POLICY_OVERRIDE);
    DetailedNotificationContent test_project4 = DetailedNotificationContent.policy(alertPolicyNotificationModel, createVulnerabilityUniqueProjectNotificationContent(projectName2), projectName2, "1.0.0", POLICY_FILTER_NAME);
    return List.of(test_project, test_project2, test_project3, test_project4);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)

Aggregations

AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)94 Test (org.junit.jupiter.api.Test)62 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)21 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)20 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)16 PageRequest (org.springframework.data.domain.PageRequest)16 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)14 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)14 OffsetDateTime (java.time.OffsetDateTime)13 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)11 ArrayList (java.util.ArrayList)10 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)9 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)7 FilteredDistributionJobResponseModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel)7 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)6 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)6 NotificationContentComponent (com.synopsys.integration.blackduck.api.manual.component.NotificationContentComponent)5 PageImpl (org.springframework.data.domain.PageImpl)5 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)4 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)4