use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class ElasticAgentExtensionV4Test method shouldValidateProfile.
@Test
public void shouldValidateProfile() {
String responseBody = "[{\"message\":\"Url must not be blank.\",\"key\":\"Url\"},{\"message\":\"SearchBase must not be blank.\",\"key\":\"SearchBase\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
final ValidationResult result = extensionV4.validateElasticProfile(PLUGIN_ID, Collections.emptyMap());
assertThat(result.isSuccessful(), is(false));
assertThat(result.getErrors(), containsInAnyOrder(new ValidationError("Url", "Url must not be blank."), new ValidationError("SearchBase", "SearchBase must not be blank.")));
assertExtensionRequest("4.0", REQUEST_VALIDATE_PROFILE, "{}");
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class ExternalArtifactsServiceTest method shouldMapPluginValidationErrorsToConfigrationProperties.
@Test
public void shouldMapPluginValidationErrorsToConfigrationProperties() {
Configuration configuration = new Configuration();
configuration.add(ConfigurationPropertyMother.create("Image", false, "alpine"));
configuration.add(ConfigurationPropertyMother.create("Tag", false, "fml"));
pluggableArtifactConfig.setConfiguration(configuration);
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("Image", "invalid"));
validationResult.addError(new ValidationError("Tag", "invalid"));
ArtifactStore artifactStore = mock(ArtifactStore.class);
when(artifactStore.getPluginId()).thenReturn(pluginId);
when(artifactExtension.validatePluggableArtifactConfig(any(String.class), any())).thenReturn(validationResult);
externalArtifactsService.validateExternalArtifactConfig(pluggableArtifactConfig, artifactStore, true);
assertThat(configuration.getProperty("Image").errors().get("Image").get(0), is("invalid"));
assertThat(configuration.getProperty("Tag").errors().get("Tag").get(0), is("invalid"));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PackageDefinitionService method performPluginValidationsFor.
public void performPluginValidationsFor(final PackageDefinition packageDefinition) {
String pluginId = packageDefinition.getRepository().getPluginConfiguration().getId();
ValidationResult validationResult = packageRepositoryExtension.isPackageConfigurationValid(pluginId, buildPackageConfigurations(packageDefinition), buildRepositoryConfigurations(packageDefinition.getRepository()));
for (ValidationError error : validationResult.getErrors()) {
packageDefinition.addConfigurationErrorFor(error.getKey(), error.getMessage());
}
for (ConfigurationProperty configurationProperty : packageDefinition.getConfiguration()) {
String key = configurationProperty.getConfigurationKey().getName();
if (PackageMetadataStore.getInstance().hasOption(packageDefinition.getRepository().getPluginConfiguration().getId(), key, PackageConfiguration.REQUIRED)) {
if (configurationProperty.getValue().isEmpty() && configurationProperty.doesNotHaveErrorsAgainstConfigurationValue()) {
configurationProperty.addErrorAgainstConfigurationValue("Field: '" + configurationProperty.getConfigurationKey().getName() + "' is required");
}
}
}
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PackageRepositoryService method performPluginValidationsFor.
void performPluginValidationsFor(final PackageRepository packageRepository) {
if (!validatePluginId(packageRepository)) {
return;
}
for (ConfigurationProperty configurationProperty : packageRepository.getConfiguration()) {
String key = configurationProperty.getConfigurationKey().getName();
String pluginId = packageRepository.getPluginConfiguration().getId();
if (repositoryMetadataStore.hasOption(pluginId, key, PackageConfiguration.REQUIRED)) {
if (configurationProperty.getValue().isEmpty()) {
configurationProperty.addErrorAgainstConfigurationValue("This field is required");
}
}
}
ValidationResult validationResult = packageRepositoryExtension.isRepositoryConfigurationValid(packageRepository.getPluginConfiguration().getId(), populateConfiguration(packageRepository.getConfiguration()));
for (ValidationError error : validationResult.getErrors()) {
packageRepository.addConfigurationErrorFor(error.getKey(), error.getMessage());
}
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PluggableScmService method validate.
public void validate(final SCM scmConfig) {
secretParamResolver.resolve(scmConfig);
final String pluginId = scmConfig.getPluginConfiguration().getId();
final SCMPropertyConfiguration configuration = getScmPropertyConfiguration(scmConfig);
ValidationResult validationResult = scmExtension.isSCMConfigurationValid(pluginId, configuration);
if (SCMMetadataStore.getInstance().hasPreferenceFor(pluginId)) {
SCMConfigurations configurationMetadata = SCMMetadataStore.getInstance().getConfigurationMetadata(pluginId);
for (SCMConfiguration scmConfiguration : configurationMetadata.list()) {
String key = scmConfiguration.getKey();
boolean isRequired = SCMMetadataStore.getInstance().hasOption(pluginId, key, Property.REQUIRED);
ConfigurationProperty property = scmConfig.getConfiguration().getProperty(key);
String configValue = property == null ? null : property.getValue();
if (isRequired && StringUtils.isBlank(configValue)) {
validationResult.addError(new ValidationError(key, "This field is required"));
}
}
}
for (ValidationError validationError : validationResult.getErrors()) {
ConfigurationProperty property = scmConfig.getConfiguration().getProperty(validationError.getKey());
if (property != null) {
property.addError(validationError.getKey(), validationError.getMessage());
}
}
}
Aggregations