use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PluggableTaskBuilderTest method shouldReturnConfigValueInExecConfig.
@Test
public void shouldReturnConfigValueInExecConfig() throws Exception {
TaskConfig defaultTaskConfig = new TaskConfig();
String propertyName = "URL";
String defaultValue = "ABC.TXT";
HashMap<String, String> configValue = new HashMap<>();
configValue.put("value", "XYZ.TXT");
Map<String, Map<String, String>> configMap = new HashMap<>();
configMap.put(propertyName, configValue);
PluggableTask task = mock(PluggableTask.class);
when(task.getPluginConfiguration()).thenReturn(new PluginConfiguration());
when(task.configAsMap()).thenReturn(configMap);
PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, task, TEST_PLUGIN_ID, "test-directory");
defaultTaskConfig.addProperty(propertyName).withDefault(defaultValue);
TaskConfig config = taskBuilder.buildTaskConfig(defaultTaskConfig);
assertThat(config.getValue(propertyName), is(configValue.get("value")));
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PluggableTaskBuilderTest method shouldReturnDefaultValueInExecConfigWhenConfigValueIsEmptyString.
@Test
public void shouldReturnDefaultValueInExecConfigWhenConfigValueIsEmptyString() throws Exception {
TaskConfig defaultTaskConfig = new TaskConfig();
String propertyName = "URL";
String defaultValue = "ABC.TXT";
Map<String, Map<String, String>> configMap = new HashMap<>();
HashMap<String, String> configValue = new HashMap<>();
configValue.put("value", "");
configMap.put(propertyName, configValue);
PluggableTask task = mock(PluggableTask.class);
when(task.getPluginConfiguration()).thenReturn(new PluginConfiguration());
when(task.configAsMap()).thenReturn(configMap);
PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, task, TEST_PLUGIN_ID, "test-directory");
defaultTaskConfig.addProperty(propertyName).withDefault(defaultValue);
TaskConfig config = taskBuilder.buildTaskConfig(defaultTaskConfig);
assertThat(config.getValue(propertyName), is(defaultValue));
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PipelineConfigServiceTest method createPipelineConfigShouldValidateAllPluggableTasks.
@Test
public void createPipelineConfigShouldValidateAllPluggableTasks() {
PluggableTask xUnit = mock(PluggableTask.class);
PluggableTask docker = mock(PluggableTask.class);
JobConfig job1 = JobConfigMother.job();
JobConfig job2 = JobConfigMother.job();
job1.addTask(xUnit);
job2.addTask(docker);
PipelineConfig pipeline = PipelineConfigMother.pipelineConfig("P1", new StageConfig(new CaseInsensitiveString("S1"), new JobConfigs(job1)), new StageConfig(new CaseInsensitiveString("S2"), new JobConfigs(job2)));
pipelineConfigService.createPipelineConfig(null, pipeline, null, null);
verify(pluggableTaskService).isValid(xUnit);
verify(pluggableTaskService).isValid(docker);
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class ConfigConverterTest method shouldMigratePluggableTask.
@Test
public void shouldMigratePluggableTask() {
ArrayList<CRConfigurationProperty> configs = new ArrayList<>();
configs.add(new CRConfigurationProperty("k", "m", null));
CRPluggableTask pluggableTask = new CRPluggableTask(CRRunIf.any, null, new CRPluginConfiguration("myplugin", "1"), configs);
PluggableTask result = (PluggableTask) configConverter.toAbstractTask(pluggableTask);
assertThat(result.getPluginConfiguration().getId(), is("myplugin"));
assertThat(result.getPluginConfiguration().getVersion(), is("1"));
assertThat(result.getConfiguration().getProperty("k").getValue(), is("m"));
assertThat(result.getConditions().first(), is(RunIfConfig.ANY));
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PluggableTaskBuilderTest method shouldReturnDefaultValueInExecConfigWhenConfigValueIsNull.
@Test
public void shouldReturnDefaultValueInExecConfigWhenConfigValueIsNull() throws Exception {
TaskConfig defaultTaskConfig = new TaskConfig();
String propertyName = "URL";
String defaultValue = "ABC.TXT";
Map<String, Map<String, String>> configMap = new HashMap<>();
configMap.put(propertyName, null);
PluggableTask task = mock(PluggableTask.class);
when(task.getPluginConfiguration()).thenReturn(new PluginConfiguration());
when(task.configAsMap()).thenReturn(configMap);
PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, task, TEST_PLUGIN_ID, "test-directory");
defaultTaskConfig.addProperty(propertyName).withDefault(defaultValue);
TaskConfig config = taskBuilder.buildTaskConfig(defaultTaskConfig);
assertThat(config.getValue(propertyName), is(defaultValue));
}
Aggregations