Search in sources :

Example 1 with ConfigElementImplementationRegistry

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()));
}
Also used : PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) AntTask(com.thoughtworks.go.config.AntTask) Test(org.junit.Test)

Example 2 with ConfigElementImplementationRegistry

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))));
}
Also used : PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ExecTask(com.thoughtworks.go.config.ExecTask) AntTask(com.thoughtworks.go.config.AntTask) PluggableViewModel(com.thoughtworks.go.plugins.presentation.PluggableViewModel) FetchTask(com.thoughtworks.go.config.FetchTask) Test(org.junit.Test)

Example 3 with ConfigElementImplementationRegistry

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"));
    }
}
Also used : PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) ExecTask(com.thoughtworks.go.config.ExecTask) Task(com.thoughtworks.go.domain.Task) FetchTask(com.thoughtworks.go.config.FetchTask) AntTask(com.thoughtworks.go.config.AntTask) FetchPluggableArtifactTask(com.thoughtworks.go.config.FetchPluggableArtifactTask) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with ConfigElementImplementationRegistry

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);
}
Also used : ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ExecTask(com.thoughtworks.go.config.ExecTask) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigElementImplementationRegistry

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"));
    }
}
Also used : ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ExecTask(com.thoughtworks.go.config.ExecTask) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)26 Test (org.junit.jupiter.api.Test)10 ExecTask (com.thoughtworks.go.config.ExecTask)8 NoPluginsInstalled (com.thoughtworks.go.config.registry.NoPluginsInstalled)6 ConfigRepository (com.thoughtworks.go.service.ConfigRepository)6 TimeProvider (com.thoughtworks.go.util.TimeProvider)6 ConfigElementImplementationRegistrar (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistrar)5 IOException (java.io.IOException)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 AntTask (com.thoughtworks.go.config.AntTask)3 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)3 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)3 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)3 Date (java.util.Date)3 Before (org.junit.Before)3 Test (org.junit.Test)3 ConfigCache (com.thoughtworks.go.config.ConfigCache)2 FetchTask (com.thoughtworks.go.config.FetchTask)2 MagicalGoConfigXmlLoader (com.thoughtworks.go.config.MagicalGoConfigXmlLoader)2 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)2