use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PluggableScmServiceTest method shouldSendResolvedValueToPluginDuringValidateSCM.
@Test
public void shouldSendResolvedValueToPluginDuringValidateSCM() {
SCMConfiguration scmConfig = new SCMConfiguration(new SCMProperty("KEY2").with(Property.REQUIRED, false));
scmConfigurations.add(scmConfig);
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1", "{{SECRET:[secret_config_id][lookup_username]}}"));
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);
doAnswer(invocation -> {
SCM config = invocation.getArgument(0);
config.getSecretParams().get(0).setValue("resolved-value");
return config;
}).when(secretParamResolver).resolve(modifiedSCM);
pluggableScmService.validate(modifiedSCM);
verify(secretParamResolver).resolve(modifiedSCM);
assertFalse(modifiedSCM.getConfiguration().getProperty("KEY1").errors().isEmpty());
assertThat(modifiedSCM.getConfiguration().getProperty("KEY1").errors().firstError(), is("error message"));
ArgumentCaptor<SCMPropertyConfiguration> captor = ArgumentCaptor.forClass(SCMPropertyConfiguration.class);
verify(scmExtension).isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), captor.capture());
assertThat(captor.getValue().list().get(0).getValue(), is("resolved-value"));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PluggableScmServiceTest method isValidShouldMapPluginValidationErrorsToPluggableSCMForMissingConfigurations.
@Test
public void isValidShouldMapPluginValidationErrorsToPluggableSCMForMissingConfigurations() {
PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("url", "URL is a required field"));
SCM scmConfig = mock(SCM.class);
when(scmConfig.doesPluginExist()).thenReturn(true);
when(scmConfig.getPluginConfiguration()).thenReturn(pluginConfiguration);
when(scmConfig.getConfiguration()).thenReturn(new Configuration());
when(scmExtension.isSCMConfigurationValid(any(String.class), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
assertFalse(pluggableScmService.isValid(scmConfig));
verify(scmConfig).addError("url", "URL is a required field");
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldInvokePluginValidationsBeforeSavingPackageRepository.
@Test
void shouldInvokePluginValidationsBeforeSavingPackageRepository() {
String pluginId = "yum";
PackageRepository packageRepository = new PackageRepository();
RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, new PackageConfigurations());
packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, "1.0"));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("url", false, "junk-url"));
ArgumentCaptor<RepositoryConfiguration> packageConfigurationsArgumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
ValidationResult expectedValidationResult = new ValidationResult();
expectedValidationResult.addError(new ValidationError("url", "url format incorrect"));
when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(getPluginDescriptor("yum"));
when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), packageConfigurationsArgumentCaptor.capture())).thenReturn(expectedValidationResult);
service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, secretParamResolver);
service.performPluginValidationsFor(packageRepository);
assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value")).isEqualTo(Arrays.asList("url format incorrect"));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PluggableTaskServiceTest method isValidShouldMapPluginValidationErrorsToPluggableTaskConfigrations.
@Test
public void isValidShouldMapPluginValidationErrorsToPluggableTaskConfigrations() {
PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
Configuration configuration = new Configuration();
configuration.add(ConfigurationPropertyMother.create("source", false, "src_dir"));
configuration.add(ConfigurationPropertyMother.create("destination", false, "dest_dir"));
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("source", "source directory format is invalid"));
validationResult.addError(new ValidationError("destination", "destination directory format is invalid"));
PluggableTask pluggableTask = mock(PluggableTask.class);
when(pluggableTask.isValid()).thenReturn(true);
when(pluggableTask.toTaskConfig()).thenReturn(new TaskConfig());
when(pluggableTask.getPluginConfiguration()).thenReturn(pluginConfiguration);
when(pluggableTask.getConfiguration()).thenReturn(configuration);
when(taskExtension.validate(any(String.class), any(TaskConfig.class))).thenReturn(validationResult);
assertFalse(pluggableTaskService.isValid(pluggableTask));
assertThat(configuration.getProperty("source").errors().get("source").get(0), is("source directory format is invalid"));
assertThat(configuration.getProperty("destination").errors().get("destination").get(0), is("destination directory format is invalid"));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class RoleConfigurationValidatorTest method shouldMapValidationErrorsToRoleConfiguration.
@Test
public void shouldMapValidationErrorsToRoleConfiguration() throws Exception {
ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("username"), new ConfigurationValue("view"));
PluginRoleConfig roleConfig = new PluginRoleConfig("admin", "auth_id", property);
ValidationResult result = new ValidationResult();
result.addError(new ValidationError("username", "username format is incorrect"));
when(extension.validateRoleConfiguration("pluginId", Collections.singletonMap("username", "view"))).thenReturn(result);
validator.validate(roleConfig, "pluginId");
assertTrue(roleConfig.hasErrors());
assertThat(roleConfig.getProperty("username").errors().get("username").get(0), is("username format is incorrect"));
}
Aggregations