Search in sources :

Example 1 with BlackDuckPropertiesFactory

use of com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory 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 2 with BlackDuckPropertiesFactory

use of com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory in project hub-alert by blackducksoftware.

the class JobNotificationProcessorTest method createNotificationExtractorBlackDuckServicesFactoryCache.

private NotificationExtractorBlackDuckServicesFactoryCache createNotificationExtractorBlackDuckServicesFactoryCache() {
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    AlertProperties properties = new AlertProperties();
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    BlackDuckPropertiesFactory blackDuckPropertiesFactory = new BlackDuckPropertiesFactory(configurationModelConfigurationAccessor, GSON, properties, proxyManager);
    return new NotificationExtractorBlackDuckServicesFactoryCache(blackDuckPropertiesFactory);
}
Also used : ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) AlertProperties(com.synopsys.integration.alert.common.AlertProperties) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)

Example 3 with BlackDuckPropertiesFactory

use of com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory in project hub-alert by blackducksoftware.

the class BlackDuckGlobalApiActionTest method runApiActionTest.

private void runApiActionTest(ThrowingBiFunction<BlackDuckGlobalApiAction, FieldModel, FieldModel, AlertException> apiAction) throws AlertException {
    TaskManager taskManager = new TaskManager();
    BlackDuckProperties properties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(properties.isConfigEnabled()).thenReturn(true);
    FieldModel fieldModel = Mockito.mock(FieldModel.class);
    Mockito.when(fieldModel.getId()).thenReturn("1");
    Mockito.when(fieldModel.getFieldValue(Mockito.eq(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED))).thenReturn(Optional.of("true"));
    String providerConfigName = "Test Provider Config";
    Mockito.when(fieldModel.getFieldValue(Mockito.eq(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME))).thenReturn(Optional.of(providerConfigName));
    BlackDuckAccumulator blackDuckAccumulator = Mockito.mock(BlackDuckAccumulator.class);
    Mockito.when(blackDuckAccumulator.getTaskName()).thenReturn("accumulator-task");
    Mockito.when(blackDuckAccumulator.getFormatedNextRunTime()).thenReturn(Optional.of("SOON"));
    BlackDuckDataSyncTask blackDuckDataSyncTask = Mockito.mock(BlackDuckDataSyncTask.class);
    Mockito.when(blackDuckDataSyncTask.getTaskName()).thenReturn("data-sync-task");
    Mockito.when(blackDuckDataSyncTask.getFormatedNextRunTime()).thenReturn(Optional.of("SOON"));
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    Long providerConfigId = -1L;
    Mockito.when(configurationModel.getConfigurationId()).thenReturn(providerConfigId);
    Mockito.when(configurationModel.getDescriptorId()).thenReturn(providerConfigId);
    ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED);
    configurationFieldModel.setFieldValue("true");
    Mockito.when(configurationModel.getField(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED)).thenReturn(Optional.of(configurationFieldModel));
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getProviderConfigurationByName(Mockito.anyString())).thenReturn(Optional.of(configurationModel));
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(BlackDuckProviderKey.class), Mockito.eq(ConfigContextEnum.DISTRIBUTION))).thenReturn(List.of());
    BlackDuckProviderKey blackDuckProviderKey = new BlackDuckProviderKey();
    StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
    BlackDuckProvider blackDuckProvider = Mockito.mock(BlackDuckProvider.class);
    Mockito.when(blackDuckProvider.validate(configurationModel)).thenReturn(true);
    Mockito.when(blackDuckProvider.createStatefulProvider(configurationModel)).thenReturn(statefulProvider);
    Mockito.when(statefulProvider.getKey()).thenReturn(blackDuckProviderKey);
    Mockito.when(statefulProvider.getConfigId()).thenReturn(providerConfigId);
    Mockito.when(statefulProvider.isConfigEnabled()).thenReturn(true);
    Mockito.when(statefulProvider.getConfigName()).thenReturn(providerConfigName);
    Mockito.when(statefulProvider.getProperties()).thenReturn(properties);
    Mockito.when(statefulProvider.getTasks()).thenReturn(List.of(blackDuckAccumulator, blackDuckDataSyncTask));
    BlackDuckPropertiesFactory propertiesFactory = Mockito.mock(BlackDuckPropertiesFactory.class);
    Mockito.when(propertiesFactory.createProperties((ConfigurationModel) Mockito.any())).thenReturn(properties);
    ProviderDataAccessor providerDataAccessor = Mockito.mock(ProviderDataAccessor.class);
    ConfigurationFieldModelConverter fieldModelConverter = Mockito.mock(ConfigurationFieldModelConverter.class);
    Mockito.when(fieldModelConverter.convertToConfigurationModel(Mockito.any())).thenReturn(configurationModel);
    BlackDuckCacheHttpClientCache blackDuckCacheHttpClientCache = Mockito.mock(BlackDuckCacheHttpClientCache.class);
    ProviderSchedulingManager providerLifecycleManager = new ProviderSchedulingManager(List.of(blackDuckProvider), taskManager, null);
    BlackDuckGlobalApiAction blackDuckGlobalApiAction = new BlackDuckGlobalApiAction(blackDuckProvider, providerLifecycleManager, providerDataAccessor, configurationModelConfigurationAccessor, blackDuckCacheHttpClientCache);
    Optional<String> initialAccumulatorNextRunTime = taskManager.getNextRunTime(blackDuckAccumulator.getTaskName());
    Optional<String> initialSyncNextRunTime = taskManager.getNextRunTime(blackDuckDataSyncTask.getTaskName());
    assertTrue(initialAccumulatorNextRunTime.isEmpty());
    assertTrue(initialSyncNextRunTime.isEmpty());
    apiAction.apply(blackDuckGlobalApiAction, fieldModel);
    Optional<String> accumulatorNextRunTime = taskManager.getNextRunTime(blackDuckAccumulator.getTaskName());
    Optional<String> syncNextRunTime = taskManager.getNextRunTime(blackDuckDataSyncTask.getTaskName());
    assertTrue(accumulatorNextRunTime.isPresent(), "The accumulator task next run time was not present");
    assertTrue(syncNextRunTime.isPresent(), "The sync task next run time was not present");
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) BlackDuckCacheHttpClientCache(com.synopsys.integration.alert.provider.blackduck.BlackDuckCacheHttpClientCache) ProviderSchedulingManager(com.synopsys.integration.alert.api.provider.lifecycle.ProviderSchedulingManager) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) BlackDuckDataSyncTask(com.synopsys.integration.alert.provider.blackduck.task.BlackDuckDataSyncTask) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) BlackDuckAccumulator(com.synopsys.integration.alert.provider.blackduck.task.accumulator.BlackDuckAccumulator) TaskManager(com.synopsys.integration.alert.api.task.TaskManager) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider)

Aggregations

ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)3 BlackDuckPropertiesFactory (com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory)3 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)2 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)2 ProviderSchedulingManager (com.synopsys.integration.alert.api.provider.lifecycle.ProviderSchedulingManager)1 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)1 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)1 AlertProperties (com.synopsys.integration.alert.common.AlertProperties)1 ProviderDataAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor)1 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)1 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)1 ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)1 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)1 BlackDuckCacheHttpClientCache (com.synopsys.integration.alert.provider.blackduck.BlackDuckCacheHttpClientCache)1 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)1 BlackDuckProvider (com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider)1 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)1 BlackDuckDataSyncTask (com.synopsys.integration.alert.provider.blackduck.task.BlackDuckDataSyncTask)1 BlackDuckAccumulator (com.synopsys.integration.alert.provider.blackduck.task.accumulator.BlackDuckAccumulator)1 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)1