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