Search in sources :

Example 21 with TaskConfig

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

the class PluggableTaskTest method postConstructShouldHandleSecureConfigurationForConfigurationProperties.

@Test
public void postConstructShouldHandleSecureConfigurationForConfigurationProperties() throws Exception {
    TaskPreference taskPreference = mock(TaskPreference.class);
    ConfigurationProperty configurationProperty = ConfigurationPropertyMother.create("KEY1");
    Configuration configuration = new Configuration(configurationProperty);
    PluggableTaskConfigStore.store().setPreferenceFor("abc.def", taskPreference);
    TaskConfig taskConfig = new TaskConfig();
    taskConfig.addProperty("KEY1").with(Property.SECURE, true);
    when(taskPreference.getConfig()).thenReturn(taskConfig);
    PluggableTask task = new PluggableTask(new PluginConfiguration("abc.def", "1"), configuration);
    assertFalse(configurationProperty.isSecure());
    task.applyPluginMetadata();
    assertTrue(configurationProperty.isSecure());
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 22 with TaskConfig

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

the class PluggableTaskTest method shouldPopulateItselfFromConfigAttributesMap.

@Test
public void shouldPopulateItselfFromConfigAttributesMap() throws Exception {
    TaskPreference taskPreference = mock(TaskPreference.class);
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"), ConfigurationPropertyMother.create("Key2"));
    PluggableTaskConfigStore.store().setPreferenceFor("abc.def", taskPreference);
    PluggableTask task = new PluggableTask(new PluginConfiguration("abc.def", "1"), configuration);
    Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1", "Key2", "value2");
    TaskConfig taskConfig = new TaskConfig();
    TaskProperty property1 = new TaskProperty("KEY1", "value1");
    TaskProperty property2 = new TaskProperty("Key2", "value2");
    taskConfig.addProperty(property1.getName());
    taskConfig.addProperty(property2.getName());
    when(taskPreference.getConfig()).thenReturn(taskConfig);
    task.setTaskConfigAttributes(attributeMap);
    assertThat(task.configAsMap().get("KEY1").get(PluggableTask.VALUE_KEY), is("value1"));
    assertThat(task.configAsMap().get("Key2").get(PluggableTask.VALUE_KEY), is("value2"));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskProperty(com.thoughtworks.go.domain.TaskProperty) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 23 with TaskConfig

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

the class PluggableTask method setTaskConfigAttributes.

@Override
protected void setTaskConfigAttributes(Map attributes) {
    TaskConfig taskConfig = PluggableTaskConfigStore.store().preferenceFor(pluginConfiguration.getId()).getConfig();
    for (Property property : taskConfig.list()) {
        String key = property.getKey();
        if (attributes.containsKey(key)) {
            Boolean isSecure = property.getOption(Property.SECURE);
            if (configuration.getProperty(key) == null) {
                configuration.addNewConfiguration(property.getKey(), isSecure);
            }
            configuration.getProperty(key).setConfigurationValue(new ConfigurationValue((String) attributes.get(key)));
            configuration.getProperty(key).handleSecureValueConfiguration(isSecure);
        }
    }
}
Also used : ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) TaskProperty(com.thoughtworks.go.domain.TaskProperty) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty)

Example 24 with TaskConfig

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

the class JsonBasedPluggableTaskTest method shouldGetTheTaskConfig.

@Test
public void shouldGetTheTaskConfig() {
    String jsonResponse = "{" + "\"URL\":{\"default-value\":\"\",\"secure\":false,\"required\":true}," + "\"USER\":{\"default-value\":\"foo\",\"secure\":true,\"required\":true}," + "\"PASSWORD\":{}" + "}";
    when(goPluginApiResponse.responseBody()).thenReturn(jsonResponse);
    TaskConfig config = task.config();
    Property url = config.get("URL");
    assertThat(url.getOption(Property.REQUIRED), is(true));
    assertThat(url.getOption(Property.SECURE), is(false));
    Property user = config.get("USER");
    assertThat(user.getOption(Property.REQUIRED), is(true));
    assertThat(user.getOption(Property.SECURE), is(true));
    Property password = config.get("PASSWORD");
    assertThat(password.getOption(Property.REQUIRED), is(true));
    assertThat(password.getOption(Property.SECURE), is(false));
    ArgumentCaptor<GoPluginApiRequest> argument = ArgumentCaptor.forClass(GoPluginApiRequest.class);
    verify(pluginManager).submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), argument.capture());
    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.CONFIGURATION_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) Property(com.thoughtworks.go.plugin.api.config.Property) Test(org.junit.Test)

Example 25 with TaskConfig

use of com.thoughtworks.go.plugin.api.task.TaskConfig 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.Test)

Aggregations

TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)29 Test (org.junit.Test)22 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)16 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)12 Configuration (com.thoughtworks.go.domain.config.Configuration)11 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)11 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)11 TaskProperty (com.thoughtworks.go.domain.TaskProperty)8 Task (com.thoughtworks.go.plugin.api.task.Task)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)8 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)6 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)5 Property (com.thoughtworks.go.plugin.api.config.Property)4 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)4 JsonBasedPluggableTask (com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask)3 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)3 Action (com.thoughtworks.go.plugin.infra.Action)3 Before (org.junit.Before)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3