use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class JobNotificationFilterUtilsTest method testPolicyNotifications.
private void testPolicyNotifications(NotificationType notificationType) {
NotificationContentComponent notificationContent = Mockito.mock(NotificationContentComponent.class);
AlertNotificationModel notificationModel = createAlertNotificationModel(notificationType);
DetailedNotificationContent detailedNotificationContent = DetailedNotificationContent.policy(notificationModel, notificationContent, PROJECT_NAME, POLICY_NAME, PROJECT_VERSION_NAME);
FilteredDistributionJobResponseModel jobResponseModel = createFilteredDistributionJobResponseModel(List.of(notificationType.name()), List.of(), List.of(), List.of(), false, "", "");
assertTrue(JobNotificationFilterUtils.doesNotificationApplyToJob(jobResponseModel, detailedNotificationContent));
}
use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class BomEditNotificationDetailExtractorTest method extractDetailedContentTest.
@Test
public void extractDetailedContentTest() throws IOException, IntegrationException {
String projectName = "project-name";
String projectVersionName = "project-version-name";
Long blackDuckConfigId = 0L;
String notificationString = TestResourceUtils.readFileToString(BOM_EDIT_JSON_PATH);
BomEditNotificationView notificationView = gson.fromJson(notificationString, BomEditNotificationView.class);
NotificationExtractorBlackDuckServicesFactoryCache cache = createCache(blackDuckConfigId, projectName, projectVersionName);
BomEditNotificationDetailExtractor extractor = new BomEditNotificationDetailExtractor(cache);
AlertNotificationModel notification = new AlertNotificationModel(0L, blackDuckConfigId, "BlackDuck", "Config 1", null, null, null, null, false);
List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
assertEquals(1, detailedNotificationContents.size());
DetailedNotificationContent detailedNotificationContent = detailedNotificationContents.get(0);
Optional<String> detailedProjectName = detailedNotificationContent.getProjectName();
assertTrue(detailedProjectName.isPresent(), "Expected project name to be present");
assertEquals(projectName, detailedProjectName.get());
assertTrue(detailedNotificationContent.getPolicyName().isEmpty(), "Expected no policy name to be present");
assertEquals(0, detailedNotificationContent.getVulnerabilitySeverities().size());
}
use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class BomEditNotificationDetailExtractor method extractDetailedContent.
@Override
public List<DetailedNotificationContent> extractDetailedContent(AlertNotificationModel alertNotificationModel, BomEditNotificationView notificationView) {
BomEditNotificationContent notificationContent = notificationView.getContent();
Optional<ProjectVersionWrapper> optionalProjectAndVersion = retrieveProjectAndVersion(alertNotificationModel.getProviderConfigId(), notificationContent.getProjectVersion());
if (optionalProjectAndVersion.isPresent()) {
ProjectVersionWrapper projectAndVersion = optionalProjectAndVersion.get();
ProjectView project = projectAndVersion.getProjectView();
ProjectVersionView projectVersion = projectAndVersion.getProjectVersionView();
String projectName = project.getName();
BomEditWithProjectNameNotificationContent updatedNotificationContent = new BomEditWithProjectNameNotificationContent(notificationContent, projectName, projectVersion.getVersionName());
DetailedNotificationContent detailedContent = DetailedNotificationContent.project(alertNotificationModel, updatedNotificationContent, projectName, projectVersion.getVersionName());
return List.of(detailedContent);
}
return List.of();
}
use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class VulnerabilityNotificationDetailExtractor method extractDetailedContent.
@Override
public List<DetailedNotificationContent> extractDetailedContent(AlertNotificationModel alertNotificationModel, VulnerabilityNotificationView notificationView) {
VulnerabilityNotificationContent notificationContent = notificationView.getContent();
List<String> applicableSeverityTypes = new LinkedList<>(getApplicableSeverityTypes(notificationContent));
// Separating this notification to be per project should fix a bug with alerts being sent about unrelated projects
return notificationContent.getAffectedProjectVersions().stream().map(affectedProjectVersion -> new VulnerabilityUniqueProjectNotificationContent(notificationContent, affectedProjectVersion)).map(vulnerabilityUniqueProjectNotificationContent -> DetailedNotificationContent.vulnerability(// This leaves the AlertNotificationModel as the original but modifies the NotificationContent field
alertNotificationModel, vulnerabilityUniqueProjectNotificationContent, vulnerabilityUniqueProjectNotificationContent.getAffectedProjectVersion().getProjectName(), vulnerabilityUniqueProjectNotificationContent.getAffectedProjectVersion().getProjectVersionName(), applicableSeverityTypes)).collect(Collectors.toList());
}
use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class LicenseLimitNotificationDetailExtractorTest method extractDetailedContentTest.
@Test
public void extractDetailedContentTest() {
LicenseLimitNotificationDetailExtractor extractor = new LicenseLimitNotificationDetailExtractor();
LicenseLimitNotificationView notificationView = new LicenseLimitNotificationView();
LicenseLimitNotificationContent notificationContent = new LicenseLimitNotificationContent();
notificationView.setContent(notificationContent);
AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
assertEquals(1, detailedNotificationContents.size());
DetailedNotificationContent detailedNotificationContent = detailedNotificationContents.get(0);
assertTrue(detailedNotificationContent.getProjectName().isEmpty(), "Expected no project name to be present");
assertTrue(detailedNotificationContent.getPolicyName().isEmpty(), "Expected no policy name to be present");
assertEquals(0, detailedNotificationContent.getVulnerabilitySeverities().size());
}
Aggregations