Search in sources :

Example 21 with DetailedNotificationContent

use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.

the class ComponentUnknownVersionNotificationDetailExtractorTest method extractDetailedContentTest.

@Test
public void extractDetailedContentTest() throws IOException {
    String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
    ComponentUnknownVersionNotificationView notificationView = gson.fromJson(jsonContent, ComponentUnknownVersionNotificationView.class);
    ComponentUnknownVersionNotificationContent notificationContent = notificationView.getContent();
    AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
    ComponentUnknownVersionNotificationDetailExtractor extractor = new ComponentUnknownVersionNotificationDetailExtractor();
    List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
    assertEquals(1, 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());
        assertTrue(detailedContent.getPolicyName().isEmpty(), "Expected no policy name to be present");
        assertEquals(0, detailedContent.getVulnerabilitySeverities().size());
        assertEquals(ComponentUnknownVersionWithStatusNotificationContent.class, detailedContent.getNotificationContentWrapper().getNotificationContentClass());
        ComponentUnknownVersionWithStatusNotificationContent content = (ComponentUnknownVersionWithStatusNotificationContent) detailedContent.getNotificationContentWrapper().getNotificationContent();
        assertEquals("project", content.getProjectName());
        assertEquals("1", content.getProjectVersionName());
        assertEquals("Apache Tomcat", content.getComponentName());
        assertEquals(1, content.getCriticalVulnerabilityCount());
        assertEquals(8, content.getHighVulnerabilityCount());
        assertEquals(58, content.getMediumVulnerabilityCount());
        assertEquals(29, content.getLowVulnerabilityCount());
        assertEquals("0.0.1", content.getCriticalVulnerabilityVersionName());
        assertEquals("6.0.0", content.getHighVulnerabilityVersionName());
        assertEquals("6.0.0", content.getMediumVulnerabilityVersionName());
        assertEquals("TOMCAT_9_0_0_M7", content.getLowVulnerabilityVersionName());
        assertTrue(StringUtils.isNotBlank(content.getBomComponent()));
        assertTrue(StringUtils.isNotBlank(content.getComponent()));
        assertTrue(StringUtils.isNotBlank(content.getCriticalVulnerabilityVersion()));
        assertTrue(StringUtils.isNotBlank(content.getHighVulnerabilityVersion()));
        assertTrue(StringUtils.isNotBlank(content.getMediumVulnerabilityVersion()));
        assertTrue(StringUtils.isNotBlank(content.getLowVulnerabilityVersion()));
    }
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ComponentUnknownVersionNotificationView(com.synopsys.integration.blackduck.api.manual.view.ComponentUnknownVersionNotificationView) ComponentUnknownVersionNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ComponentUnknownVersionNotificationContent) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) ComponentUnknownVersionWithStatusNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.ComponentUnknownVersionWithStatusNotificationContent) Test(org.junit.jupiter.api.Test)

Example 22 with DetailedNotificationContent

use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent 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 23 with DetailedNotificationContent

use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.

the class ProjectVersionNotificationDetailExtractorTest method extractDetailedContentTest.

@Test
public void extractDetailedContentTest() throws IOException {
    String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
    ProjectVersionNotificationView projectNotificationView = gson.fromJson(jsonContent, ProjectVersionNotificationView.class);
    ProjectVersionNotificationContent projectVersionNotificationContent = projectNotificationView.getContent();
    AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
    ProjectVersionNotificationDetailExtractor extractor = new ProjectVersionNotificationDetailExtractor();
    List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, projectNotificationView);
    assertEquals(1, detailedNotificationContents.size());
    DetailedNotificationContent detailedNotificationContent = detailedNotificationContents.get(0);
    Optional<String> optionalProjectName = detailedNotificationContent.getProjectName();
    assertTrue(optionalProjectName.isPresent(), "Expect project name to be present");
    assertEquals(projectVersionNotificationContent.getProjectName(), optionalProjectName.get());
    assertTrue(detailedNotificationContent.getPolicyName().isEmpty(), "Expected no policy name to be present");
    assertEquals(0, detailedNotificationContent.getVulnerabilitySeverities().size());
}
Also used : ProjectVersionNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProjectVersionNotificationView(com.synopsys.integration.blackduck.api.manual.view.ProjectVersionNotificationView) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) Test(org.junit.jupiter.api.Test)

Example 24 with DetailedNotificationContent

use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.

the class RuleViolationClearedNotificationContentDetailExtractorTest method extractDetailedContentTest.

@Test
public void extractDetailedContentTest() throws IOException {
    String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
    RuleViolationClearedNotificationView notificationView = gson.fromJson(jsonContent, RuleViolationClearedNotificationView.class);
    RuleViolationClearedNotificationContent notificationContent = notificationView.getContent();
    AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
    RuleViolationClearedNotificationDetailExtractor extractor = new RuleViolationClearedNotificationDetailExtractor();
    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) RuleViolationClearedNotificationView(com.synopsys.integration.blackduck.api.manual.view.RuleViolationClearedNotificationView) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) RuleViolationClearedNotificationContent(com.synopsys.integration.blackduck.api.manual.component.RuleViolationClearedNotificationContent) Test(org.junit.jupiter.api.Test)

Example 25 with DetailedNotificationContent

use of com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent in project hub-alert by blackducksoftware.

the class JobNotificationMapper method createRequestModelFromNotifications.

private FilteredDistributionJobRequestModel createRequestModelFromNotifications(List<DetailedNotificationContent> detailedContents, List<FrequencyType> frequencies) {
    Long commonProviderConfigId = detailedContents.stream().map(DetailedNotificationContent::getProviderConfigId).findAny().orElseThrow(() -> new AlertRuntimeException("Notification(s) missing provider configuration id"));
    FilteredDistributionJobRequestModel filteredDistributionJobRequestModel = new FilteredDistributionJobRequestModel(commonProviderConfigId, frequencies);
    for (DetailedNotificationContent detailedNotificationContent : detailedContents) {
        detailedNotificationContent.getProjectName().ifPresent(filteredDistributionJobRequestModel::addProjectName);
        filteredDistributionJobRequestModel.addNotificationType(detailedNotificationContent.getNotificationContentWrapper().extractNotificationType());
        filteredDistributionJobRequestModel.addVulnerabilitySeverities(detailedNotificationContent.getVulnerabilitySeverities());
        detailedNotificationContent.getPolicyName().ifPresent(filteredDistributionJobRequestModel::addPolicyName);
    }
    return filteredDistributionJobRequestModel;
}
Also used : DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) FilteredDistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel)

Aggregations

DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)27 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)21 Test (org.junit.jupiter.api.Test)17 FilteredDistributionJobResponseModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel)8 NotificationContentComponent (com.synopsys.integration.blackduck.api.manual.component.NotificationContentComponent)6 FilteredDistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel)3 VulnerabilityNotificationView (com.synopsys.integration.blackduck.api.manual.view.VulnerabilityNotificationView)3 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)2 VulnerabilityUniqueProjectNotificationContent (com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent)2 VulnerabilityNotificationContent (com.synopsys.integration.blackduck.api.manual.component.VulnerabilityNotificationContent)2 BomEditNotificationView (com.synopsys.integration.blackduck.api.manual.view.BomEditNotificationView)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)1 AlertPagedDetails (com.synopsys.integration.alert.common.rest.model.AlertPagedDetails)1 NotificationDetailExtractor (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractor)1 FilteredJobNotificationWrapper (com.synopsys.integration.alert.processor.api.filter.FilteredJobNotificationWrapper)1 NotificationContentWrapper (com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper)1