use of com.synopsys.integration.blackduck.api.manual.component.RuleViolationNotificationContent 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.component.RuleViolationNotificationContent in project hub-alert by blackducksoftware.
the class BlackDuckResponseTestUtility method createRuleViolationUniquePolicyNotificationContent.
public RuleViolationUniquePolicyNotificationContent createRuleViolationUniquePolicyNotificationContent(String projectName, String projectVersionName) {
int componentVersionsInViolation = 1;
RuleViolationNotificationContent notificationContent = createRuleViolationNotificationContent(projectName, projectVersionName);
return new RuleViolationUniquePolicyNotificationContent(projectName, notificationContent.getProjectVersionName(), notificationContent.getProjectVersion(), componentVersionsInViolation, notificationContent.getComponentVersionStatuses(), notificationContent.getPolicyInfos().get(0));
}
use of com.synopsys.integration.blackduck.api.manual.component.RuleViolationNotificationContent in project hub-alert by blackducksoftware.
the class BlackDuckResponseTestUtility method createRuleViolationNotificationContent.
private RuleViolationNotificationContent createRuleViolationNotificationContent(String projectName, String projectVersionName) {
RuleViolationNotificationContent notificationContent = new RuleViolationNotificationContent();
notificationContent.setProjectName(projectName);
notificationContent.setProjectVersionName(projectVersionName);
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));
return notificationContent;
}
use of com.synopsys.integration.blackduck.api.manual.component.RuleViolationNotificationContent 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.component.RuleViolationNotificationContent in project hub-alert by blackducksoftware.
the class DetailedNotificationContentTest method policyTest.
@Test
public void policyTest() {
String projectName = "policy project";
String projectVersionName = "version";
String policyName = "policy name 01";
RuleViolationNotificationContent ruleViolationNotificationContent = new RuleViolationNotificationContent();
DetailedNotificationContent detailedContent = DetailedNotificationContent.policy(ALERT_NOTIFICATION_MODEL, ruleViolationNotificationContent, projectName, projectVersionName, policyName);
assertContent(detailedContent, ALERT_NOTIFICATION_MODEL.getProviderConfigId(), ruleViolationNotificationContent.getClass(), List.of());
assertEquals(projectName, detailedContent.getProjectName().orElse(null));
assertEquals(policyName, detailedContent.getPolicyName().orElse(null));
}
Aggregations