use of com.synopsys.integration.alert.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.
the class AlertStartupInitializer method saveAction.
private Collection<ConfigurationFieldModel> saveAction(DescriptorKey descriptorKey, Collection<ConfigurationFieldModel> configurationFieldModels) throws AlertException {
Map<String, FieldValueModel> fieldValueModelMap = modelConverter.convertToFieldValuesMap(configurationFieldModels);
FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), fieldValueModelMap);
FieldModel savedFieldModel = fieldModelProcessor.performBeforeSaveAction(fieldModel);
return modelConverter.convertToConfigurationFieldModelMap(savedFieldModel).values();
}
use of com.synopsys.integration.alert.common.rest.model.FieldValueModel 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.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.
the class BlackDuckGlobalConfigurationFieldModelValidatorTest method createDefaultKeyToValues.
private Map<String, FieldValueModel> createDefaultKeyToValues() {
Map<String, FieldValueModel> keyToValues = new HashMap<>();
FieldValueModel nameFieldValueModel = new FieldValueModel(List.of("uniqueName"), true);
FieldValueModel urlFieldValueModel = new FieldValueModel(List.of("https://google.com"), true);
FieldValueModel apiKeyFieldValueModel = new FieldValueModel(List.of("This should be long enough to pass: aksjdfalkfalksfsdfljahfjdasjkdfhlajfhlkasjhdflaskjhdflkasjhflksajhflaksjhflkasjhdflakjshfldjakfasjf"), true);
FieldValueModel timeoutFieldValueModel = new FieldValueModel(List.of("300"), true);
keyToValues.put(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, nameFieldValueModel);
keyToValues.put(BlackDuckDescriptor.KEY_BLACKDUCK_URL, urlFieldValueModel);
keyToValues.put(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, apiKeyFieldValueModel);
keyToValues.put(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT, timeoutFieldValueModel);
return keyToValues;
}
use of com.synopsys.integration.alert.common.rest.model.FieldValueModel 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.common.rest.model.FieldValueModel in project hub-alert by blackducksoftware.
the class AzureBoardsGlobalConfigurationFieldModelValidatorTest method createValidKeyToValues.
private Map<String, FieldValueModel> createValidKeyToValues() {
Map<String, FieldValueModel> keyToValues = new HashMap<>();
FieldValueModel organizationName = new FieldValueModel(List.of("organizationName"), true);
FieldValueModel clientKey = new FieldValueModel(List.of("clientKey"), true);
FieldValueModel clientSecret = new FieldValueModel(List.of("clientSecret"), true);
keyToValues.put(AzureBoardsDescriptor.KEY_ORGANIZATION_NAME, organizationName);
keyToValues.put(AzureBoardsDescriptor.KEY_CLIENT_ID, clientKey);
keyToValues.put(AzureBoardsDescriptor.KEY_CLIENT_SECRET, clientSecret);
return keyToValues;
}
Aggregations