Search in sources :

Example 16 with PluggableTask

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")));
}
Also used : HashMap(java.util.HashMap) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 17 with PluggableTask

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));
}
Also used : HashMap(java.util.HashMap) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 18 with PluggableTask

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);
}
Also used : PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 19 with PluggableTask

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));
}
Also used : PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 20 with PluggableTask

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));
}
Also used : HashMap(java.util.HashMap) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Aggregations

PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)38 Test (org.junit.Test)33 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)28 Configuration (com.thoughtworks.go.domain.config.Configuration)18 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)8 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)7 Map (java.util.Map)6 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)5 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)4 HashMap (java.util.HashMap)4 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)3 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)3 DefaultGoPublisher (com.thoughtworks.go.work.DefaultGoPublisher)3 Gson (com.google.gson.Gson)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)2 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)2 Property (com.thoughtworks.go.plugin.api.config.Property)2 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)2 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)2 MissingPluggableTaskViewModel (com.thoughtworks.go.presentation.MissingPluggableTaskViewModel)2