use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluginServiceTest method shouldTalkToPluginForPluginSettingsValidation_ConfigRepo.
@Test
public void shouldTalkToPluginForPluginSettingsValidation_ConfigRepo() {
PluginSettingsMetadataStore.getInstance().addMetadataFor("plugin-id-4", PluginConstants.CONFIG_REPO_EXTENSION, null, null);
when(configRepoExtension.isConfigRepoPlugin("plugin-id-4")).thenReturn(true);
when(configRepoExtension.canHandlePlugin("plugin-id-4")).thenReturn(true);
when(configRepoExtension.validatePluginSettings(eq("plugin-id-4"), any(PluginSettingsConfiguration.class))).thenReturn(new ValidationResult());
PluginSettings pluginSettings = new PluginSettings("plugin-id-4");
pluginService.validatePluginSettingsFor(pluginSettings);
verify(configRepoExtension).validatePluginSettings(eq("plugin-id-4"), any(PluginSettingsConfiguration.class));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluggableScmServiceTest method shouldPassValidationIfAllRequiredFieldsHaveValuesForSCM.
@Test
public void shouldPassValidationIfAllRequiredFieldsHaveValuesForSCM() {
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
configuration.getProperty("KEY1").setConfigurationValue(new ConfigurationValue("junk"));
SCM modifiedSCM = new SCM("scm-id", new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
when(scmExtension.isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
pluggableScmService.validate(modifiedSCM);
assertTrue(validationResult.getErrors().isEmpty());
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluggableScmServiceTest method shouldValidateSCM.
@Test
public void shouldValidateSCM() {
SCMConfiguration scmConfig = new SCMConfiguration(new SCMProperty("KEY2").with(Property.REQUIRED, false));
scmConfigurations.add(scmConfig);
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
SCM modifiedSCM = new SCM("scm-id", new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("KEY1", "error message"));
when(scmExtension.isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
pluggableScmService.validate(modifiedSCM);
assertFalse(modifiedSCM.getConfiguration().getProperty("KEY1").errors().isEmpty());
assertThat(modifiedSCM.getConfiguration().getProperty("KEY1").errors().firstError(), is("error message"));
verify(scmExtension).isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluggableScmServiceTest method shouldHandleIncorrectKeyForValidateSCM.
@Test
public void shouldHandleIncorrectKeyForValidateSCM() {
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
configuration.getProperty("KEY1").setConfigurationValue(new ConfigurationValue("junk"));
SCM modifiedSCM = new SCM("scm-id", new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("NON-EXISTENT-KEY", "error message"));
when(scmExtension.isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
pluggableScmService.validate(modifiedSCM);
assertTrue(modifiedSCM.errors().isEmpty());
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluggableScmServiceTest method shouldValidateMandatoryAndSecureFieldsForSCM.
@Test
public void shouldValidateMandatoryAndSecureFieldsForSCM() {
SCMConfiguration scmConfig = new SCMConfiguration(new SCMProperty("KEY2").with(Property.REQUIRED, true).with(Property.SECURE, true));
scmConfigurations.add(scmConfig);
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"), ConfigurationPropertyMother.create("KEY2", true, ""));
SCM modifiedSCM = new SCM("scm-id", new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
when(scmExtension.isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
when(localizer.localize("MANDATORY_CONFIGURATION_FIELD")).thenReturn("MANDATORY_CONFIGURATION_FIELD");
pluggableScmService.validate(modifiedSCM);
final List<ValidationError> validationErrors = validationResult.getErrors();
assertFalse(validationErrors.isEmpty());
final ValidationError validationErrorForKey1 = getValidationErrorFor(validationErrors, "KEY1");
assertNotNull(validationErrorForKey1);
assertThat(validationErrorForKey1.getMessage(), is("MANDATORY_CONFIGURATION_FIELD"));
final ValidationError validationErrorForKey2 = getValidationErrorFor(validationErrors, "KEY2");
assertNotNull(validationErrorForKey2);
assertThat(validationErrorForKey2.getMessage(), is("MANDATORY_CONFIGURATION_FIELD"));
}
Aggregations