Search in sources :

Example 1 with BlackDuckProvider

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

the class SystemValidatorTest method testValidateHubValidProviderWithProxy.

@Test
public void testValidateHubValidProviderWithProxy() throws Exception {
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    CredentialsBuilder builder = Credentials.newBuilder();
    builder.setUsername("AUser");
    builder.setPassword("aPassword");
    Credentials credentials = builder.build();
    ProxyInfoBuilder proxyBuilder = ProxyInfo.newBuilder();
    proxyBuilder.setHost("google.com");
    proxyBuilder.setPort(3218);
    proxyBuilder.setCredentials(credentials);
    proxyBuilder.setNtlmDomain(null);
    proxyBuilder.setNtlmWorkstation(null);
    ProxyInfo expectedProxyInfo = proxyBuilder.build();
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(expectedProxyInfo);
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckProperties.getBlackDuckUrl()).thenReturn(Optional.of("Black Duck URL"));
    Mockito.when(blackDuckProperties.getApiToken()).thenReturn("Black Duck API Token");
    Mockito.when(blackDuckProperties.getBlackDuckTimeout()).thenReturn(BlackDuckProperties.DEFAULT_TIMEOUT);
    BlackDuckServerConfig serverConfig = Mockito.mock(BlackDuckServerConfig.class);
    Mockito.when(serverConfig.canConnect(Mockito.any(IntLogger.class))).thenReturn(false);
    DefaultSystemMessageAccessor defaultSystemMessageUtility = Mockito.mock(DefaultSystemMessageAccessor.class);
    StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
    BlackDuckProvider provider = Mockito.mock(BlackDuckProvider.class);
    Mockito.when(provider.createStatefulProvider(Mockito.any())).thenReturn(statefulProvider);
    Mockito.when(statefulProvider.getProperties()).thenReturn(blackDuckProperties);
    BlackDuckSystemValidator blackDuckSystemValidator = new BlackDuckSystemValidator(defaultSystemMessageUtility);
    blackDuckSystemValidator.validate(blackDuckProperties);
    Mockito.verify(defaultSystemMessageUtility, Mockito.times(0)).addSystemMessage(Mockito.anyString(), Mockito.any(SystemMessageSeverity.class), Mockito.any(SystemMessageType.class));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) CredentialsBuilder(com.synopsys.integration.rest.credentials.CredentialsBuilder) SystemMessageSeverity(com.synopsys.integration.alert.common.enumeration.SystemMessageSeverity) SystemMessageType(com.synopsys.integration.alert.common.enumeration.SystemMessageType) DefaultSystemMessageAccessor(com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor) BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) Credentials(com.synopsys.integration.rest.credentials.Credentials) ProxyInfoBuilder(com.synopsys.integration.rest.proxy.ProxyInfoBuilder) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) Test(org.junit.jupiter.api.Test)

Example 2 with BlackDuckProvider

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

the class SystemValidatorTest method testvalidateBlackDuckProviderNullURL.

@Test
public void testvalidateBlackDuckProviderNullURL() throws Exception {
    long configId = 1L;
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckProperties.getBlackDuckUrl()).thenReturn(Optional.empty());
    Mockito.when(blackDuckProperties.getBlackDuckTimeout()).thenReturn(BlackDuckProperties.DEFAULT_TIMEOUT);
    Mockito.when(blackDuckProperties.getConfigName()).thenReturn(DEFAULT_CONFIG_NAME);
    Mockito.when(blackDuckProperties.getConfigId()).thenReturn(configId);
    StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
    BlackDuckProvider provider = Mockito.mock(BlackDuckProvider.class);
    Mockito.when(provider.createStatefulProvider(Mockito.any())).thenReturn(statefulProvider);
    Mockito.when(statefulProvider.getProperties()).thenReturn(blackDuckProperties);
    DefaultSystemMessageAccessor defaultSystemMessageUtility = Mockito.mock(DefaultSystemMessageAccessor.class);
    String missingUrlMessageType = BlackDuckSystemValidator.createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_URL_MISSING);
    BlackDuckSystemValidator blackDuckSystemValidator = new BlackDuckSystemValidator(defaultSystemMessageUtility);
    blackDuckSystemValidator.validate(blackDuckProperties);
    Mockito.verify(defaultSystemMessageUtility).addSystemMessage(Mockito.eq(String.format(BlackDuckSystemValidator.MISSING_BLACKDUCK_URL_ERROR_W_CONFIG_FORMAT, DEFAULT_CONFIG_NAME)), Mockito.eq(SystemMessageSeverity.WARNING), Mockito.eq(missingUrlMessageType));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) DefaultSystemMessageAccessor(com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) Test(org.junit.jupiter.api.Test)

Example 3 with BlackDuckProvider

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

the class SystemValidatorTest method testvalidateBlackDuckProviderLocalhostURL.

@Test
public void testvalidateBlackDuckProviderLocalhostURL() throws Exception {
    long configId = 1L;
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckProperties.getBlackDuckUrl()).thenReturn(Optional.of("https://localhost:443"));
    Mockito.when(blackDuckProperties.getBlackDuckTimeout()).thenReturn(BlackDuckProperties.DEFAULT_TIMEOUT);
    Mockito.when(blackDuckProperties.getConfigName()).thenReturn(DEFAULT_CONFIG_NAME);
    Mockito.when(blackDuckProperties.getConfigId()).thenReturn(configId);
    BlackDuckServerConfig blackDuckServerConfig = Mockito.mock(BlackDuckServerConfig.class);
    Mockito.when(blackDuckProperties.createBlackDuckServerConfig(Mockito.any(IntLogger.class))).thenReturn(blackDuckServerConfig);
    StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
    BlackDuckProvider provider = Mockito.mock(BlackDuckProvider.class);
    Mockito.when(provider.createStatefulProvider(Mockito.any())).thenReturn(statefulProvider);
    Mockito.when(statefulProvider.getProperties()).thenReturn(blackDuckProperties);
    DefaultSystemMessageAccessor defaultSystemMessageUtility = Mockito.mock(DefaultSystemMessageAccessor.class);
    String localhostMessageType = BlackDuckSystemValidator.createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_LOCALHOST);
    BlackDuckSystemValidator blackDuckSystemValidator = new BlackDuckSystemValidator(defaultSystemMessageUtility);
    blackDuckSystemValidator.validate(blackDuckProperties);
    Mockito.verify(defaultSystemMessageUtility).addSystemMessage(Mockito.eq(String.format(BlackDuckSystemValidator.BLACKDUCK_LOCALHOST_ERROR_FORMAT, DEFAULT_CONFIG_NAME)), Mockito.eq(SystemMessageSeverity.WARNING), Mockito.eq(localhostMessageType));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) DefaultSystemMessageAccessor(com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) Test(org.junit.jupiter.api.Test)

Example 4 with BlackDuckProvider

use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider 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)

Example 5 with BlackDuckProvider

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

the class SystemValidatorTest method testValidateHubValidProvider.

@Test
public void testValidateHubValidProvider() throws Exception {
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckProperties.getBlackDuckUrl()).thenReturn(Optional.of("https://alert.example.com:443/alert"));
    Mockito.when(blackDuckProperties.getApiToken()).thenReturn("Test Api Key");
    Mockito.when(blackDuckProperties.getBlackDuckTimeout()).thenReturn(BlackDuckProperties.DEFAULT_TIMEOUT);
    BlackDuckServerConfig serverConfig = Mockito.mock(BlackDuckServerConfig.class);
    Mockito.when(serverConfig.canConnect(Mockito.any(IntLogger.class))).thenReturn(true);
    Mockito.when(blackDuckProperties.createBlackDuckServerConfig(Mockito.any(IntLogger.class))).thenReturn(serverConfig);
    DefaultSystemMessageAccessor defaultSystemMessageUtility = Mockito.mock(DefaultSystemMessageAccessor.class);
    StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
    BlackDuckProvider provider = Mockito.mock(BlackDuckProvider.class);
    Mockito.when(provider.createStatefulProvider(Mockito.any())).thenReturn(statefulProvider);
    Mockito.when(statefulProvider.getProperties()).thenReturn(blackDuckProperties);
    BlackDuckSystemValidator blackDuckSystemValidator = new BlackDuckSystemValidator(defaultSystemMessageUtility);
    blackDuckSystemValidator.validate(blackDuckProperties);
    Mockito.verify(defaultSystemMessageUtility, Mockito.times(0)).addSystemMessage(Mockito.anyString(), Mockito.any(SystemMessageSeverity.class), Mockito.any(SystemMessageType.class));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) SystemMessageSeverity(com.synopsys.integration.alert.common.enumeration.SystemMessageSeverity) SystemMessageType(com.synopsys.integration.alert.common.enumeration.SystemMessageType) DefaultSystemMessageAccessor(com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor) BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) Test(org.junit.jupiter.api.Test)

Aggregations

StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)6 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)6 BlackDuckProvider (com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider)6 DefaultSystemMessageAccessor (com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor)5 BlackDuckSystemValidator (com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator)5 Test (org.junit.jupiter.api.Test)5 ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)4 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)4 IntLogger (com.synopsys.integration.log.IntLogger)4 SystemMessageSeverity (com.synopsys.integration.alert.common.enumeration.SystemMessageSeverity)2 SystemMessageType (com.synopsys.integration.alert.common.enumeration.SystemMessageType)2 ProviderSchedulingManager (com.synopsys.integration.alert.api.provider.lifecycle.ProviderSchedulingManager)1 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)1 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)1 ProviderDataAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor)1 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)1 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)1 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)1 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)1 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)1