use of com.thoughtworks.go.config.FetchTask in project gocd by gocd.
the class TaskViewServiceTest method getOnCancelTaskViewModels_shouldUsePassedInTaskOnCancelIfAvailable.
@Test
public void getOnCancelTaskViewModels_shouldUsePassedInTaskOnCancelIfAvailable() {
when(registry.implementersOf(Task.class)).thenReturn(taskImplementations());
AntTask ant = new AntTask();
FetchTask fetch = new FetchTask();
AntTask given = new AntTask();
ExecTask cancelExec = new ExecTask("ls", "-la", ".");
given.setCancelTask(cancelExec);
when(registry.getViewModelFor(ant, "new")).thenReturn(viewModel(ant));
when(registry.getViewModelFor(fetch, "new")).thenReturn(viewModel(fetch));
when(registry.getViewModelFor(cancelExec, "edit")).thenReturn(viewModel(cancelExec));
List<PluggableViewModel<Task>> onCancelTaskViewModels = new TaskViewService(registry, mock(PluginManager.class)).getOnCancelTaskViewModels(given);
assertThat(onCancelTaskViewModels, is(asList(viewModel(ant), viewModel(cancelExec), viewModel(fetch))));
}
use of com.thoughtworks.go.config.FetchTask in project gocd by gocd.
the class TaskViewServiceTest method shouldCreateTaskViewModelsGivenATask.
@Test
public void shouldCreateTaskViewModelsGivenATask() {
when(registry.implementersOf(Task.class)).thenReturn(taskImplementations());
ExecTask given = new ExecTask("mkdir", "foo", "work");
AntTask ant = new AntTask();
FetchTask fetch = new FetchTask();
when(registry.getViewModelFor(ant, "new")).thenReturn(viewModel(ant));
when(registry.getViewModelFor(fetch, "new")).thenReturn(viewModel(fetch));
when(registry.getViewModelFor(given, "new")).thenReturn(viewModel(given));
List<PluggableViewModel> viewModels = taskViewService.getTaskViewModelsWith(given);
assertThat(viewModels.size(), is(3));
assertThat(viewModels.contains(viewModel(ant)), is(true));
assertThat(viewModels.contains(viewModel(fetch)), is(true));
assertThat(viewModels.contains(viewModel(given)), is(true));
}
use of com.thoughtworks.go.config.FetchTask in project gocd by gocd.
the class TaskViewServiceTest method shouldGetListOfOnCancelTaskViewModels.
@Test
public void shouldGetListOfOnCancelTaskViewModels() {
ConfigElementImplementationRegistry registry = this.registry;
when(registry.implementersOf(Task.class)).thenReturn(taskImplementations());
AntTask ant = new AntTask();
FetchTask fetch = new FetchTask();
ExecTask exec = new ExecTask();
when(registry.getViewModelFor(ant, "new")).thenReturn(viewModel(ant));
when(registry.getViewModelFor(fetch, "new")).thenReturn(viewModel(fetch));
when(registry.getViewModelFor(exec, "new")).thenReturn(viewModel(exec));
TaskViewService taskViewService = new TaskViewService(registry, mock(PluginManager.class));
List<PluggableViewModel<Task>> onCancelTaskViewModels = taskViewService.getOnCancelTaskViewModels(new AntTask());
assertThat(onCancelTaskViewModels, is(asList(viewModel(ant), viewModel(exec), viewModel(fetch))));
}
use of com.thoughtworks.go.config.FetchTask in project gocd by gocd.
the class FetchTaskRepresenter method fetchTaskFromJson.
private static AbstractFetchTask fetchTaskFromJson(JsonReader jsonReader) {
FetchTask fetchTask = new FetchTask();
if (jsonReader == null) {
return fetchTask;
}
setBaseTask(jsonReader, fetchTask);
Optional<Boolean> isSourceAFileValue = jsonReader.optBoolean("is_source_a_file");
Boolean isSourceAFile = isSourceAFileValue.orElse(false);
if (isSourceAFile) {
jsonReader.readStringIfPresent("source", fetchTask::setSrcfile);
} else {
jsonReader.readStringIfPresent("source", fetchTask::setSrcdir);
}
jsonReader.readStringIfPresent("destination", fetchTask::setDest);
return fetchTask;
}
use of com.thoughtworks.go.config.FetchTask in project gocd by gocd.
the class FetchTaskRepresenter method fetchTaskFromJson.
private static AbstractFetchTask fetchTaskFromJson(JsonReader jsonReader) {
FetchTask fetchTask = new FetchTask();
if (jsonReader == null) {
return fetchTask;
}
setBaseTask(jsonReader, fetchTask);
Optional<Boolean> isSourceAFileValue = jsonReader.optBoolean("is_source_a_file");
Boolean isSourceAFile = isSourceAFileValue.orElse(false);
if (isSourceAFile) {
jsonReader.readStringIfPresent("source", fetchTask::setSrcfile);
} else {
jsonReader.readStringIfPresent("source", fetchTask::setSrcdir);
}
jsonReader.readStringIfPresent("destination", fetchTask::setDest);
return fetchTask;
}
Aggregations