use of com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView in project hub-alert by blackducksoftware.
the class BlackDuckResponseTestUtility method createRuleViolationNotificationView.
public RuleViolationNotificationView createRuleViolationNotificationView(String projectName, String projectVersionName) {
RuleViolationNotificationContent notificationContent = createRuleViolationNotificationContent(projectName, projectVersionName);
RuleViolationNotificationView notificationView = new RuleViolationNotificationView();
notificationView.setContent(notificationContent);
notificationView.setType(NotificationType.RULE_VIOLATION);
return notificationView;
}
use of com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView in project hub-alert by blackducksoftware.
the class JobNotificationProcessorTest method createNotification.
private AlertNotificationModel createNotification(String notificationType) {
RuleViolationNotificationView ruleViolationNotificationView = blackDuckResponseTestUtility.createRuleViolationNotificationView("project-name", "project-version-name");
String notificationContent = GSON.toJson(ruleViolationNotificationView);
return new AlertNotificationModel(123L, PROVIDER_DETAILS.getProviderConfigId(), PROVIDER_DETAILS.getProvider().getLabel(), PROVIDER_DETAILS.getProvider().getValue(), notificationType, notificationContent, OffsetDateTime.now(), OffsetDateTime.now(), false);
}
use of com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView 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.blackduck.api.manual.view.RuleViolationNotificationView in project hub-alert by blackducksoftware.
the class NotificationContentProcessorTest method createNotification.
private AlertNotificationModel createNotification(String notificationType) {
RuleViolationNotificationView ruleViolationNotificationView = blackDuckResponseTestUtility.createRuleViolationNotificationView(projectName, projectVersionName);
String notificationContent = GSON.toJson(ruleViolationNotificationView);
return new AlertNotificationModel(notificationId, PROVIDER_DETAILS.getProviderConfigId(), PROVIDER_DETAILS.getProvider().getLabel(), PROVIDER_DETAILS.getProvider().getValue(), notificationType, notificationContent, OffsetDateTime.now(), OffsetDateTime.now(), false);
}
use of com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView in project hub-alert by blackducksoftware.
the class NotificationProcessorTest method createRuleViolationNotificationView.
// ==============
// Helper methods
// ==============
private RuleViolationNotificationView createRuleViolationNotificationView(String projectName) {
RuleViolationNotificationContent notificationContent = new RuleViolationNotificationContent();
notificationContent.setProjectName(projectName);
notificationContent.setProjectVersionName("a-project-version");
notificationContent.setProjectVersion("https://a-project-version");
notificationContent.setComponentVersionsInViolation(1);
PolicyInfo policyInfo = new PolicyInfo();
policyInfo.setPolicy("https://a-policy");
policyInfo.setPolicyName("a policy");
policyInfo.setSeverity(PolicyRuleSeverityType.MAJOR.name());
notificationContent.setPolicyInfos(List.of(policyInfo));
ComponentVersionStatus componentVersionStatus = new ComponentVersionStatus();
componentVersionStatus.setBomComponent("https://bom-component");
componentVersionStatus.setComponentName("component name");
componentVersionStatus.setComponent("https://component");
componentVersionStatus.setComponentVersionName("component-version name");
componentVersionStatus.setComponentVersion("https://component-version");
componentVersionStatus.setPolicies(List.of(policyInfo.getPolicy()));
componentVersionStatus.setBomComponentVersionPolicyStatus(ProjectVersionComponentPolicyStatusType.IN_VIOLATION.name());
componentVersionStatus.setComponentIssueLink("https://component-issues");
notificationContent.setComponentVersionStatuses(List.of(componentVersionStatus));
RuleViolationNotificationView notificationView = new RuleViolationNotificationView();
notificationView.setContent(notificationContent);
notificationView.setType(NotificationType.RULE_VIOLATION);
return notificationView;
}
Aggregations