Search in sources :

Example 1 with BlackDuckHttpClient

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());
}
Also used : ProjectVersionNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) HttpUrl(com.synopsys.integration.rest.HttpUrl) NotificationContentWrapper(com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper) Test(org.junit.jupiter.api.Test)

Example 2 with BlackDuckHttpClient

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));
}
Also used : ProjectUsersService(com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with BlackDuckHttpClient

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));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 4 with BlackDuckHttpClient

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());
}
Also used : Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) Logger(org.slf4j.Logger)

Example 5 with BlackDuckHttpClient

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();
}
Also used : Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider)

Aggregations

BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)15 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)12 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)8 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)4 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)4 HttpUrl (com.synopsys.integration.rest.HttpUrl)4 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)3 IntLogger (com.synopsys.integration.log.IntLogger)3 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)2 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)2 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)2 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)2 NotificationContentWrapper (com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper)2 RuleViolationNotificationMessageExtractor (com.synopsys.integration.alert.provider.blackduck.processor.message.RuleViolationNotificationMessageExtractor)2 BlackDuckComponentVulnerabilityDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckComponentVulnerabilityDetailsCreator)2 BlackDuckMessageBomComponentDetailsCreatorFactory (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreatorFactory)2 BomComponent404Handler (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BomComponent404Handler)2 BlackDuckComponentPolicyDetailsCreatorFactory (com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckComponentPolicyDetailsCreatorFactory)2