Search in sources :

Example 1 with RuleViolationNotificationView

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

Example 2 with RuleViolationNotificationView

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);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) RuleViolationNotificationView(com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView)

Example 3 with RuleViolationNotificationView

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());
    }
}
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 4 with RuleViolationNotificationView

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);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) RuleViolationNotificationView(com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView)

Example 5 with RuleViolationNotificationView

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;
}
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

RuleViolationNotificationView (com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView)8 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)5 RuleViolationNotificationContent (com.synopsys.integration.blackduck.api.manual.component.RuleViolationNotificationContent)4 ComponentVersionStatus (com.synopsys.integration.blackduck.api.manual.component.ComponentVersionStatus)2 PolicyInfo (com.synopsys.integration.blackduck.api.manual.component.PolicyInfo)2 Test (org.junit.jupiter.api.Test)2 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)1 ProcessingJobAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProcessingJobAccessor)1 FilteredDistributionJobResponseModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel)1 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)1 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)1 ProviderMessageDistributor (com.synopsys.integration.alert.processor.api.distribute.ProviderMessageDistributor)1 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)1 ArrayList (java.util.ArrayList)1