use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class BomEditNotificationDetailExtractorTest method extractDetailedContentErrorTest.
@Test
public void extractDetailedContentErrorTest() throws IOException, IntegrationException {
Long blackDuckConfigId = 0L;
String notificationString = TestResourceUtils.readFileToString(BOM_EDIT_JSON_PATH);
BomEditNotificationView notificationView = gson.fromJson(notificationString, BomEditNotificationView.class);
NotificationExtractorBlackDuckServicesFactoryCache cache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
Mockito.doThrow(new AlertConfigurationException("Expected Exception thrown creating BlackDuckServicesFactory")).when(cache).retrieveBlackDuckServicesFactory(Mockito.anyLong());
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(0, detailedNotificationContents.size());
}
use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.
the class RuleViolationNotificationDetailExtractorTest method extractDetailedContentTest.
@Test
public void extractDetailedContentTest() throws IOException {
String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
RuleViolationNotificationView notificationView = gson.fromJson(jsonContent, RuleViolationNotificationView.class);
RuleViolationNotificationContent notificationContent = notificationView.getContent();
AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
RuleViolationNotificationDetailExtractor extractor = new RuleViolationNotificationDetailExtractor();
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.common.rest.model.AlertNotificationModel 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.common.rest.model.AlertNotificationModel 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.common.rest.model.AlertNotificationModel 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());
}
Aggregations