Search in sources :

Example 11 with PluggableTask

use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.

the class PluggableTaskViewModelFactoryTest method shouldReturnMissingPluginTaskViewIfPluginIsMissing.

@Test
public void shouldReturnMissingPluginTaskViewIfPluginIsMissing() {
    String pluginId = "pluginId";
    PluggableTaskViewModelFactory factory = new PluggableTaskViewModelFactory();
    PluggableViewModel<PluggableTask> viewModel = factory.viewModelFor(new PluggableTask(new PluginConfiguration(pluginId, "1"), new Configuration()), "edit");
    assertThat(viewModel.getParameters().get("template"), is(String.format("Associated plugin '%s' not found. Please contact the Go admin to install the plugin.", pluginId)));
    assertThat(viewModel.getTypeForDisplay(), is(pluginId));
    assertThat(viewModel instanceof MissingPluggableTaskViewModel, is(true));
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) MissingPluggableTaskViewModel(com.thoughtworks.go.presentation.MissingPluggableTaskViewModel) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 12 with PluggableTask

use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.

the class PluggableTaskViewModelFactoryTest method typeForDisplayAndTemplateOfViewModelShouldBeGotFromThePlugin.

@Test
public void typeForDisplayAndTemplateOfViewModelShouldBeGotFromThePlugin() throws Exception {
    PluggableTask pluggableTask = new PluggableTask(new PluginConfiguration("plugin-1", "2"), new Configuration());
    PluggableTaskViewModelFactory factory = new PluggableTaskViewModelFactory();
    PluggableViewModel<PluggableTask> viewModel = factory.viewModelFor(pluggableTask, "new");
    assertThat(viewModel.getTypeForDisplay(), is("First plugin"));
    assertThat(viewModel.getParameters().get("template"), is("<input type='text' ng-model='abc'></input>"));
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 13 with PluggableTask

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);
}
Also used : PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 14 with PluggableTask

use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.

the class TaskViewService method allPluginTasks.

private List<PluggableTask> allPluginTasks() {
    final ArrayList<PluggableTask> tasks = new ArrayList<>();
    for (final String pluginId : PluggableTaskConfigStore.store().pluginIds()) {
        GoPluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptorFor(pluginId);
        TaskPreference taskPreference = PluggableTaskConfigStore.store().preferenceFor(pluginId);
        if (pluginDescriptor != null && taskPreference != null) {
            tasks.add(new PluggableTask(new PluginConfiguration(pluginId, pluginDescriptor.version()), getConfiguration(taskPreference.getConfig())));
        }
    }
    return tasks;
}
Also used : ArrayList(java.util.ArrayList) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)

Example 15 with PluggableTask

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, DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext, String consoleLogCharset) {
            throw new RuntimeException("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());
        String error = "Error: err";
        assertThat(captor.getValue(), is(error));
        assertThat(e.getMessage(), is(new RuntimeException("err").toString()));
    }
}
Also used : PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) ArgumentCaptor(org.mockito.ArgumentCaptor) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) CruiseControlException(com.thoughtworks.go.util.command.CruiseControlException) Test(org.junit.Test)

Aggregations

PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)38 Test (org.junit.Test)33 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)28 Configuration (com.thoughtworks.go.domain.config.Configuration)18 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)8 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)7 Map (java.util.Map)6 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)5 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)4 HashMap (java.util.HashMap)4 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)3 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)3 DefaultGoPublisher (com.thoughtworks.go.work.DefaultGoPublisher)3 Gson (com.google.gson.Gson)2 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)2 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)2 Property (com.thoughtworks.go.plugin.api.config.Property)2 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)2 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)2 MissingPluggableTaskViewModel (com.thoughtworks.go.presentation.MissingPluggableTaskViewModel)2