Search in sources :

Example 66 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class BomEditNotificationDetailExtractorTest method extractDetailedContentErrorTest.

@Test
public void extractDetailedContentErrorTest() throws IOException, IntegrationException {
    Long blackDuckConfigId = 0L;
    String notificationString = TestResourceUtils.readFileToString(BOM_EDIT_JSON_PATH);
    BomEditNotificationView notificationView = gson.fromJson(notificationString, BomEditNotificationView.class);
    NotificationExtractorBlackDuckServicesFactoryCache cache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
    Mockito.doThrow(new AlertConfigurationException("Expected Exception thrown creating BlackDuckServicesFactory")).when(cache).retrieveBlackDuckServicesFactory(Mockito.anyLong());
    BomEditNotificationDetailExtractor extractor = new BomEditNotificationDetailExtractor(cache);
    AlertNotificationModel notification = new AlertNotificationModel(0L, blackDuckConfigId, "BlackDuck", "Config 1", null, null, null, null, false);
    List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
    assertEquals(0, detailedNotificationContents.size());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) BomEditNotificationView(com.synopsys.integration.blackduck.api.manual.view.BomEditNotificationView) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 67 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel 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 68 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel 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 69 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel 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 70 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel 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)

Aggregations

AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)94 Test (org.junit.jupiter.api.Test)62 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)21 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)20 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)16 PageRequest (org.springframework.data.domain.PageRequest)16 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)14 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)14 OffsetDateTime (java.time.OffsetDateTime)13 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)11 ArrayList (java.util.ArrayList)10 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)9 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)7 FilteredDistributionJobResponseModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel)7 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)6 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)6 NotificationContentComponent (com.synopsys.integration.blackduck.api.manual.component.NotificationContentComponent)5 PageImpl (org.springframework.data.domain.PageImpl)5 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)4 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)4