Search in sources :

Example 11 with TaskConfig

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

the class PluggableTaskTest method shouldBeAbleToGetTaskConfigRepresentation.

@Test
public void shouldBeAbleToGetTaskConfigRepresentation() {
    List<ConfigurationProperty> configurationProperties = Arrays.asList(ConfigurationPropertyMother.create("source", false, "src_dir"), ConfigurationPropertyMother.create("destination", false, "des_dir"));
    Configuration configuration = new Configuration();
    configuration.addAll(configurationProperties);
    PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
    PluggableTask pluggableTask = new PluggableTask(pluginConfiguration, configuration);
    TaskConfig taskConfig = pluggableTask.toTaskConfig();
    assertThat(taskConfig.size(), is(2));
    assertThat(taskConfig.get("source").getValue(), is("src_dir"));
    assertThat(taskConfig.get("destination").getValue(), is("des_dir"));
}
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) Test(org.junit.Test)

Example 12 with TaskConfig

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

the class PluggableTaskTest method postConstructShouldDoNothingForAInvalidConfigurationProperty.

@Test
public void postConstructShouldDoNothingForAInvalidConfigurationProperty() 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();
    when(taskPreference.getConfig()).thenReturn(taskConfig);
    PluggableTask task = new PluggableTask(new PluginConfiguration("abc.def", "1"), configuration);
    assertFalse(configurationProperty.isSecure());
    task.applyPluginMetadata();
    assertFalse(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 13 with TaskConfig

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

the class PluggableTaskTest method shouldNotOverwriteValuesIfTheyAreNotAvailableInConfigAttributesMap.

@Test
public void shouldNotOverwriteValuesIfTheyAreNotAvailableInConfigAttributesMap() 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");
    TaskConfig taskConfig = new TaskConfig();
    TaskProperty property1 = new TaskProperty("KEY1", "value1");
    TaskProperty property2 = new TaskProperty("Key2", null);
    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(nullValue()));
}
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 14 with TaskConfig

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

the class PluggableTaskTest method shouldAddConfigurationProperties.

@Test
public void shouldAddConfigurationProperties() {
    List<ConfigurationProperty> configurationProperties = Arrays.asList(ConfigurationPropertyMother.create("key", "value", "encValue"), new ConfigurationProperty());
    PluginConfiguration pluginConfiguration = new PluginConfiguration("github.pr", "1.1");
    TaskPreference taskPreference = mock(TaskPreference.class);
    TaskConfig taskConfig = new TaskConfig();
    Configuration configuration = new Configuration();
    Property property = new Property("key");
    property.with(Property.SECURE, false);
    PluggableTaskConfigStore.store().setPreferenceFor(pluginConfiguration.getId(), taskPreference);
    TaskConfigProperty taskConfigProperty = taskConfig.addProperty("key");
    when(taskPreference.getConfig()).thenReturn(taskConfig);
    PluggableTask pluggableTask = new PluggableTask(pluginConfiguration, configuration);
    pluggableTask.addConfigurations(configurationProperties);
    assertThat(configuration.size(), is(2));
}
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) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) TaskProperty(com.thoughtworks.go.domain.TaskProperty) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 15 with TaskConfig

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

the class PluggableTaskTest method shouldHandleSecureConfigurations.

@Test
public void shouldHandleSecureConfigurations() throws Exception {
    TaskPreference taskPreference = mock(TaskPreference.class);
    Configuration configuration = new Configuration();
    PluggableTaskConfigStore.store().setPreferenceFor("abc.def", taskPreference);
    PluggableTask task = new PluggableTask(new PluginConfiguration("abc.def", "1"), configuration);
    Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1");
    TaskConfig taskConfig = new TaskConfig();
    taskConfig.addProperty("KEY1").with(Property.SECURE, true);
    when(taskPreference.getConfig()).thenReturn(taskConfig);
    task.setTaskConfigAttributes(attributeMap);
    assertThat(task.getConfiguration().size(), is(1));
    assertTrue(task.getConfiguration().first().isSecure());
    assertThat(task.getConfiguration().first().getValue(), is("value1"));
}
Also used : 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)

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