Search in sources :

Example 6 with BlackDuckProviderKey

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());
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) Test(org.junit.jupiter.api.Test)

Example 7 with BlackDuckProviderKey

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");
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) GlobalConfigurationValidatorAsserter(com.synopsys.integration.alert.test.common.channel.GlobalConfigurationValidatorAsserter) Test(org.junit.jupiter.api.Test)

Example 8 with BlackDuckProviderKey

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());
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) Test(org.junit.jupiter.api.Test)

Example 9 with BlackDuckProviderKey

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));
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)

Example 10 with BlackDuckProviderKey

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();
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)23 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)11 Test (org.junit.jupiter.api.Test)10 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)4 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)4 BlackDuckComponentVulnerabilityDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckComponentVulnerabilityDetailsCreator)4 BlackDuckMessageBomComponentDetailsCreatorFactory (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreatorFactory)4 BomComponent404Handler (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BomComponent404Handler)4 BlackDuckComponentPolicyDetailsCreatorFactory (com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckComponentPolicyDetailsCreatorFactory)4 BlackDuckPolicySeverityConverter (com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckPolicySeverityConverter)4 GlobalConfigurationValidatorAsserter (com.synopsys.integration.alert.test.common.channel.GlobalConfigurationValidatorAsserter)4 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)3 ProviderKey (com.synopsys.integration.alert.descriptor.api.model.ProviderKey)3 BlackDuckPolicyComponentConcernCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckPolicyComponentConcernCreator)3 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)3 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)3 HttpUrl (com.synopsys.integration.rest.HttpUrl)3 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)2 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)2