use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluginServiceTest method shouldUpdatePluginSettingsWithErrorsIfExists.
@Test
public void shouldUpdatePluginSettingsWithErrorsIfExists() {
PluginSettingsMetadataStore.getInstance().addMetadataFor("plugin-id-4", PluginConstants.NOTIFICATION_EXTENSION, null, null);
when(notificationExtension.canHandlePlugin("plugin-id-4")).thenReturn(true);
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("p4-k1", "m1"));
validationResult.addError(new ValidationError("p4-k3", "m3"));
when(notificationExtension.validatePluginSettings(eq("plugin-id-4"), any(PluginSettingsConfiguration.class))).thenReturn(validationResult);
Map<String, String> parameterMap = new HashMap<>();
parameterMap.put("p4-k1", "v1");
parameterMap.put("p4-k2", "v2");
parameterMap.put("p4-k3", "v3");
PluginSettings pluginSettings = new PluginSettings("plugin-id-4");
pluginSettings.populateSettingsMap(parameterMap);
pluginService.validatePluginSettingsFor(pluginSettings);
assertThat(pluginSettings.hasErrors(), is(true));
assertThat(pluginSettings.getErrorFor("p4-k1"), is(Arrays.asList("m1")));
assertThat(pluginSettings.getErrorFor("p4-k3"), is(Arrays.asList("m3")));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult 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(localizer.localize("MANDATORY_CONFIGURATION_FIELD_WITH_NAME", configurationProperty.getConfigurationKey().getName()));
}
}
}
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult 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(localizer.localize("MANDATORY_CONFIGURATION_FIELD"));
}
}
}
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.ValidationResult in project gocd by gocd.
the class PluggableScmService method validate.
public void validate(final SCM 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, localizer.localize("MANDATORY_CONFIGURATION_FIELD")));
}
}
}
for (ValidationError validationError : validationResult.getErrors()) {
ConfigurationProperty property = scmConfig.getConfiguration().getProperty(validationError.getKey());
if (property != null) {
property.addError(validationError.getKey(), validationError.getMessage());
}
}
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluggableScmService method isValid.
public boolean isValid(final SCM scmConfig) {
if (!scmConfig.doesPluginExist()) {
throw new RuntimeException(String.format("Plugin with id '%s' is not found.", scmConfig.getPluginConfiguration().getId()));
}
ValidationResult validationResult = scmExtension.isSCMConfigurationValid(scmConfig.getPluginConfiguration().getId(), getScmPropertyConfiguration(scmConfig));
addErrorsToConfiguration(validationResult, scmConfig);
return validationResult.isSuccessful();
}
Aggregations