Search in sources :

Example 11 with TaskConfigProperty

use of com.thoughtworks.go.plugin.api.task.TaskConfigProperty in project gocd by gocd.

the class JsonBasedPluggableTaskTest method shouldValidateTaskConfig.

@Test
public void shouldValidateTaskConfig() {
    String jsonResponse = "{\"errors\":{\"key1\":\"err1\",\"key2\":\"err3\"}}";
    String config = "{\"URL\":{\"secure\":false,\"value\":\"http://foo\",\"required\":true}}";
    when(goPluginApiResponse.responseBody()).thenReturn(jsonResponse);
    TaskConfig configuration = new TaskConfig();
    final TaskConfigProperty property = new TaskConfigProperty("URL", "http://foo");
    property.with(Property.SECURE, false);
    property.with(Property.REQUIRED, true);
    configuration.add(property);
    ValidationResult result = task.validate(configuration);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.getErrors().get(0).getKey(), is("key1"));
    assertThat(result.getErrors().get(0).getMessage(), is("err1"));
    assertThat(result.getErrors().get(1).getKey(), is("key2"));
    assertThat(result.getErrors().get(1).getMessage(), is("err3"));
    ArgumentCaptor<GoPluginApiRequest> argument = ArgumentCaptor.forClass(GoPluginApiRequest.class);
    verify(pluginManager).submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), argument.capture());
    assertThat(argument.getValue().requestBody(), is(config));
    MatcherAssert.assertThat(argument.getValue().extension(), Matchers.is(PLUGGABLE_TASK_EXTENSION));
    MatcherAssert.assertThat(argument.getValue().extensionVersion(), Matchers.is(JsonBasedTaskExtensionHandler_V1.VERSION));
    MatcherAssert.assertThat(argument.getValue().requestName(), Matchers.is(TaskExtension.VALIDATION_REQUEST));
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 12 with TaskConfigProperty

use of com.thoughtworks.go.plugin.api.task.TaskConfigProperty in project gocd by gocd.

the class PluggableTaskBuilder method getExecProperty.

private Property getExecProperty(TaskConfig defaultConfig, Property property) {
    String key = property.getKey();
    String configValue = pluginConfig.get(key) == null ? null : pluginConfig.get(key).get(PluggableTask.VALUE_KEY);
    return StringUtils.isBlank(configValue) ? defaultConfig.get(key) : new TaskConfigProperty(key, configValue);
}
Also used : TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty)

Aggregations

TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)12 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)6 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)5 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)4 Test (org.junit.Test)4 JsonBasedPluggableTask (com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask)3 Property (com.thoughtworks.go.plugin.api.config.Property)3 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)2 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)2 PluggableTaskConfigStore (com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore)2 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)2 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)2 PluggableInstanceSettings (com.thoughtworks.go.server.ui.plugins.PluggableInstanceSettings)2 PluggableTaskPluginInfo (com.thoughtworks.go.server.ui.plugins.PluggableTaskPluginInfo)2 PluginView (com.thoughtworks.go.server.ui.plugins.PluginView)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 GsonBuilder (com.google.gson.GsonBuilder)1 Configuration (com.thoughtworks.go.domain.config.Configuration)1 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)1