use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient 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.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.
the class ProviderDataAccessorTest method init.
@BeforeEach
void init() throws Exception {
blackDuckPropertiesFactory = Mockito.mock(BlackDuckPropertiesFactory.class);
BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
Mockito.when(blackDuckPropertiesFactory.createProperties(Mockito.any(ConfigurationModel.class))).thenReturn(blackDuckProperties);
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Mockito.when(blackDuckProperties.createBlackDuckHttpClient(Mockito.any(IntLogger.class))).thenReturn(blackDuckHttpClient);
blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
Mockito.when(blackDuckProperties.createBlackDuckServicesFactory(Mockito.any(BlackDuckHttpClient.class), Mockito.any(IntLogger.class))).thenReturn(blackDuckServicesFactory);
projectService = Mockito.mock(ProjectService.class);
Mockito.when(blackDuckServicesFactory.createProjectService()).thenReturn(projectService);
blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
projectUsersService = Mockito.mock(ProjectUsersService.class);
Mockito.when(blackDuckServicesFactory.createProjectUsersService()).thenReturn(projectUsersService);
apiDiscovery = Mockito.mock(ApiDiscovery.class);
UrlMultipleResponses<UserView> usersLink = Mockito.mock(UrlMultipleResponses.class);
Mockito.when(apiDiscovery.metaUsersLink()).thenReturn(usersLink);
Mockito.when(blackDuckServicesFactory.getApiDiscovery()).thenReturn(apiDiscovery);
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
configurationFieldModel.setFieldValue(PROVIDER_CONFIG_NAME);
configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
providerConfiguration = new ConfigurationModel(1L, 1L, "createdAt", "lastModified", ConfigContextEnum.GLOBAL, Map.of(PROVIDER_CONFIG_NAME, configurationFieldModel));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(1L)).thenReturn(Optional.of(providerConfiguration));
Mockito.when(configurationModelConfigurationAccessor.getProviderConfigurationByName(Mockito.anyString())).thenReturn(Optional.of(providerConfiguration));
}
use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.
the class NotificationExtractorBlackDuckServicesFactoryCache method createBlackDuckServicesFactory.
private BlackDuckServicesFactory createBlackDuckServicesFactory(Long blackDuckConfigId) throws AlertConfigurationException {
Optional<BlackDuckProperties> optionalProperties = blackDuckPropertiesFactory.createProperties(blackDuckConfigId);
if (optionalProperties.isPresent()) {
BlackDuckProperties blackDuckProperties = optionalProperties.get();
Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
try {
BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckCacheClient(intLogger);
return blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
} catch (AlertException e) {
throw new AlertConfigurationException("The BlackDuck configuration is invalid", e);
}
}
throw new AlertConfigurationException(String.format("No BlackDuck configuration with id '%s' existed", blackDuckConfigId));
}
use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.
the class BlackDuckSSOConfigRetriever method fromProperties.
public static BlackDuckSSOConfigRetriever fromProperties(BlackDuckProperties blackDuckProperties) throws AlertException {
Logger logger = LoggerFactory.getLogger(BlackDuckSSOConfigRetriever.class);
Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(intLogger);
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
return new BlackDuckSSOConfigRetriever(blackDuckServicesFactory.getApiDiscovery(), blackDuckServicesFactory.getBlackDuckApiClient());
}
use of com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient in project hub-alert by blackducksoftware.
the class BlackDuckProjectExistencePopulator method createBlackDuckApiClient.
private BlackDuckApiClient createBlackDuckApiClient(ConfigurationModel providerGlobalConfig) throws AlertException {
StatefulProvider statefulProvider = blackDuckProvider.createStatefulProvider(providerGlobalConfig);
BlackDuckProperties blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
IntLogger intLogger = new Slf4jIntLogger(logger);
BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(intLogger);
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
return blackDuckServicesFactory.getBlackDuckApiClient();
}
Aggregations