use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class ComponentUnknownVersionNotificationDetailExtractorTest method extractDetailedContentTest.
@Test
public void extractDetailedContentTest() throws IOException {
String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
ComponentUnknownVersionNotificationView notificationView = gson.fromJson(jsonContent, ComponentUnknownVersionNotificationView.class);
ComponentUnknownVersionNotificationContent notificationContent = notificationView.getContent();
AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
ComponentUnknownVersionNotificationDetailExtractor extractor = new ComponentUnknownVersionNotificationDetailExtractor();
List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
assertEquals(1, detailedNotificationContents.size());
for (DetailedNotificationContent detailedContent : detailedNotificationContents) {
Optional<String> optionalProjectName = detailedContent.getProjectName();
assertTrue(optionalProjectName.isPresent(), "Expect project name to be present");
assertEquals(notificationContent.getProjectName(), optionalProjectName.get());
assertTrue(detailedContent.getPolicyName().isEmpty(), "Expected no policy name to be present");
assertEquals(0, detailedContent.getVulnerabilitySeverities().size());
assertEquals(ComponentUnknownVersionWithStatusNotificationContent.class, detailedContent.getNotificationContentWrapper().getNotificationContentClass());
ComponentUnknownVersionWithStatusNotificationContent content = (ComponentUnknownVersionWithStatusNotificationContent) detailedContent.getNotificationContentWrapper().getNotificationContent();
assertEquals("project", content.getProjectName());
assertEquals("1", content.getProjectVersionName());
assertEquals("Apache Tomcat", content.getComponentName());
assertEquals(1, content.getCriticalVulnerabilityCount());
assertEquals(8, content.getHighVulnerabilityCount());
assertEquals(58, content.getMediumVulnerabilityCount());
assertEquals(29, content.getLowVulnerabilityCount());
assertEquals("0.0.1", content.getCriticalVulnerabilityVersionName());
assertEquals("6.0.0", content.getHighVulnerabilityVersionName());
assertEquals("6.0.0", content.getMediumVulnerabilityVersionName());
assertEquals("TOMCAT_9_0_0_M7", content.getLowVulnerabilityVersionName());
assertTrue(StringUtils.isNotBlank(content.getBomComponent()));
assertTrue(StringUtils.isNotBlank(content.getComponent()));
assertTrue(StringUtils.isNotBlank(content.getCriticalVulnerabilityVersion()));
assertTrue(StringUtils.isNotBlank(content.getHighVulnerabilityVersion()));
assertTrue(StringUtils.isNotBlank(content.getMediumVulnerabilityVersion()));
assertTrue(StringUtils.isNotBlank(content.getLowVulnerabilityVersion()));
}
}
use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class PolicyOverrideNotificationDetailExtractorTest method extractDetailedContentTest.
@Test
public void extractDetailedContentTest() throws IOException {
String notificationString = TestResourceUtils.readFileToString(POLICY_OVERRIDE_JSON_PATH);
PolicyOverrideNotificationView notificationView = gson.fromJson(notificationString, PolicyOverrideNotificationView.class);
PolicyOverrideNotificationContent notificationContent = notificationView.getContent();
AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
PolicyOverrideNotificationDetailExtractor extractor = new PolicyOverrideNotificationDetailExtractor();
List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
assertEquals(2, detailedNotificationContents.size());
for (DetailedNotificationContent detailedNotificationContent : detailedNotificationContents) {
Optional<String> detailedProjectName = detailedNotificationContent.getProjectName();
assertTrue(detailedProjectName.isPresent(), "Expected project name to be present");
assertEquals(notificationContent.getProjectName(), detailedProjectName.get());
}
Set<String> detailedPolicyNames = detailedNotificationContents.stream().map(DetailedNotificationContent::getPolicyName).flatMap(Optional::stream).collect(Collectors.toSet());
for (PolicyInfo policyInfo : notificationContent.getPolicyInfos()) {
assertTrue(detailedPolicyNames.contains(policyInfo.getPolicyName()), "Expected extracted policy name to be present in notification policy infos");
}
}
use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class ProjectVersionNotificationDetailExtractorTest method extractDetailedContentTest.
@Test
public void extractDetailedContentTest() throws IOException {
String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
ProjectVersionNotificationView projectNotificationView = gson.fromJson(jsonContent, ProjectVersionNotificationView.class);
ProjectVersionNotificationContent projectVersionNotificationContent = projectNotificationView.getContent();
AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
ProjectVersionNotificationDetailExtractor extractor = new ProjectVersionNotificationDetailExtractor();
List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, projectNotificationView);
assertEquals(1, detailedNotificationContents.size());
DetailedNotificationContent detailedNotificationContent = detailedNotificationContents.get(0);
Optional<String> optionalProjectName = detailedNotificationContent.getProjectName();
assertTrue(optionalProjectName.isPresent(), "Expect project name to be present");
assertEquals(projectVersionNotificationContent.getProjectName(), optionalProjectName.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 RuleViolationClearedNotificationContentDetailExtractorTest method extractDetailedContentTest.
@Test
public void extractDetailedContentTest() throws IOException {
String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
RuleViolationClearedNotificationView notificationView = gson.fromJson(jsonContent, RuleViolationClearedNotificationView.class);
RuleViolationClearedNotificationContent notificationContent = notificationView.getContent();
AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
RuleViolationClearedNotificationDetailExtractor extractor = new RuleViolationClearedNotificationDetailExtractor();
List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
assertEquals(2, detailedNotificationContents.size());
for (DetailedNotificationContent detailedContent : detailedNotificationContents) {
Optional<String> optionalProjectName = detailedContent.getProjectName();
assertTrue(optionalProjectName.isPresent(), "Expect project name to be present");
assertEquals(notificationContent.getProjectName(), optionalProjectName.get());
Optional<String> optionalPolicyName = detailedContent.getPolicyName();
assertTrue(optionalPolicyName.isPresent(), "Expected policy name to be present");
boolean containsPolicy = notificationContent.getPolicyInfos().stream().map(PolicyInfo::getPolicyName).anyMatch(policyName -> policyName.equals(optionalPolicyName.get()));
assertTrue(containsPolicy, "Expected policy name to be present in original notification");
assertEquals(0, detailedContent.getVulnerabilitySeverities().size());
}
}
use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.
the class JobNotificationMapper method createRequestModelFromNotifications.
private FilteredDistributionJobRequestModel createRequestModelFromNotifications(List<DetailedNotificationContent> detailedContents, List<FrequencyType> frequencies) {
Long commonProviderConfigId = detailedContents.stream().map(DetailedNotificationContent::getProviderConfigId).findAny().orElseThrow(() -> new AlertRuntimeException("Notification(s) missing provider configuration id"));
FilteredDistributionJobRequestModel filteredDistributionJobRequestModel = new FilteredDistributionJobRequestModel(commonProviderConfigId, frequencies);
for (DetailedNotificationContent detailedNotificationContent : detailedContents) {
detailedNotificationContent.getProjectName().ifPresent(filteredDistributionJobRequestModel::addProjectName);
filteredDistributionJobRequestModel.addNotificationType(detailedNotificationContent.getNotificationContentWrapper().extractNotificationType());
filteredDistributionJobRequestModel.addVulnerabilitySeverities(detailedNotificationContent.getVulnerabilitySeverities());
detailedNotificationContent.getPolicyName().ifPresent(filteredDistributionJobRequestModel::addPolicyName);
}
return filteredDistributionJobRequestModel;
}
Aggregations