Search in sources :

Example 16 with FilteredDistributionJobResponseModel

use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.

the class DefaultProcessingJobAccessor method convertToFilteredDistributionJobResponseModel.

private FilteredDistributionJobResponseModel convertToFilteredDistributionJobResponseModel(DistributionJobEntity jobEntity) {
    UUID jobId = jobEntity.getJobId();
    ProcessingType processingType = Enum.valueOf(ProcessingType.class, jobEntity.getProcessingType());
    String channelName = jobEntity.getChannelDescriptorName();
    String jobName = jobEntity.getName();
    BlackDuckJobDetailsEntity blackDuckJobDetails = jobEntity.getBlackDuckJobDetails();
    List<String> notificationTypes = blackDuckJobDetailsAccessor.retrieveNotificationTypesForJob(jobId);
    List<BlackDuckProjectDetailsModel> projectDetails = blackDuckJobDetailsAccessor.retrieveProjectDetailsForJob(jobId);
    List<String> policyNames = blackDuckJobDetailsAccessor.retrievePolicyNamesForJob(jobId);
    List<String> vulnerabilitySeverityNames = blackDuckJobDetailsAccessor.retrieveVulnerabilitySeverityNamesForJob(jobId);
    boolean filterByProject = blackDuckJobDetails.getFilterByProject();
    String projectNamePattern = blackDuckJobDetails.getProjectNamePattern();
    String projectVersionNamePattern = blackDuckJobDetails.getProjectVersionNamePattern();
    return new FilteredDistributionJobResponseModel(jobId, processingType, channelName, jobName, notificationTypes, projectDetails, policyNames, vulnerabilitySeverityNames, filterByProject, projectNamePattern, projectVersionNamePattern);
}
Also used : FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) BlackDuckProjectDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.BlackDuckProjectDetailsModel) ProcessingType(com.synopsys.integration.alert.common.enumeration.ProcessingType) UUID(java.util.UUID) BlackDuckJobDetailsEntity(com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)

Example 17 with FilteredDistributionJobResponseModel

use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.

the class NotificationProcessorTest method createNonMatchingJobs.

private List<FilteredDistributionJobResponseModel> createNonMatchingJobs(int numberToCreate, String notificationType, boolean filterByProject, String projectNamePattern) {
    List<FilteredDistributionJobResponseModel> nonMatchingJobs = new ArrayList<>(numberToCreate);
    for (int i = 0; i < numberToCreate; i++) {
        FilteredDistributionJobResponseModel job = createJob(notificationType, filterByProject, projectNamePattern);
        nonMatchingJobs.add(job);
    }
    return nonMatchingJobs;
}
Also used : FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) ArrayList(java.util.ArrayList)

Example 18 with FilteredDistributionJobResponseModel

use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel 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 19 with FilteredDistributionJobResponseModel

use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.

the class JobNotificationFilterUtilsTest method doesProjectVersionNameMatchWithNoProjectTest.

@Test
public void doesProjectVersionNameMatchWithNoProjectTest() {
    FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(List.of(), List.of(), List.of(), List.of(), true, "", "1.0.*");
    boolean doesProjectApplyToJob = JobNotificationFilterUtils.doesProjectApplyToJob(jobResponseModel, "projectName", "1.0.0");
    assertTrue(doesProjectApplyToJob);
}
Also used : FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) Test(org.junit.jupiter.api.Test)

Example 20 with FilteredDistributionJobResponseModel

use of com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel in project hub-alert by blackducksoftware.

the class JobNotificationFilterUtilsTest method doesProjectApplyToJobPatternMatchingTest.

@Test
public void doesProjectApplyToJobPatternMatchingTest() {
    FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(List.of(NotificationType.VULNERABILITY.name()), List.of(PROJECT_NAME), List.of(), List.of(), true, ".*", "");
    assertTrue(JobNotificationFilterUtils.doesProjectApplyToJob(jobResponseModel, PROJECT_NAME, PROJECT_VERSION_NAME));
    FilteredDistributionJobResponseModel jobResponseModelFilterByNamePattern = createFilteredDistributionJobResponseModel(List.of(NotificationType.VULNERABILITY.name()), List.of(PROJECT_NAME), List.of(), List.of(), true, "project*", "");
    assertTrue(JobNotificationFilterUtils.doesProjectApplyToJob(jobResponseModelFilterByNamePattern, PROJECT_NAME, PROJECT_VERSION_NAME));
    assertFalse(JobNotificationFilterUtils.doesProjectApplyToJob(jobResponseModelFilterByNamePattern, "nonMatchingName", PROJECT_VERSION_NAME));
}
Also used : FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) Test(org.junit.jupiter.api.Test)

Aggregations

FilteredDistributionJobResponseModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel)24 Test (org.junit.jupiter.api.Test)19 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)8 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)7 NotificationContentComponent (com.synopsys.integration.blackduck.api.manual.component.NotificationContentComponent)6 FilteredDistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 ProcessingType (com.synopsys.integration.alert.common.enumeration.ProcessingType)1 ProcessingJobAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProcessingJobAccessor)1 BlackDuckProjectDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.BlackDuckProjectDetailsModel)1 AlertPagedDetails (com.synopsys.integration.alert.common.rest.model.AlertPagedDetails)1 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)1 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)1 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)1 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)1 ProviderMessageDistributor (com.synopsys.integration.alert.processor.api.distribute.ProviderMessageDistributor)1 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)1 RuleViolationNotificationView (com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView)1 HashMap (java.util.HashMap)1