use of com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper in project hub-alert by blackducksoftware.
the class ProjectVersionNotificationMessageExtractorTest method extractTest.
@Test
public void extractTest() throws IntegrationException {
NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Mockito.when(blackDuckHttpClient.getBlackDuckUrl()).thenReturn(new HttpUrl("https://a.blackduck.server.example.com"));
Mockito.when(blackDuckServicesFactory.getBlackDuckHttpClient()).thenReturn(blackDuckHttpClient);
Mockito.when(servicesFactoryCache.retrieveBlackDuckServicesFactory(Mockito.anyLong())).thenReturn(blackDuckServicesFactory);
ProjectVersionNotificationContent projectVersionNotificationContent = createProjectVersionNotificationContent();
NotificationContentWrapper notificationContentWrapper = createNotificationContentWrapper(projectVersionNotificationContent);
ProjectVersionNotificationMessageExtractor extractor = new ProjectVersionNotificationMessageExtractor(providerKey, servicesFactoryCache);
ProviderMessageHolder providerMessageHolder = extractor.extract(notificationContentWrapper, projectVersionNotificationContent);
assertEquals(1, providerMessageHolder.getProjectMessages().size());
assertEquals(0, providerMessageHolder.getSimpleMessages().size());
ProjectMessage projectMessage = providerMessageHolder.getProjectMessages().get(0);
assertEquals(MessageReason.PROJECT_VERSION_STATUS, projectMessage.getMessageReason());
assertTrue(projectMessage.getOperation().isPresent());
assertEquals(ProjectOperation.CREATE, projectMessage.getOperation().get());
assertTrue(projectMessage.getBomComponents().isEmpty());
assertEquals(PROJECT, projectMessage.getProject().getValue());
assertTrue(projectMessage.getProject().getUrl().isPresent());
assertEquals(PROJECT_URL, projectMessage.getProject().getUrl().get());
assertTrue(projectMessage.getProjectVersion().isPresent());
LinkableItem projectVersion = projectMessage.getProjectVersion().get();
assertEquals(PROJECT_VERSION, projectVersion.getValue());
assertTrue(projectVersion.getUrl().isPresent());
assertEquals(PROJECT_VERSION_URL, projectVersion.getUrl().get());
}
use of com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper in project hub-alert by blackducksoftware.
the class VulnerabilityNotificationDetailExtractorTest method verifyExtraction.
@Test
public void verifyExtraction() throws IOException {
VulnerabilityNotificationView vulnerabilityNotificationView = getVulnerabilityNotificationView(VULNERABILITY_COMPLEX_JSON_PATH);
VulnerabilityNotificationContent content = vulnerabilityNotificationView.getContent();
VulnerabilityNotificationDetailExtractor vulnerabilityNotificationDetailExtractor = new VulnerabilityNotificationDetailExtractor();
AlertNotificationModel alertNotificationModel = createAlertNotificationModel();
List<DetailedNotificationContent> filterableNotificationWrappers = vulnerabilityNotificationDetailExtractor.extractDetailedContent(alertNotificationModel, vulnerabilityNotificationView);
assertEquals(3, filterableNotificationWrappers.size());
for (DetailedNotificationContent filterableNotificationWrapper : filterableNotificationWrappers) {
NotificationContentWrapper notificationContentWrapper = filterableNotificationWrapper.getNotificationContentWrapper();
assertEquals(NotificationType.VULNERABILITY.name(), notificationContentWrapper.extractNotificationType());
// The Vuln extractor should return a different object structure
assertNotEquals(content, notificationContentWrapper.getNotificationContent());
assertEquals(3, filterableNotificationWrapper.getVulnerabilitySeverities().size());
assertFalse(filterableNotificationWrapper.getVulnerabilitySeverities().contains(VulnerabilitySeverityType.CRITICAL.name()));
assertTrue(filterableNotificationWrapper.getPolicyName().isEmpty(), "Expected no policy name to be present");
}
}
use of com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper in project hub-alert by blackducksoftware.
the class NotificationContentProcessorTest method processNotificationContentSummaryTest.
@Test
public void processNotificationContentSummaryTest() {
AlertNotificationModel notificationModel = createNotification(NotificationType.RULE_VIOLATION.name());
RuleViolationUniquePolicyNotificationContent notificationContent = blackDuckResponseTestUtility.createRuleViolationUniquePolicyNotificationContent(projectName, projectVersionName);
NotificationContentWrapper notificationContentWrapper1 = new NotificationContentWrapper(notificationModel, notificationContent, RuleViolationUniquePolicyNotificationContent.class);
// When set to summary, project messages will be summarized into a SimpleMessage rather than ProjectMessage
ProcessedProviderMessageHolder processedProviderMessageHolder = notificationContentProcessor.processNotificationContent(ProcessingType.SUMMARY, List.of(notificationContentWrapper1));
List<ProcessedProviderMessage<ProjectMessage>> processedProviderMessages = processedProviderMessageHolder.getProcessedProjectMessages();
List<ProcessedProviderMessage<SimpleMessage>> processedSimpleMessages = processedProviderMessageHolder.getProcessedSimpleMessages();
assertTrue(processedProviderMessages.isEmpty());
assertEquals(1, processedSimpleMessages.size());
ProcessedProviderMessage<SimpleMessage> processedSimpleMessage = processedSimpleMessages.get(0);
assertEquals(1, processedSimpleMessage.getNotificationIds().size());
assertTrue(processedSimpleMessage.getNotificationIds().contains(notificationId));
SimpleMessage simpleMessage = processedSimpleMessage.getProviderMessage();
assertEquals(PROVIDER_DETAILS, simpleMessage.getProviderDetails());
assertTrue(simpleMessage.getSource().isPresent());
ProjectMessage sourceProjectMessage = simpleMessage.getSource().get();
assertEquals(projectName, sourceProjectMessage.getProject().getValue());
assertTrue(sourceProjectMessage.getProjectVersion().isPresent());
assertEquals(projectVersionName, sourceProjectMessage.getProjectVersion().get().getValue());
}
use of com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper in project hub-alert by blackducksoftware.
the class JobNotificationProcessor method processAndDistribute.
private void processAndDistribute(ProcessedNotificationDetails processedNotificationDetails, ProcessingType processingType, List<AlertNotificationModel> notifications) {
List<NotificationContentWrapper> notificationContentWrappers = notifications.stream().map(notificationDetailExtractionDelegator::wrapNotification).flatMap(List::stream).map(DetailedNotificationContent::getNotificationContentWrapper).collect(Collectors.toList());
ProcessedProviderMessageHolder processedMessageHolder = notificationContentProcessor.processNotificationContent(processingType, notificationContentWrappers);
providerMessageDistributor.distribute(processedNotificationDetails, processedMessageHolder);
}
use of com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper in project hub-alert by blackducksoftware.
the class LicenseLimitNotificationMessageExtractorTest method extractTest.
@Test
public void extractTest() {
LicenseLimitNotificationContent notificationContentComponent = createLicenseLimitNotificationContent();
NotificationContentWrapper notificationContentWrapper = createNotificationContentWrapper(notificationContentComponent);
LicenseLimitNotificationMessageExtractor licenseLimitNotificationMessageExtractor = new LicenseLimitNotificationMessageExtractor(blackDuckProviderKey);
ProviderMessageHolder providerMessageHolder = licenseLimitNotificationMessageExtractor.extract(notificationContentWrapper, notificationContentComponent);
assertEquals(0, providerMessageHolder.getProjectMessages().size());
assertEquals(1, providerMessageHolder.getSimpleMessages().size());
SimpleMessage simpleMessage = providerMessageHolder.getSimpleMessages().get(0);
assertEquals(summary, simpleMessage.getSummary());
assertEquals(description, simpleMessage.getDescription());
assertEquals(4, simpleMessage.getDetails().size());
}
Aggregations