Search in sources :

Example 1 with TaskConfigProperty

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

the class PluggableTaskPluginInfoBuilderTest method allPluginInfos_ShouldReturnAListOfAllPluginInfos.

@Test
public void allPluginInfos_ShouldReturnAListOfAllPluginInfos() 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);
    Collection<PluggableTaskPluginInfo> pluginInfos = builder.allPluginInfos();
    PluggableTaskPluginInfo expectedPluginInfo = new PluggableTaskPluginInfo(plugin, taskView.displayValue(), new PluggableInstanceSettings(configurations(taskConfig), new PluginView(taskView.template())));
    assertEquals(Arrays.asList(expectedPluginInfo), pluginInfos);
}
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 2 with TaskConfigProperty

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

the class PluggableTaskService method validate.

public boolean validate(final PluggableTask modifiedTask) {
    final TaskConfig configuration = new TaskConfig();
    for (ConfigurationProperty configurationProperty : modifiedTask.getConfiguration()) {
        configuration.add(new TaskConfigProperty(configurationProperty.getConfigurationKey().getName(), configurationProperty.getValue()));
    }
    final String pluginId = modifiedTask.getPluginConfiguration().getId();
    ValidationResult validationResult = taskExtension.validate(pluginId, configuration);
    final TaskPreference preference = PluggableTaskConfigStore.store().preferenceFor(pluginId);
    if (PluggableTaskConfigStore.store().hasPreferenceFor(pluginId)) {
        for (ConfigurationProperty configurationProperty : modifiedTask.getConfiguration()) {
            String key = configurationProperty.getConfigurationKey().getName();
            final Property property = preference.getConfig().get(key);
            if (property != null) {
                final Boolean required = property.getOption(Property.REQUIRED);
                if (required && StringUtils.isBlank(configurationProperty.getConfigValue()))
                    validationResult.addError(new ValidationError(property.getKey(), localizer.localize("MANDATORY_CONFIGURATION_FIELD")));
            }
        }
    }
    for (ValidationError validationError : validationResult.getErrors()) {
        modifiedTask.getConfiguration().getProperty(validationError.getKey()).addError(validationError.getKey(), validationError.getMessage());
    }
    return validationResult.isSuccessful();
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)

Example 3 with TaskConfigProperty

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

the class TaskViewServiceTest method shouldStoreDefaultValuesGivenForPropertiesInAPluginWhenInitializingANewTaskPlugin.

@Test
public void shouldStoreDefaultValuesGivenForPropertiesInAPluginWhenInitializingANewTaskPlugin() throws Exception {
    String plugin = "task-plugin";
    when(pluginManager.getPluginDescriptorFor(plugin)).thenReturn(new GoPluginDescriptor(plugin, "1", null, null, null, false));
    Property taskConfigProperty1 = new TaskConfigProperty("key1", null);
    Property taskConfigProperty2 = new TaskConfigProperty("key2", null);
    Property taskConfigProperty3 = new TaskConfigProperty("key3", null);
    storeTaskPreferences(plugin, taskConfigProperty1.withDefault("default1"), taskConfigProperty2.withDefault("default2"), taskConfigProperty3);
    when(registry.implementersOf(Task.class)).thenReturn(Arrays.<Class<? extends Task>>asList(PluggableTask.class));
    PluggableTask pluggableTask = (PluggableTask) taskViewService.taskInstanceFor(new PluggableTask(new PluginConfiguration(plugin, "1"), new Configuration()).getTaskType());
    assertThat(pluggableTask.getConfiguration().getProperty("key1").getValue(), is("default1"));
    assertThat(pluggableTask.getConfiguration().getProperty("key2").getValue(), is("default2"));
    assertNull(pluggableTask.getConfiguration().getProperty("key3").getValue());
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 4 with TaskConfigProperty

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

the class TaskViewServiceTest method shouldFetchPluggableTasksWithSecureConfigurations.

@Test
public void shouldFetchPluggableTasksWithSecureConfigurations() throws Exception {
    String plugin = "task-plugin";
    when(pluginManager.getPluginDescriptorFor(plugin)).thenReturn(new GoPluginDescriptor(plugin, "1", null, null, null, false));
    Property taskConfigProperty = new TaskConfigProperty("key1", null).with(Property.SECURE, true);
    storeTaskPreferences(plugin, taskConfigProperty);
    when(registry.implementersOf(Task.class)).thenReturn(Arrays.<Class<? extends Task>>asList(PluggableTask.class));
    PluggableTask pluggableTask = (PluggableTask) taskViewService.taskInstanceFor(new PluggableTask(new PluginConfiguration(plugin, "1"), null).getTaskType());
    assertTrue(pluggableTask.getConfiguration().first().isSecure());
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 5 with TaskConfigProperty

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

the class PluggableTaskTest method addProperty.

private void addProperty(TaskConfig taskConfig, String key, String displayName, int displayOrder) {
    TaskConfigProperty property = taskConfig.addProperty(key);
    property.with(Property.DISPLAY_NAME, displayName);
    property.with(Property.DISPLAY_ORDER, displayOrder);
}
Also used : TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty)

Aggregations

TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)12 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)6 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)5 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)4 Test (org.junit.Test)4 JsonBasedPluggableTask (com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask)3 Property (com.thoughtworks.go.plugin.api.config.Property)3 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)2 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)2 PluggableTaskConfigStore (com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore)2 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)2 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)2 PluggableInstanceSettings (com.thoughtworks.go.server.ui.plugins.PluggableInstanceSettings)2 PluggableTaskPluginInfo (com.thoughtworks.go.server.ui.plugins.PluggableTaskPluginInfo)2 PluginView (com.thoughtworks.go.server.ui.plugins.PluginView)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 GsonBuilder (com.google.gson.GsonBuilder)1 Configuration (com.thoughtworks.go.domain.config.Configuration)1 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)1