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"));
}
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());
}
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()));
}
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));
}
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"));
}
Aggregations