Search in sources :

Example 31 with TaskConfig

use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.

the class PluggableTaskServiceTest method isValidShouldMapPluginValidationErrorsToPluggableTaskForMissingConfigurations.

@Test
public void isValidShouldMapPluginValidationErrorsToPluggableTaskForMissingConfigurations() {
    PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("source", "source is mandatory"));
    PluggableTask pluggableTask = mock(PluggableTask.class);
    when(pluggableTask.isValid()).thenReturn(true);
    when(pluggableTask.toTaskConfig()).thenReturn(new TaskConfig());
    when(pluggableTask.getPluginConfiguration()).thenReturn(pluginConfiguration);
    when(pluggableTask.getConfiguration()).thenReturn(new Configuration());
    when(taskExtension.validate(any(String.class), any(TaskConfig.class))).thenReturn(validationResult);
    assertFalse(pluggableTaskService.isValid(pluggableTask));
    verify(pluggableTask).addError("source", "source is mandatory");
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.jupiter.api.Test)

Example 32 with TaskConfig

use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.

the class PluggableTaskPluginInfoBuilderTest method pluginInfoFor_ShouldProvidePluginInfoForAPlugin.

@Test
public void pluginInfoFor_ShouldProvidePluginInfoForAPlugin() throws Exception {
    GoPluginDescriptor.About about = new GoPluginDescriptor.About("Plugin Descriptor Validator", "1.0.1", "12.4", "Validates its own plugin descriptor", new GoPluginDescriptor.Vendor("ThoughtWorks Go Team", "www.thoughtworks.com"), Arrays.asList("Linux", "Windows", "Mac OS X"));
    GoPluginDescriptor plugin = new GoPluginDescriptor("docker-plugin", "1.0", about, null, null, false);
    PluginManager pluginManager = mock(PluginManager.class);
    PluggableTaskConfigStore packageMetadataStore = mock(PluggableTaskConfigStore.class);
    when(packageMetadataStore.pluginIds()).thenReturn(Collections.singleton(plugin.id()));
    when(pluginManager.getPluginDescriptorFor(plugin.id())).thenReturn(plugin);
    JsonBasedPluggableTask jsonBasedPluggableTask = mock(JsonBasedPluggableTask.class);
    TaskView taskView = new TaskView() {

        @Override
        public String displayValue() {
            return "task display value";
        }

        @Override
        public String template() {
            return "pluggable task view template";
        }
    };
    TaskConfig taskConfig = new TaskConfig();
    taskConfig.add(new TaskConfigProperty("key1", null));
    taskConfig.add(new TaskConfigProperty("key2", null));
    when(jsonBasedPluggableTask.config()).thenReturn(taskConfig);
    when(jsonBasedPluggableTask.view()).thenReturn(taskView);
    TaskPreference taskPreference = new TaskPreference(jsonBasedPluggableTask);
    when(packageMetadataStore.preferenceFor(plugin.id())).thenReturn(taskPreference);
    PluggableTaskPluginInfoBuilder builder = new PluggableTaskPluginInfoBuilder(pluginManager, packageMetadataStore);
    PluggableTaskPluginInfo pluginInfo = builder.pluginInfoFor(plugin.id());
    PluggableTaskPluginInfo expectedPluginInfo = new PluggableTaskPluginInfo(plugin, taskView.displayValue(), new PluggableInstanceSettings(configurations(taskConfig), new PluginView(taskView.template())));
    assertEquals(expectedPluginInfo, pluginInfo);
}
Also used : TaskView(com.thoughtworks.go.plugin.api.task.TaskView) JsonBasedPluggableTask(com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask) PluggableTaskPluginInfo(com.thoughtworks.go.server.ui.plugins.PluggableTaskPluginInfo) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) PluggableInstanceSettings(com.thoughtworks.go.server.ui.plugins.PluggableInstanceSettings) PluginView(com.thoughtworks.go.server.ui.plugins.PluginView) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PluggableTaskConfigStore(com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 33 with TaskConfig

use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.

the class PluggableTaskViewModelBuilderTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    builder = new PluggableTaskViewModelBuilder(manager);
    xunitConvertor = new GoPluginDescriptor("xunit.convertor", "version1", new GoPluginDescriptor.About("Xunit Convertor", "1.0", null, null, null, null), null, null, false);
    powershellTask = new GoPluginDescriptor("powershell.task", "version1", new GoPluginDescriptor.About("Powershell Task", "2.0", null, null, null, null), null, null, false);
    JsonBasedPluggableTask jsonBasedPluggableTask = mock(JsonBasedPluggableTask.class);
    TaskView taskView = new TaskView() {

        @Override
        public String displayValue() {
            return "task display value";
        }

        @Override
        public String template() {
            return "pluggable task view template";
        }
    };
    TaskConfig taskConfig = new TaskConfig();
    taskConfig.add(new TaskConfigProperty("key1", null));
    taskConfig.add(new TaskConfigProperty("key2", null));
    when(jsonBasedPluggableTask.config()).thenReturn(taskConfig);
    when(jsonBasedPluggableTask.view()).thenReturn(taskView);
    taskPreference = new TaskPreference(jsonBasedPluggableTask);
    PluggableTaskConfigStore.store().setPreferenceFor("xunit.convertor", taskPreference);
    PluggableTaskConfigStore.store().setPreferenceFor("powershell.task", taskPreference);
}
Also used : TaskView(com.thoughtworks.go.plugin.api.task.TaskView) JsonBasedPluggableTask(com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Before(org.junit.Before)

Example 34 with TaskConfig

use of com.thoughtworks.go.plugin.api.task.TaskConfig in project go-plugins by gocd.

the class CurlTask method config.

@Override
public TaskConfig config() {
    TaskConfig config = new TaskConfig();
    config.addProperty(URL_PROPERTY);
    config.addProperty(SECURE_CONNECTION_PROPERTY).withDefault(SECURE_CONNECTION);
    config.addProperty(REQUEST_PROPERTY).withDefault(REQUEST_TYPE);
    config.addProperty(ADDITIONAL_OPTIONS);
    return config;
}
Also used : TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig)

Aggregations

TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)34 Test (org.junit.jupiter.api.Test)23 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)16 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)15 Configuration (com.thoughtworks.go.domain.config.Configuration)13 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)11 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)11 TaskProperty (com.thoughtworks.go.domain.TaskProperty)8 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)7 Task (com.thoughtworks.go.plugin.api.task.Task)7 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)7 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)6 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)5 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)5 Property (com.thoughtworks.go.plugin.api.config.Property)4 JsonBasedPluggableTask (com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask)3 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)3 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)3 Action (com.thoughtworks.go.plugin.infra.Action)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3