use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class JSONResultMessageHandlerTest method shouldBuildValidationResultFromResponseBody.
@Test
public void shouldBuildValidationResultFromResponseBody() throws Exception {
String responseBody = "[{\"key\":\"key-one\",\"message\":\"incorrect value\"},{\"message\":\"general error\"}]";
ValidationResult validationResult = messageHandler.toValidationResult(responseBody);
assertValidationError(validationResult.getErrors().get(0), "key-one", "incorrect value");
assertValidationError(validationResult.getErrors().get(1), "", "general error");
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluginSettingsJsonMessageHandlerTestBase method shouldBuildValidationResultFromCheckSCMConfigurationValidResponse.
@Test
public void shouldBuildValidationResultFromCheckSCMConfigurationValidResponse() throws Exception {
String responseBody = "[{\"key\":\"key-one\",\"message\":\"incorrect value\"},{\"message\":\"general error\"}]";
ValidationResult validationResult = messageHandler.responseMessageForPluginSettingsValidation(responseBody);
assertValidationError(validationResult.getErrors().get(0), "key-one", "incorrect value");
assertValidationError(validationResult.getErrors().get(1), "", "general error");
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluginServiceTest method shouldSavePluginSettingsToDbIfPluginSettingsAreValidated.
@Test
public void shouldSavePluginSettingsToDbIfPluginSettingsAreValidated() {
Map<String, String> parameterMap = new HashMap<>();
parameterMap.put("p2-k1", "v1");
PluginSettings pluginSettings = new PluginSettings("plugin-id-2");
pluginSettings.populateSettingsMap(parameterMap);
Username currentUser = new Username("admin");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(securityService.isUserAdmin(currentUser)).thenReturn(true);
when(configRepoExtension.canHandlePlugin("plugin-id-2")).thenReturn(true);
when(configRepoExtension.validatePluginSettings(eq("plugin-id-2"), any(PluginSettingsConfiguration.class))).thenReturn(new ValidationResult());
pluginService.savePluginSettings(currentUser, result, pluginSettings);
Plugin plugin = new Plugin("plugin-id-2", toJSON(parameterMap));
verify(pluginDao).saveOrUpdate(plugin);
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluginServiceTest method shouldNotUpdatePluginSettingsWithErrorsIfNotExists.
@Test
public void shouldNotUpdatePluginSettingsWithErrorsIfNotExists() {
PluginSettingsMetadataStore.getInstance().addMetadataFor("plugin-id-4", PluginConstants.NOTIFICATION_EXTENSION, null, null);
when(notificationExtension.canHandlePlugin("plugin-id-4")).thenReturn(true);
when(notificationExtension.validatePluginSettings(eq("plugin-id-4"), any(PluginSettingsConfiguration.class))).thenReturn(new ValidationResult());
Map<String, String> parameterMap = new HashMap<>();
parameterMap.put("p4-k1", "v1");
parameterMap.put("p4-k2", "v2");
PluginSettings pluginSettings = new PluginSettings("plugin-id-4");
pluginSettings.populateSettingsMap(parameterMap);
pluginService.validatePluginSettingsFor(pluginSettings);
assertThat(pluginSettings.hasErrors(), is(false));
}
use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.
the class PluginServiceTest method shouldIgnoreErrorsWhileNotifyingPluginSettingChange.
@Test
public void shouldIgnoreErrorsWhileNotifyingPluginSettingChange() throws Exception {
Map<String, String> parameterMap = new HashMap<>();
parameterMap.put("p2-k1", "v1");
PluginSettings pluginSettings = new PluginSettings("plugin-id-2");
pluginSettings.populateSettingsMap(parameterMap);
Username currentUser = new Username("admin");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(securityService.isUserAdmin(currentUser)).thenReturn(true);
when(configRepoExtension.canHandlePlugin("plugin-id-2")).thenReturn(true);
when(configRepoExtension.validatePluginSettings(eq("plugin-id-2"), any(PluginSettingsConfiguration.class))).thenReturn(new ValidationResult());
doThrow(new RuntimeException()).when(configRepoExtension).notifyPluginSettingsChange("plugin-id-2", pluginSettings.getSettingsAsKeyValuePair());
pluginService.savePluginSettings(currentUser, result, pluginSettings);
Plugin plugin = new Plugin("plugin-id-2", toJSON(parameterMap));
verify(pluginDao).saveOrUpdate(plugin);
verify(configRepoExtension).notifyPluginSettingsChange("plugin-id-2", pluginSettings.getSettingsAsKeyValuePair());
assertTrue(result.isSuccessful());
}
Aggregations