use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class ElasticAgentExtensionV3Test method shouldValidateProfile.
@Test
public void shouldValidateProfile() throws JSONException {
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 = extensionV3.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("3.0", REQUEST_VALIDATE_PROFILE, "{}");
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class ArtifactExtensionTest method shouldValidateArtifactStoreConfig.
@Test
public void shouldValidateArtifactStoreConfig() {
String responseBody = "[{\"message\":\"ACCESS_KEY must not be blank.\",\"key\":\"ACCESS_KEY\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
ValidationResult validationResult = artifactExtension.validateArtifactStoreConfig(PLUGIN_ID, Collections.singletonMap("ACCESS_KEY", ""));
final GoPluginApiRequest request = requestArgumentCaptor.getValue();
assertThat(request.extension(), is(ARTIFACT_EXTENSION));
assertThat(request.requestName(), is(REQUEST_STORE_CONFIG_VALIDATE));
assertThat(request.requestBody(), is("{\"ACCESS_KEY\":\"\"}"));
assertThat(validationResult.isSuccessful(), is(false));
assertThat(validationResult.getErrors(), containsInAnyOrder(new ValidationError("ACCESS_KEY", "ACCESS_KEY must not be blank.")));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class ArtifactExtensionTest method shouldValidateFetchArtifactConfig.
@Test
public void shouldValidateFetchArtifactConfig() {
String responseBody = "[{\"message\":\"Filename must not be blank.\",\"key\":\"Filename\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
ValidationResult validationResult = artifactExtension.validateFetchArtifactConfig(PLUGIN_ID, Collections.singletonMap("Filename", ""));
final GoPluginApiRequest request = requestArgumentCaptor.getValue();
assertThat(request.extension(), is(ARTIFACT_EXTENSION));
assertThat(request.requestName(), is(REQUEST_FETCH_ARTIFACT_VALIDATE));
assertThat(request.requestBody(), is("{\"Filename\":\"\"}"));
assertThat(validationResult.isSuccessful(), is(false));
assertThat(validationResult.getErrors(), containsInAnyOrder(new ValidationError("Filename", "Filename must not be blank.")));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PluginServiceTest method shouldNotSavePluginSettingsIfPluginReturnsValidationErrors.
@Test
public void shouldNotSavePluginSettingsIfPluginReturnsValidationErrors() {
PluginSettingsMetadataStore.getInstance().addMetadataFor("some-plugin", PluginConstants.CONFIG_REPO_EXTENSION, null, null);
PluginSettings pluginSettings = new PluginSettings("some-plugin");
Username currentUser = new Username("admin");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(securityService.isUserAdmin(currentUser)).thenReturn(true);
when(configRepoExtension.canHandlePlugin("some-plugin")).thenReturn(true);
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("foo", "foo is a required field"));
when(configRepoExtension.validatePluginSettings(eq("some-plugin"), any(PluginSettingsConfiguration.class))).thenReturn(validationResult);
pluginService.savePluginSettings(currentUser, result, pluginSettings);
assertThat(result.httpCode(), is(422));
assertThat(pluginSettings.errors().size(), is(1));
assertThat(pluginSettings.getErrorFor("foo"), is(Arrays.asList("foo is a required field")));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationError in project gocd by gocd.
the class PluggableTaskServiceTest method shouldValidateMandatoryFields.
@Test
public void shouldValidateMandatoryFields() {
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
PluggableTask modifiedTask = new PluggableTask(new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
when(taskExtension.validate(eq(modifiedTask.getPluginConfiguration().getId()), any(TaskConfig.class))).thenReturn(validationResult);
when(localizer.localize("MANDATORY_CONFIGURATION_FIELD")).thenReturn("MANDATORY_CONFIGURATION_FIELD");
pluggableTaskService.validate(modifiedTask);
final List<ValidationError> validationErrors = validationResult.getErrors();
assertFalse(validationErrors.isEmpty());
final ValidationError validationError = validationErrors.stream().filter(new Predicate<ValidationError>() {
@Override
public boolean test(ValidationError item) {
return ((ValidationError) item).getKey().equals("KEY1");
}
}).findFirst().orElse(null);
assertNotNull(validationError);
assertThat(validationError.getMessage(), is("MANDATORY_CONFIGURATION_FIELD"));
}
Aggregations