use of com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey in project hub-alert by blackducksoftware.
the class BlackDuckGlobalConfigurationFieldModelValidatorTest method nonUniqueName.
@Test
public void nonUniqueName() {
String duplicateName = "duplicateName";
Map<String, FieldValueModel> defaultKeyToValues = createDefaultKeyToValues();
FieldValueModel apiKeyFieldValueModel = new FieldValueModel(List.of(duplicateName), true);
defaultKeyToValues.put(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, apiKeyFieldValueModel);
FieldModel fieldModel = new FieldModel(new BlackDuckProviderKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), defaultKeyToValues);
ConfigurationFieldModel configurationFieldModel = Mockito.mock(ConfigurationFieldModel.class);
Mockito.when(configurationFieldModel.getFieldValue()).thenReturn(Optional.of(duplicateName));
ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
Mockito.when(configurationModel.getDescriptorContext()).thenReturn(ConfigContextEnum.GLOBAL);
Mockito.when(configurationModel.getField(Mockito.any())).thenReturn(Optional.of(configurationFieldModel));
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorType(Mockito.any())).thenReturn(List.of(configurationModel));
BlackDuckGlobalConfigurationFieldModelValidator blackDuckGlobalConfigurationValidator = new BlackDuckGlobalConfigurationFieldModelValidator(configurationModelConfigurationAccessor);
Set<AlertFieldStatus> alertFieldStatuses = blackDuckGlobalConfigurationValidator.validate(fieldModel);
assertEquals(1, alertFieldStatuses.size());
AlertFieldStatus alertFieldStatus = alertFieldStatuses.stream().findFirst().orElse(null);
assertNotNull(alertFieldStatus);
assertEquals(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, alertFieldStatus.getFieldName());
}
use of com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey in project hub-alert by blackducksoftware.
the class BlackDuckGlobalConfigurationFieldModelValidatorTest method apiKeyTooShort.
@Test
public void apiKeyTooShort() {
BlackDuckGlobalConfigurationFieldModelValidator blackDuckGlobalConfigurationValidator = new BlackDuckGlobalConfigurationFieldModelValidator(createDefaultConfigurationAccessor());
GlobalConfigurationValidatorAsserter globalConfigurationValidatorAsserter = new GlobalConfigurationValidatorAsserter(new BlackDuckProviderKey().getUniversalKey(), blackDuckGlobalConfigurationValidator, createDefaultKeyToValues());
globalConfigurationValidatorAsserter.assertInvalidValue(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, "too short");
}
use of com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey in project hub-alert by blackducksoftware.
the class BlackDuckGlobalConfigurationFieldModelValidatorTest method verifyValidConfiguration.
/*
* Provider config name: Required, no duplicate names
* Url: required, valid Url
* API key: required, Specific length
* Timeout: required, long timeout warning, < 0 timeout error
*/
@Test
public void verifyValidConfiguration() {
Map<String, FieldValueModel> defaultKeyToValues = createDefaultKeyToValues();
FieldModel fieldModel = new FieldModel(new BlackDuckProviderKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), defaultKeyToValues);
BlackDuckGlobalConfigurationFieldModelValidator blackDuckGlobalConfigurationValidator = new BlackDuckGlobalConfigurationFieldModelValidator(createDefaultConfigurationAccessor());
Set<AlertFieldStatus> alertFieldStatuses = blackDuckGlobalConfigurationValidator.validate(fieldModel);
assertEquals(0, alertFieldStatuses.size());
}
use of com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey in project hub-alert by blackducksoftware.
the class AlertIntegrationTestConfiguration method initBlackDuckData.
// FIXME delete
@Deprecated(forRemoval = true)
public void initBlackDuckData() throws AlertException {
TestProperties testProperties = new TestProperties();
ConfigurationFieldModel blackDuckURLField = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
blackDuckURLField.setFieldValue(testProperties.getBlackDuckURL());
ConfigurationFieldModel blackDuckAPITokenField = ConfigurationFieldModel.createSensitive(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
blackDuckAPITokenField.setFieldValue(testProperties.getBlackDuckAPIToken());
ConfigurationFieldModel blackDuckTimeoutField = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT);
blackDuckTimeoutField.setFieldValue(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_TIMEOUT));
BlackDuckProviderKey blackDuckProviderKey = new BlackDuckProviderKey();
ConfigurationModel blackDuckConfiguration = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(blackDuckProviderKey, ConfigContextEnum.GLOBAL).stream().findFirst().orElse(configurationModelConfigurationAccessor.createConfiguration(blackDuckProviderKey, ConfigContextEnum.GLOBAL, List.of(blackDuckURLField, blackDuckAPITokenField, blackDuckTimeoutField)));
configurationModelConfigurationAccessor.updateConfiguration(blackDuckConfiguration.getConfigurationId(), List.of(blackDuckURLField, blackDuckAPITokenField, blackDuckTimeoutField));
}
use of com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey in project hub-alert by blackducksoftware.
the class ProcessingJobAccessorTestIT method createProvider.
@BeforeEach
public void createProvider() {
ConfigurationFieldModel providerConfigEnabled = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED);
providerConfigEnabled.setFieldValue("true");
ConfigurationFieldModel providerConfigName = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
providerConfigName.setFieldValue("My Black Duck Config");
ConfigurationFieldModel blackduckUrl = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
blackduckUrl.setFieldValue("https://a-blackduck-server");
ConfigurationFieldModel blackduckApiKey = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
blackduckApiKey.setFieldValue("123456789012345678901234567890123456789012345678901234567890");
ConfigurationFieldModel blackduckTimeout = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT);
blackduckTimeout.setFieldValue("300");
List<ConfigurationFieldModel> providerConfigFields = List.of(providerConfigEnabled, providerConfigName, blackduckUrl, blackduckApiKey, blackduckTimeout);
providerConfigId = configurationModelConfigurationAccessor.createConfiguration(new BlackDuckProviderKey(), ConfigContextEnum.GLOBAL, providerConfigFields).getConfigurationId();
}
Aggregations