use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PluggableTaskBuilderTest method shouldReturnDefaultValueInExecConfigWhenNoConfigValueIsProvided.
@Test
public void shouldReturnDefaultValueInExecConfigWhenNoConfigValueIsProvided() throws Exception {
Map<String, Map<String, String>> configMap = new HashMap<>();
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");
TaskConfig defaultTaskConfig = new TaskConfig();
String propertyName = "URL";
String defaultValue = "ABC.TXT";
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 PluggableTaskBuilderTest method shouldBuildExecutorConfigPlusExecutionContextAndInvokeTheTaskExecutorWithIt.
@Test
public void shouldBuildExecutorConfigPlusExecutionContextAndInvokeTheTaskExecutorWithIt() throws Exception {
Task task = mock(Task.class);
TaskConfig defaultTaskConfig = mock(TaskConfig.class);
when(task.config()).thenReturn(defaultTaskConfig);
final TaskConfig executorTaskConfig = mock(TaskConfig.class);
final TaskExecutionContext taskExecutionContext = mock(TaskExecutionContext.class);
PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, pluggableTask, TEST_PLUGIN_ID, "test-directory") {
@Override
protected TaskConfig buildTaskConfig(TaskConfig config) {
return executorTaskConfig;
}
@Override
protected TaskExecutionContext buildTaskContext(DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext, String consoleLogCharset) {
return taskExecutionContext;
}
};
TaskExecutor taskExecutor = mock(TaskExecutor.class);
when(taskExecutor.execute(executorTaskConfig, taskExecutionContext)).thenReturn(new ExecutionResult());
when(task.executor()).thenReturn(taskExecutor);
taskBuilder.executeTask(task, null, null, "utf-8");
verify(task).config();
verify(task).executor();
verify(taskExecutor).execute(executorTaskConfig, taskExecutionContext);
assertThat(ReflectionUtil.getStaticField(JobConsoleLogger.class, "context"), is(not(nullValue())));
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PluggableTaskBuilderTest method shouldPublishErrorMessageIfPluginReturnsAFailureResponse.
@Test
public void shouldPublishErrorMessageIfPluginReturnsAFailureResponse() 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, DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext, String consoleLogCharset) {
return ExecutionResult.failure("err");
}
};
try {
taskBuilder.build(goPublisher, variableContext, taskExtension, null, null, "utf-8");
fail("expected exception to be thrown");
} catch (Exception e) {
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(goPublisher).taggedConsumeLine(eq(DefaultGoPublisher.ERR), captor.capture());
assertThat(captor.getValue(), is("err"));
assertThat(e.getMessage(), is("err"));
}
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PluggableTaskBuilderTest method shouldReturnPluggableTaskContext.
@Test
public void shouldReturnPluggableTaskContext() throws Exception {
PluggableTask task = mock(PluggableTask.class);
when(task.getPluginConfiguration()).thenReturn(new PluginConfiguration());
String workingDir = "test-directory";
PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, task, TEST_PLUGIN_ID, workingDir);
TaskExecutionContext taskExecutionContext = taskBuilder.buildTaskContext(goPublisher, variableContext, "utf-8");
assertThat(taskExecutionContext instanceof PluggableTaskContext, is(true));
assertThat(taskExecutionContext.workingDir(), is(workingDir));
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class ConfigElementImplementationRegistrarTest method shouldRegisterViewEngineForPluggableTask.
@Test
public void shouldRegisterViewEngineForPluggableTask() {
TaskPreference taskPreference = mock(TaskPreference.class);
TaskView view = mock(TaskView.class);
when(taskPreference.getView()).thenReturn(view);
when(view.template()).thenReturn("plugin-template-value");
when(view.displayValue()).thenReturn("Plugin display value");
PluggableTaskConfigStore.store().setPreferenceFor("plugin1", taskPreference);
PluggableTask pluggableTask = new PluggableTask(new PluginConfiguration("plugin1", "2"), new Configuration());
PluggableViewModel<PluggableTask> pluggableTaskViewModel = registry.getViewModelFor(pluggableTask, "new");
assertEquals(PluggableTaskViewModel.class, pluggableTaskViewModel.getClass());
assertThat(pluggableTaskViewModel.getModel(), is(pluggableTask));
}
Aggregations