use of com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry in project gocd by gocd.
the class TaskViewServiceTest method shouldGetTaskInstanceForAType.
@Test
public void shouldGetTaskInstanceForAType() throws Exception {
ConfigElementImplementationRegistry registry = this.registry;
when(registry.implementersOf(Task.class)).thenReturn(taskImplementations());
TaskViewService taskViewService = new TaskViewService(registry, mock(PluginManager.class));
assertThat(taskViewService.taskInstanceFor(new AntTask().getTaskType()), is(new AntTask()));
}
use of com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry 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.registry.ConfigElementImplementationRegistry in project gocd by gocd.
the class TaskViewServiceTest method shouldThrowAnExceptionIfTheTaskOfGivenTypeIsNotFound.
@Test
public void shouldThrowAnExceptionIfTheTaskOfGivenTypeIsNotFound() {
ConfigElementImplementationRegistry registry = this.registry;
List<Class<? extends Task>> taskClasses = new ArrayList<>();
taskClasses.add(AntTask.class);
when(registry.implementersOf(Task.class)).thenReturn(taskClasses);
TaskViewService service = new TaskViewService(registry, mock(PluginManager.class));
try {
service.taskInstanceFor("Unknown");
fail("Should have failed since the given task is not available in the registry");
} catch (RuntimeException e) {
assertThat(e.getMessage(), is("Could not find any task of type: Unknown"));
}
}
use of com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry in project gocd by gocd.
the class UniqueOnCancelValidatorTest method shouldNotFailWithExceptionWhenThereIsOneOnCancelTaskForABuiltInTask.
@Test
public void shouldNotFailWithExceptionWhenThereIsOneOnCancelTaskForABuiltInTask() throws Exception {
ConfigElementImplementationRegistry registry = mock(ConfigElementImplementationRegistry.class);
when(registry.implementersOf(Task.class)).thenReturn(tasks(ExecTask.class));
String content = "<cruise>" + " <pipeline>" + " <stage>" + " <jobs>" + " <job>" + " <tasks>" + " <exec command=\"install_addons.sh\">" + " <runif status=\"passed\" />" + " <oncancel>\n" + " <ant buildfile=\"build.xml\" />\n" + " </oncancel>" + " </exec>" + " </tasks>" + " </job>" + " </jobs>" + " </stage>" + " </pipeline>" + "</cruise>";
UniqueOnCancelValidator validator = new UniqueOnCancelValidator();
validator.validate(elementFor(content), registry);
}
use of com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry in project gocd by gocd.
the class UniqueOnCancelValidatorTest method shouldFailWithExceptionWhenThereIsMoreThanOneOnCancelTasksForAPluginInTask.
@Test
public void shouldFailWithExceptionWhenThereIsMoreThanOneOnCancelTasksForAPluginInTask() throws Exception {
ConfigElementImplementationRegistry registry = mock(ConfigElementImplementationRegistry.class);
when(registry.implementersOf(Task.class)).thenReturn(tasks(ExecTask.class, PluggableTask.class));
String content = "<cruise>" + " <pipeline>" + " <stage>" + " <jobs>" + " <job>" + " <tasks>" + " <task name=\"\">\n" + " <pluginConfiguration id=\"curl.task.plugin\" version=\"1\" />\n" + " <configuration>\n" + " <property>\n" + " <key>Url</key>\n" + " <value>With_On_Cancel</value>\n" + " </property>\n" + " </configuration>\n" + " <runif status=\"passed\" />\n" + " <oncancel>\n" + " <ant buildfile=\"blah\" target=\"blah1\" />\n" + " </oncancel>\n" + " <oncancel>\n" + " <ant buildfile=\"blah\" target=\"blah2\" />\n" + " </oncancel>\n" + " </task>" + " </tasks>" + " </job>" + " </jobs>" + " </stage>" + " </pipeline>" + "</cruise>";
try {
UniqueOnCancelValidator validator = new UniqueOnCancelValidator();
validator.validate(elementFor(content), registry);
} catch (Exception e) {
assertThat(e.getMessage(), is("Task [task] should not contain more than 1 oncancel task"));
}
}
Aggregations