use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigurationValidatorTest method verifyMalformedUrl.
@Test
void verifyMalformedUrl() {
String badUrl = "notAValidUrl";
JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, badUrl, USER_NAME, PASSWORD, Boolean.FALSE, Boolean.FALSE);
ValidationResponseModel validationResponseModel = validator.validate(model);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(1, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
for (AlertFieldStatus status : alertFieldStatuses) {
assertEquals("url", status.getFieldName(), "Validation reported an error for an unexpected field.");
}
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigurationValidatorTest method verifyValidConfig.
@Test
void verifyValidConfig() {
JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, URL, USER_NAME, PASSWORD, Boolean.FALSE, Boolean.FALSE);
ValidationResponseModel validationResponseModel = validator.validate(model);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(0, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus 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.descriptor.config.field.errors.AlertFieldStatus 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.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class AzureBoardsGlobalConfigurationFieldModelValidatorTest method oauthRequestIsRunningError.
@Test
public void oauthRequestIsRunningError() {
OAuthRequestValidator oAuthRequestValidator = new OAuthRequestValidator();
oAuthRequestValidator.addAuthorizationRequest("test");
AzureBoardsGlobalConfigurationFieldModelValidator azureBoardsGlobalConfigurationValidator = new AzureBoardsGlobalConfigurationFieldModelValidator(oAuthRequestValidator);
Set<AlertFieldStatus> fieldStatuses = azureBoardsGlobalConfigurationValidator.validate(new FieldModel(new AzureBoardsChannelKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), createValidKeyToValues()));
assertEquals(1, fieldStatuses.size());
AlertFieldStatus alertFieldStatus = fieldStatuses.stream().findFirst().orElse(null);
assertNotNull(alertFieldStatus);
assertEquals(AzureBoardsDescriptor.KEY_OAUTH, alertFieldStatus.getFieldName());
}
Aggregations