Search in sources :

Example 31 with ValidationResult

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");
}
Also used : ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.Test)

Example 32 with ValidationResult

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");
}
Also used : ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.Test)

Example 33 with ValidationResult

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);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginSettings(com.thoughtworks.go.server.domain.PluginSettings) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) Test(org.junit.Test)

Example 34 with ValidationResult

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));
}
Also used : PluginSettings(com.thoughtworks.go.server.domain.PluginSettings) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.Test)

Example 35 with ValidationResult

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());
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginSettings(com.thoughtworks.go.server.domain.PluginSettings) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) Test(org.junit.Test)

Aggregations

ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)85 Test (org.junit.Test)69 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)43 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)17 Configuration (com.thoughtworks.go.domain.config.Configuration)14 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)11 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)11 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)10 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)10 PluginSettings (com.thoughtworks.go.server.domain.PluginSettings)9 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)7 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)7 SCM (com.thoughtworks.go.domain.scm.SCM)7 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)5 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)5 Username (com.thoughtworks.go.server.domain.Username)5 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)4 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)3