use of com.synopsys.integration.bdio.model.externalid.ExternalId 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.bdio.model.externalid.ExternalId in project hub-alert by blackducksoftware.
the class BlackDuckProviderService method triggerBlackDuckNotification.
public void triggerBlackDuckNotification(Supplier<ExternalId> externalIdSupplier, Predicate<ProjectVersionComponentVersionView> componentFilter) throws IntegrationException {
setupBlackDuckServicesFactory();
BlackDuckApiClient blackDuckService = blackDuckServicesFactory.getBlackDuckApiClient();
ProjectService projectService = blackDuckServicesFactory.createProjectService();
ProjectVersionWrapper projectVersion = projectService.getProjectVersion(blackDuckProjectName, blackDuckProjectVersion).orElseThrow(() -> new IntegrationException(String.format("Could not find the Black Duck project '%s' version '%s'", blackDuckProjectName, blackDuckProjectVersion)));
ProjectVersionView projectVersionView = projectVersion.getProjectVersionView();
List<ProjectVersionComponentVersionView> bomComponents = blackDuckService.getAllResponses(projectVersionView.metaComponentsLink());
Optional<ProjectVersionComponentVersionView> apacheCommonsFileUpload = bomComponents.stream().filter(componentFilter).findFirst();
if (apacheCommonsFileUpload.isPresent()) {
blackDuckService.delete(apacheCommonsFileUpload.get());
// Thread.currentThread().wait(1000);
}
ExternalId externalId = externalIdSupplier.get();
ProjectBomService projectBomService = blackDuckServicesFactory.createProjectBomService();
projectBomService.addComponentToProjectVersion(externalId, projectVersionView);
}
Aggregations