Search in sources :

Example 1 with PolicyOverrideNotificationContent

use of com.synopsys.integration.blackduck.api.manual.component.PolicyOverrideNotificationContent 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)

Aggregations

AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)1 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)1 PolicyInfo (com.synopsys.integration.blackduck.api.manual.component.PolicyInfo)1 PolicyOverrideNotificationContent (com.synopsys.integration.blackduck.api.manual.component.PolicyOverrideNotificationContent)1 PolicyOverrideNotificationView (com.synopsys.integration.blackduck.api.manual.view.PolicyOverrideNotificationView)1 Test (org.junit.jupiter.api.Test)1