use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.
the class PolicyNotificationFilterCustomFunctionAction method createBlackDuckServicesFactory.
private Optional<BlackDuckServicesFactory> createBlackDuckServicesFactory(FieldModel fieldModel) throws IntegrationException {
Optional<BlackDuckProperties> optionalBlackDuckProperties = createBlackDuckProperties(fieldModel);
if (optionalBlackDuckProperties.isPresent()) {
BlackDuckProperties blackDuckProperties = optionalBlackDuckProperties.get();
BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(logger);
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, logger);
return Optional.of(blackDuckServicesFactory);
}
return Optional.empty();
}
use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.
the class ProjectNotificationMessageExtractorTest 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);
ProjectNotificationContent projectNotificationContent = createProjectNotificationContent();
NotificationContentWrapper notificationContentWrapper = createNotificationContentWrapper(projectNotificationContent);
ProjectNotificationMessageExtractor extractor = new ProjectNotificationMessageExtractor(providerKey, servicesFactoryCache);
ProviderMessageHolder providerMessageHolder = extractor.extract(notificationContentWrapper, projectNotificationContent);
assertEquals(1, providerMessageHolder.getProjectMessages().size());
assertEquals(0, providerMessageHolder.getSimpleMessages().size());
ProjectMessage projectMessage = providerMessageHolder.getProjectMessages().get(0);
assertEquals(MessageReason.PROJECT_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());
assertFalse(projectMessage.getProjectVersion().isPresent());
}
use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.
the class BlackDuckNotificationRetrieverFactory method createBlackDuckNotificationRetriever.
public Optional<BlackDuckNotificationRetriever> createBlackDuckNotificationRetriever(BlackDuckProperties blackDuckProperties) {
Optional<BlackDuckHttpClient> optionalBlackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClientAndLogErrors(logger);
if (optionalBlackDuckHttpClient.isPresent()) {
BlackDuckHttpClient blackDuckHttpClient = optionalBlackDuckHttpClient.get();
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, new Slf4jIntLogger(logger));
BlackDuckNotificationRetriever notificationRetriever = new BlackDuckNotificationRetriever(blackDuckServicesFactory.getBlackDuckApiClient(), blackDuckServicesFactory.getApiDiscovery());
return Optional.of(notificationRetriever);
} else {
logger.warn("The BlackDuck configuration '{}' could not be used to retrieve notifications", blackDuckProperties.getConfigName());
}
return Optional.empty();
}
use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.
the class NotificationContentProcessorTest method createRuleViolationNotificationMessageExtractor.
private RuleViolationNotificationMessageExtractor createRuleViolationNotificationMessageExtractor() throws IntegrationException {
BlackDuckProviderKey providerKey = new BlackDuckProviderKey();
NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
BlackDuckPolicySeverityConverter blackDuckPolicySeverityConverter = new BlackDuckPolicySeverityConverter();
BlackDuckPolicyComponentConcernCreator blackDuckPolicyComponentConcernCreator = new BlackDuckPolicyComponentConcernCreator(blackDuckPolicySeverityConverter);
BlackDuckComponentVulnerabilityDetailsCreator vulnerabilityDetailsCreator = new BlackDuckComponentVulnerabilityDetailsCreator();
BlackDuckComponentPolicyDetailsCreatorFactory blackDuckComponentPolicyDetailsCreatorFactory = new BlackDuckComponentPolicyDetailsCreatorFactory(blackDuckPolicySeverityConverter);
BlackDuckMessageBomComponentDetailsCreatorFactory detailsCreatorFactory = new BlackDuckMessageBomComponentDetailsCreatorFactory(vulnerabilityDetailsCreator, blackDuckComponentPolicyDetailsCreatorFactory);
// Mocks for AbstractRuleViolationNotificationMessageExtractor
BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Mockito.when(servicesFactoryCache.retrieveBlackDuckServicesFactory(Mockito.any())).thenReturn(blackDuckServicesFactory);
Mockito.when(blackDuckServicesFactory.getBlackDuckHttpClient()).thenReturn(blackDuckHttpClient);
Mockito.when(blackDuckHttpClient.getBlackDuckUrl()).thenReturn(new HttpUrl(PROVIDER_DETAILS.getProvider().getUrl().get()));
BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
ProjectVersionComponentVersionView projectVersionComponentVersionView = blackDuckResponseTestUtility.createProjectVersionComponentVersionView();
Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class))).thenReturn(projectVersionComponentVersionView);
BomComponent404Handler bomComponent404Handler = new BomComponent404Handler();
return new RuleViolationNotificationMessageExtractor(providerKey, servicesFactoryCache, blackDuckPolicyComponentConcernCreator, detailsCreatorFactory, bomComponent404Handler);
}
use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.
the class JobNotificationProcessorTest method createRuleViolationNotificationMessageExtractor.
private RuleViolationNotificationMessageExtractor createRuleViolationNotificationMessageExtractor() throws IntegrationException {
BlackDuckProviderKey providerKey = new BlackDuckProviderKey();
NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
BlackDuckPolicySeverityConverter blackDuckPolicySeverityConverter = new BlackDuckPolicySeverityConverter();
BlackDuckPolicyComponentConcernCreator blackDuckPolicyComponentConcernCreator = new BlackDuckPolicyComponentConcernCreator(blackDuckPolicySeverityConverter);
BlackDuckComponentVulnerabilityDetailsCreator vulnerabilityDetailsCreator = new BlackDuckComponentVulnerabilityDetailsCreator();
BlackDuckComponentPolicyDetailsCreatorFactory blackDuckComponentPolicyDetailsCreatorFactory = new BlackDuckComponentPolicyDetailsCreatorFactory(blackDuckPolicySeverityConverter);
BlackDuckMessageBomComponentDetailsCreatorFactory detailsCreatorFactory = new BlackDuckMessageBomComponentDetailsCreatorFactory(vulnerabilityDetailsCreator, blackDuckComponentPolicyDetailsCreatorFactory);
// Mocks for AbstractRuleViolationNotificationMessageExtractor
BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Mockito.when(servicesFactoryCache.retrieveBlackDuckServicesFactory(Mockito.any())).thenReturn(blackDuckServicesFactory);
Mockito.when(blackDuckServicesFactory.getBlackDuckHttpClient()).thenReturn(blackDuckHttpClient);
Mockito.when(blackDuckHttpClient.getBlackDuckUrl()).thenReturn(new HttpUrl(PROVIDER_DETAILS.getProvider().getUrl().get()));
BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
ProjectVersionComponentVersionView projectVersionComponentVersionView = blackDuckResponseTestUtility.createProjectVersionComponentVersionView();
Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class))).thenReturn(projectVersionComponentVersionView);
BomComponent404Handler bomComponent404Handler = new BomComponent404Handler();
return new RuleViolationNotificationMessageExtractor(providerKey, servicesFactoryCache, blackDuckPolicyComponentConcernCreator, detailsCreatorFactory, bomComponent404Handler);
}
Aggregations