Search in sources :

Example 6 with RuleViolationNotificationView

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

the class NotificationProcessorTest method processNotificationsWithMoreThanAPageOfJobsTest.

@Test
public // Passing case: A distribution event is sent
void processNotificationsWithMoreThanAPageOfJobsTest() {
    String projectName = "2468 - Test Project";
    String matchingProjectNamePattern = "2468.*";
    String nonMatchingProjectNamePattern = "13579asdf - DO NOT MATCH";
    String targetNotificationType = NotificationType.RULE_VIOLATION.name();
    String nonTargetNotificationType = NotificationType.LICENSE_LIMIT.name();
    RuleViolationNotificationView ruleViolationNotificationView = createRuleViolationNotificationView(projectName);
    String notificationContentString = GSON.toJson(ruleViolationNotificationView);
    AlertNotificationModel notification = createNotification(targetNotificationType, notificationContentString);
    FilteredDistributionJobResponseModel matchingJob = createJob(targetNotificationType, true, matchingProjectNamePattern);
    List<FilteredDistributionJobResponseModel> nonMatchingJobs = createNonMatchingJobs(250, nonTargetNotificationType, true, nonMatchingProjectNamePattern);
    // Only needs to handle the target notification type
    NotificationDetailExtractionDelegator extractionDelegator = new NotificationDetailExtractionDelegator(BLACK_DUCK_RESPONSE_RESOLVER, List.of(RULE_VIOLATION_NDE));
    ProcessingJobAccessor processingJobAccessor = new MockProcessingJobAccessor(nonMatchingJobs, matchingJob, 199);
    // This is needed to verify the notification is "sent"
    ProviderMessageDistributor distributor = Mockito.mock(ProviderMessageDistributor.class);
    Mockito.doNothing().when(distributor).distribute(Mockito.any(), Mockito.any());
    NotificationProcessor notificationProcessor = createNotificationProcessor(extractionDelegator, processingJobAccessor, distributor);
    notificationProcessor.processNotifications(List.of(notification), List.of(FrequencyType.REAL_TIME, FrequencyType.DAILY));
    // Exactly one distribution event should be sent
    Mockito.verify(distributor, Mockito.times(1)).distribute(Mockito.any(), Mockito.any());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) ProviderMessageDistributor(com.synopsys.integration.alert.processor.api.distribute.ProviderMessageDistributor) ProcessingJobAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProcessingJobAccessor) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator) RuleViolationNotificationView(com.synopsys.integration.blackduck.api.manual.view.RuleViolationNotificationView) Test(org.junit.jupiter.api.Test)

Example 7 with RuleViolationNotificationView

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

Example 8 with RuleViolationNotificationView

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

the class NotificationRemovalTest method createABatchOfNotifications.

private void createABatchOfNotifications(ConfigurationModel providerConfig, OffsetDateTime notificationCreationTime, boolean batchOfProcessedNotifications) {
    int count = BATCH_SIZE;
    List<AlertNotificationModel> notifications = new ArrayList<>(BATCH_SIZE);
    ProviderDetails providerDetails = new ProviderDetails(providerConfig.getConfigurationId(), new LinkableItem("Black Duck", "bd-server", BLACKDUCK_PROVIDER_URL));
    for (int index = 0; index < count; index++) {
        RuleViolationNotificationView ruleViolationNotificationView = createRuleViolationNotificationView(PROJECT_NAME);
        String notificationContentString = GSON.toJson(ruleViolationNotificationView);
        notifications.add(createNotification(providerDetails, NotificationType.RULE_VIOLATION.name(), notificationContentString, notificationCreationTime, batchOfProcessedNotifications));
    }
    notifications = notificationAccessor.saveAllNotifications(notifications);
    createAuditEntries(notifications);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ArrayList(java.util.ArrayList) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) 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