Search in sources :

Example 1 with RuleViolationNotificationContent

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;
}
Also used : RuleViolationNotificationContent(com.synopsys.integration.blackduck.api.manual.component.RuleViolationNotificationContent) RuleViolationNotificationView(com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView)

Example 2 with RuleViolationNotificationContent

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));
}
Also used : RuleViolationNotificationContent(com.synopsys.integration.blackduck.api.manual.component.RuleViolationNotificationContent) RuleViolationUniquePolicyNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.RuleViolationUniquePolicyNotificationContent)

Example 3 with RuleViolationNotificationContent

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;
}
Also used : RuleViolationNotificationContent(com.synopsys.integration.blackduck.api.manual.component.RuleViolationNotificationContent) ComponentVersionStatus(com.synopsys.integration.blackduck.api.manual.component.ComponentVersionStatus) PolicyInfo(com.synopsys.integration.blackduck.api.manual.component.PolicyInfo)

Example 4 with RuleViolationNotificationContent

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());
    }
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) RuleViolationNotificationContent(com.synopsys.integration.blackduck.api.manual.component.RuleViolationNotificationContent) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) RuleViolationNotificationView(com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView) Test(org.junit.jupiter.api.Test)

Example 5 with RuleViolationNotificationContent

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));
}
Also used : RuleViolationNotificationContent(com.synopsys.integration.blackduck.api.manual.component.RuleViolationNotificationContent) Test(org.junit.jupiter.api.Test)

Aggregations

RuleViolationNotificationContent (com.synopsys.integration.blackduck.api.manual.component.RuleViolationNotificationContent)7 RuleViolationNotificationView (com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView)4 ComponentVersionStatus (com.synopsys.integration.blackduck.api.manual.component.ComponentVersionStatus)3 PolicyInfo (com.synopsys.integration.blackduck.api.manual.component.PolicyInfo)3 Test (org.junit.jupiter.api.Test)2 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)1 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)1 RuleViolationUniquePolicyNotificationContent (com.synopsys.integration.alert.provider.blackduck.processor.model.RuleViolationUniquePolicyNotificationContent)1