use of com.synopsys.integration.blackduck.api.manual.view.ComponentUnknownVersionNotificationView in project hub-alert by blackducksoftware.
the class ComponentUnknownVersionNotificationSerializationTest method testNotificationSerialization.
@Test
@Ignore
@Disabled
public void testNotificationSerialization() throws IntegrationException, InterruptedException {
LocalDateTime searchStartTime = LocalDateTime.now().minusMinutes(1);
AlertRequestUtility alertRequestUtility = IntegrationPerformanceTestRunner.createAlertRequestUtility(webApplicationContext);
BlackDuckProviderService blackDuckProviderService = new BlackDuckProviderService(alertRequestUtility, gson);
configureJob(alertRequestUtility, blackDuckProviderService);
ExternalId externalId = new ExternalId(Forge.MAVEN);
externalId.setGroup("commons-fileupload");
externalId.setName("commons-fileupload");
Predicate<ProjectVersionComponentVersionView> componentFilter = (component) -> component.getComponentName().equals("Apache Commons FileUpload");
blackDuckProviderService.triggerBlackDuckNotification(() -> externalId, componentFilter);
try {
WaitJobConfig waitJobConfig = new WaitJobConfig(intLogger, "notification serialization test notification wait", 300, searchStartTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(), 20);
NotificationReceivedWaitJobTask notificationWaitJobTask = new NotificationReceivedWaitJobTask(notificationAccessor, searchStartTime, "Apache Commons FileUpload", null, NotificationType.COMPONENT_UNKNOWN_VERSION);
WaitJob<Boolean> waitForNotificationToBeProcessed = WaitJob.createSimpleWait(waitJobConfig, notificationWaitJobTask);
boolean isComplete = waitForNotificationToBeProcessed.waitFor();
if (isComplete) {
String notificationContent = notificationWaitJobTask.getNotificationContent().orElseThrow(() -> new IllegalStateException("Expected notification is missing."));
BlackDuckResponseResolver resolver = blackDuckProviderService.getBlackDuckServicesFactory().getBlackDuckResponseResolver();
ComponentUnknownVersionNotificationView notificationView = resolver.resolve(notificationContent, ComponentUnknownVersionNotificationView.class);
assertNotNull(notificationView.getContent());
assertTrue(StringUtils.isNotBlank(notificationView.getContent().getComponentName()));
BlackDuckApiClient apiClient = blackDuckProviderService.getBlackDuckServicesFactory().getBlackDuckApiClient();
Optional<HttpUrl> componentUrl = HttpUrl.createSafely(notificationView.getContent().getBomComponent());
if (componentUrl.isPresent()) {
apiClient.delete(componentUrl.get());
}
}
} catch (InterruptedException ex) {
// if a timeout happens that's ok we are trying to ensure deserialization is correct.
}
}
use of com.synopsys.integration.blackduck.api.manual.view.ComponentUnknownVersionNotificationView 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()));
}
}
Aggregations