use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class ProcessingJobAccessorTestIT method testMatchingEnabledJobsUniqueJobsPerPage.
@Test
public void testMatchingEnabledJobsUniqueJobsPerPage() throws InterruptedException {
int expectedNumOfJobs = 1000;
Set<UUID> previousJobIdSet = new HashSet<>();
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name(), VulnerabilitySeverityType.HIGH.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
createJobs(createDistributionJobModels(List.of(VulnerabilitySeverityType.LOW.name()), 100));
List<DetailedNotificationContent> notifications = new ArrayList<>();
notifications.addAll(createVulnerabilityNotificationWrappers(List.of(VulnerabilitySeverityType.LOW.name()), PROJECT_NAME_1, PROJECT_VERSION_NAME_1));
notifications.addAll(createVulnerabilityNotificationWrappers(List.of(VulnerabilitySeverityType.HIGH.name()), PROJECT_NAME_2, PROJECT_VERSION_NAME_2));
int currentPage = 0;
FilteredDistributionJobRequestModel filteredDistributionJobRequestModel = new FilteredDistributionJobRequestModel(providerConfigId, List.of(FrequencyType.REAL_TIME));
filteredDistributionJobRequestModel.addProjectName(PROJECT_NAME_1);
filteredDistributionJobRequestModel.addProjectName(PROJECT_NAME_2);
filteredDistributionJobRequestModel.addNotificationType(NotificationType.VULNERABILITY.name());
filteredDistributionJobRequestModel.addVulnerabilitySeverities(List.of(VulnerabilitySeverityType.LOW.name(), VulnerabilitySeverityType.HIGH.name()));
AlertPagedDetails<FilteredDistributionJobResponseModel> jobs = processingJobAccessor.getMatchingEnabledJobsByFilteredNotifications(filteredDistributionJobRequestModel, currentPage, 100);
while (currentPage < jobs.getTotalPages()) {
currentPage++;
for (FilteredDistributionJobResponseModel jobResponseModel : jobs.getModels()) {
// this will update the job id such that last updated time will change.
// need to make sure the subsequent page requests don't return duplicate jobs.
UUID jobId = jobResponseModel.getId();
// cannot find the same job id in subsequent page requests for jobs.
assertFalse(previousJobIdSet.contains(jobId), String.format("Job id: %s found in set of previously mapped job ids.", jobId));
previousJobIdSet.add(jobId);
}
jobs = processingJobAccessor.getMatchingEnabledJobsByFilteredNotifications(filteredDistributionJobRequestModel, currentPage, 100);
}
assertEquals(expectedNumOfJobs, previousJobIdSet.size());
}
use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class JobNotificationFilterUtilsTest method doesNotificationApplyToJobProjectFailureTest.
@Test
public void doesNotificationApplyToJobProjectFailureTest() {
NotificationContentComponent notificationContent = Mockito.mock(NotificationContentComponent.class);
AlertNotificationModel notificationModel = createAlertNotificationModel(NotificationType.VULNERABILITY);
DetailedNotificationContent detailedNotificationContent = DetailedNotificationContent.project(notificationModel, notificationContent, PROJECT_NAME, PROJECT_VERSION_NAME);
FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(List.of(NotificationType.VULNERABILITY.name()), List.of("projectDoesNotExist"), List.of(), List.of(), true, "", "");
assertFalse(JobNotificationFilterUtils.doesNotificationApplyToJob(jobResponseModel, detailedNotificationContent));
}
use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class JobNotificationFilterUtilsTest method doesNotificationApplyToJobVulnerabilityTest.
@Test
public void doesNotificationApplyToJobVulnerabilityTest() {
NotificationContentComponent notificationContent = Mockito.mock(NotificationContentComponent.class);
AlertNotificationModel notificationModel = createAlertNotificationModel(NotificationType.VULNERABILITY);
DetailedNotificationContent detailedNotificationContent = DetailedNotificationContent.vulnerability(notificationModel, notificationContent, PROJECT_NAME, PROJECT_VERSION_NAME, List.of("vuln"));
FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(List.of(NotificationType.VULNERABILITY.name()), List.of(), List.of(), List.of(), false, "", "");
assertTrue(JobNotificationFilterUtils.doesNotificationApplyToJob(jobResponseModel, detailedNotificationContent));
FilteredDistributionJobResponseModel jobResponseModelWithFailure = createFilteredDistributionJobResponseModel(List.of(NotificationType.VULNERABILITY.name()), List.of(), List.of(), List.of("vulnDoesNotExist"), false, "", "");
assertFalse(JobNotificationFilterUtils.doesNotificationApplyToJob(jobResponseModelWithFailure, detailedNotificationContent));
}
use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class JobNotificationFilterUtilsTest method doesNotificationApplyToJobPolicyOverrideTest.
@Test
public void doesNotificationApplyToJobPolicyOverrideTest() {
testPolicyNotifications(NotificationType.POLICY_OVERRIDE);
testPolicyNotifications(NotificationType.RULE_VIOLATION);
testPolicyNotifications(NotificationType.RULE_VIOLATION_CLEARED);
NotificationContentComponent notificationContent = Mockito.mock(NotificationContentComponent.class);
AlertNotificationModel notificationModel = createAlertNotificationModel(NotificationType.POLICY_OVERRIDE);
DetailedNotificationContent detailedNotificationContent = DetailedNotificationContent.policy(notificationModel, notificationContent, PROJECT_NAME, PROJECT_VERSION_NAME, POLICY_NAME);
FilteredDistributionJobResponseModel jobResponseModelWithFailure = createFilteredDistributionJobResponseModel(List.of(NotificationType.POLICY_OVERRIDE.name()), List.of(), List.of("policyDoesNotExist"), List.of(), false, "", "");
assertFalse(JobNotificationFilterUtils.doesNotificationApplyToJob(jobResponseModelWithFailure, detailedNotificationContent));
}
use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class JobNotificationFilterUtilsTest method doesNotificationApplyToJobNotificationTypeFailureTest.
@Test
public void doesNotificationApplyToJobNotificationTypeFailureTest() {
NotificationContentComponent notificationContent = Mockito.mock(NotificationContentComponent.class);
AlertNotificationModel notificationModel = createAlertNotificationModel(NotificationType.VULNERABILITY);
DetailedNotificationContent detailedNotificationContent = DetailedNotificationContent.vulnerability(notificationModel, notificationContent, PROJECT_NAME, PROJECT_VERSION_NAME, List.of("vuln"));
FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(List.of(NotificationType.POLICY_OVERRIDE.name()), List.of(), List.of(), List.of(), false, "", "");
assertFalse(JobNotificationFilterUtils.doesNotificationApplyToJob(jobResponseModel, detailedNotificationContent));
}
Aggregations