Search in sources :

Example 6 with PolicyInfo

use of com.synopsys.integration.blackduck.api.manual.component.PolicyInfo in project hub-alert by blackducksoftware.

the class RuleViolationClearedUniquePolicyNotificationContentTest method getContentsTest.

@Test
public void getContentsTest() {
    int componentVersionsCleared = 1;
    ComponentVersionStatus componentVersionStatus = new ComponentVersionStatus();
    PolicyInfo policyInfo = new PolicyInfo();
    RuleViolationClearedUniquePolicyNotificationContent notificationContent = new RuleViolationClearedUniquePolicyNotificationContent(PROJECT_NAME, PROJECT_VERSION_NAME, PROJECT_VERSION_URL, componentVersionsCleared, List.of(componentVersionStatus), policyInfo);
    assertEquals(PROJECT_NAME, notificationContent.getProjectName());
    assertEquals(PROJECT_VERSION_NAME, notificationContent.getProjectVersionName());
    assertEquals(PROJECT_VERSION_URL, notificationContent.getProjectVersionUrl());
    assertEquals(componentVersionsCleared, notificationContent.getComponentVersionsCleared());
    assertTrue(notificationContent.getComponentVersionStatuses().contains(componentVersionStatus));
    assertEquals(policyInfo, notificationContent.getPolicyInfo());
}
Also used : ComponentVersionStatus(com.synopsys.integration.blackduck.api.manual.component.ComponentVersionStatus) PolicyInfo(com.synopsys.integration.blackduck.api.manual.component.PolicyInfo) Test(org.junit.jupiter.api.Test)

Example 7 with PolicyInfo

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

Example 8 with PolicyInfo

use of com.synopsys.integration.blackduck.api.manual.component.PolicyInfo in project hub-alert by blackducksoftware.

the class RuleViolationUniquePolicyNotificationContentTest method getContentsTest.

@Test
public void getContentsTest() {
    int componentVersionsInViolation = 1;
    ComponentVersionStatus componentVersionStatus = new ComponentVersionStatus();
    PolicyInfo policyInfo = new PolicyInfo();
    RuleViolationUniquePolicyNotificationContent notificationContent = new RuleViolationUniquePolicyNotificationContent(PROJECT_NAME, PROJECT_VERSION_NAME, PROJECT_VERSION_URL, componentVersionsInViolation, List.of(componentVersionStatus), policyInfo);
    assertEquals(PROJECT_NAME, notificationContent.getProjectName());
    assertEquals(PROJECT_VERSION_NAME, notificationContent.getProjectVersionName());
    assertEquals(PROJECT_VERSION_URL, notificationContent.getProjectVersionUrl());
    assertEquals(componentVersionsInViolation, notificationContent.getComponentVersionsInViolation());
    assertTrue(notificationContent.getComponentVersionStatuses().contains(componentVersionStatus));
    assertEquals(policyInfo, notificationContent.getPolicyInfo());
}
Also used : ComponentVersionStatus(com.synopsys.integration.blackduck.api.manual.component.ComponentVersionStatus) PolicyInfo(com.synopsys.integration.blackduck.api.manual.component.PolicyInfo) Test(org.junit.jupiter.api.Test)

Example 9 with PolicyInfo

use of com.synopsys.integration.blackduck.api.manual.component.PolicyInfo 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;
}
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) RuleViolationNotificationView(com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView)

Example 10 with PolicyInfo

use of com.synopsys.integration.blackduck.api.manual.component.PolicyInfo in project hub-alert by blackducksoftware.

the class NotificationRemovalTest method createRuleViolationNotificationView.

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

Aggregations

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