Search in sources :

Example 6 with PluggableTask

use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.

the class PipelineConfigServiceTest method updatePipelineConfigShouldValidateAllPluggableTasks.

@Test
public void updatePipelineConfigShouldValidateAllPluggableTasks() {
    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.updatePipelineConfig(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 7 with PluggableTask

use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.

the class ConfigConverter method toPluggableTask.

public PluggableTask toPluggableTask(CRPluggableTask pluggableTask) {
    PluginConfiguration pluginConfiguration = toPluginConfiguration(pluggableTask.getPluginConfiguration());
    Configuration configuration = toConfiguration(pluggableTask.getConfiguration());
    PluggableTask task = new PluggableTask(pluginConfiguration, configuration);
    setCommonTaskMembers(task, pluggableTask);
    return task;
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask)

Example 8 with PluggableTask

use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.

the class BuilderFactoryTest method shouldCreateABuilderForEachTypeOfTaskWhichExists.

@Test
public void shouldCreateABuilderForEachTypeOfTaskWhichExists() throws Exception {
    Pipeline pipeline = PipelineMother.pipeline("pipeline1", StageMother.custom("stage1"));
    AntTask antTask = new AntTask();
    NantTask nantTask = new NantTask();
    RakeTask rakeTask = new RakeTask();
    PluggableTask pluggableTask = new PluggableTask();
    Builder expectedBuilderForAntTask = myFakeBuilder();
    Builder expectedBuilderForNantTask = myFakeBuilder();
    Builder expectedBuilderForRakeTask = myFakeBuilder();
    Builder expectedBuilderForPluggableTask = myFakeBuilder();
    when(antTaskBuilder.createBuilder(builderFactory, antTask, pipeline, pipelineResolver)).thenReturn(expectedBuilderForAntTask);
    when(nantTaskBuilder.createBuilder(builderFactory, nantTask, pipeline, pipelineResolver)).thenReturn(expectedBuilderForNantTask);
    when(rakeTaskBuilder.createBuilder(builderFactory, rakeTask, pipeline, pipelineResolver)).thenReturn(expectedBuilderForRakeTask);
    when(pluggableTaskBuilderCreator.createBuilder(builderFactory, pluggableTask, pipeline, pipelineResolver)).thenReturn(expectedBuilderForPluggableTask);
    List<Builder> builders = builderFactory.buildersForTasks(pipeline, listOf(antTask, nantTask, rakeTask, pluggableTask), pipelineResolver);
    assertThat(builders.size(), is(4));
    assertThat(builders.get(0), is(expectedBuilderForAntTask));
    assertThat(builders.get(1), is(expectedBuilderForNantTask));
    assertThat(builders.get(2), is(expectedBuilderForRakeTask));
    assertThat(builders.get(3), is(expectedBuilderForPluggableTask));
}
Also used : RakeTask(com.thoughtworks.go.config.RakeTask) Builder(com.thoughtworks.go.domain.builder.Builder) AntTask(com.thoughtworks.go.config.AntTask) NantTask(com.thoughtworks.go.config.NantTask) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 9 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 10 with PluggableTask

use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.

the class PluggableTaskBuilderTest method shouldPublishErrorMessageIfPluginThrowsAnException.

@Test
public void shouldPublishErrorMessageIfPluginThrowsAnException() throws CruiseControlException {
    PluggableTask task = mock(PluggableTask.class);
    when(task.getPluginConfiguration()).thenReturn(new PluginConfiguration());
    PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, pluggableTask, TEST_PLUGIN_ID, "test-directory") {

        @Override
        protected ExecutionResult executeTask(Task task, BuildLogElement buildLogElement, DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext) {
            throw new RuntimeException("err");
        }
    };
    when(pluginManager.doOn(eq(Task.class), eq(TEST_PLUGIN_ID), any(ActionWithReturn.class))).thenAnswer(new Answer<ExecutionResult>() {

        @Override
        public ExecutionResult answer(InvocationOnMock invocationOnMock) throws Throwable {
            ActionWithReturn<Task, ExecutionResult> actionWithReturn = (ActionWithReturn<Task, ExecutionResult>) invocationOnMock.getArguments()[2];
            return actionWithReturn.execute(mock(Task.class), pluginDescriptor);
        }
    });
    try {
        taskBuilder.build(buildLogElement, goPublisher, variableContext, taskExtension);
        fail("expected exception to be thrown");
    } catch (Exception e) {
        ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
        verify(goPublisher).consumeLine(captor.capture());
        String error = "Error: err";
        assertThat(captor.getValue(), is(error));
        assertThat(e.getMessage(), is(new RuntimeException("err").toString()));
    }
}
Also used : PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) ArgumentCaptor(org.mockito.ArgumentCaptor) BuildLogElement(com.thoughtworks.go.domain.BuildLogElement) ExecutionResult(com.thoughtworks.go.plugin.api.response.execution.ExecutionResult) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) CruiseControlException(com.thoughtworks.go.util.command.CruiseControlException) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) ActionWithReturn(com.thoughtworks.go.plugin.infra.ActionWithReturn) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) 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 BuildLogElement (com.thoughtworks.go.domain.BuildLogElement)3 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)3 ExecutionResult (com.thoughtworks.go.plugin.api.response.execution.ExecutionResult)3 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)3 DefaultGoPublisher (com.thoughtworks.go.work.DefaultGoPublisher)3 Gson (com.google.gson.Gson)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