Search in sources :

Example 6 with TaskPreference

use of com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference in project gocd by gocd.

the class PluggableTaskTest method shouldPopulatePropertiesForDisplayRetainingOrderAndDisplayNameIfConfigured.

@Test
public void shouldPopulatePropertiesForDisplayRetainingOrderAndDisplayNameIfConfigured() throws Exception {
    Task taskDetails = mock(Task.class);
    TaskConfig taskConfig = new TaskConfig();
    addProperty(taskConfig, "KEY2", "Key 2", 1);
    addProperty(taskConfig, "KEY1", "Key 1", 0);
    addProperty(taskConfig, "KEY3", "Key 3", 2);
    when(taskDetails.config()).thenReturn(taskConfig);
    when(taskDetails.view()).thenReturn(mock(TaskView.class));
    String pluginId = "plugin_with_all_details";
    PluggableTaskConfigStore.store().setPreferenceFor(pluginId, new TaskPreference(taskDetails));
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY3", true, "encryptedValue1"), ConfigurationPropertyMother.create("KEY1", false, "value1"), ConfigurationPropertyMother.create("KEY2", false, "value2"));
    PluggableTask task = new PluggableTask(new PluginConfiguration(pluginId, "1"), configuration);
    List<TaskProperty> propertiesForDisplay = task.getPropertiesForDisplay();
    assertThat(propertiesForDisplay.size(), is(3));
    assertProperty(propertiesForDisplay.get(0), "Key 1", "value1", "key1");
    assertProperty(propertiesForDisplay.get(1), "Key 2", "value2", "key2");
    assertProperty(propertiesForDisplay.get(2), "Key 3", "****", "key3");
}
Also used : Task(com.thoughtworks.go.plugin.api.task.Task) AntTask(com.thoughtworks.go.config.AntTask) TaskView(com.thoughtworks.go.plugin.api.task.TaskView) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskProperty(com.thoughtworks.go.domain.TaskProperty) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 7 with TaskPreference

use of com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference in project gocd by gocd.

the class PluggableTaskTest method shouldNotOverwriteValuesIfTheyAreNotAvailableInConfigAttributesMap.

@Test
public void shouldNotOverwriteValuesIfTheyAreNotAvailableInConfigAttributesMap() throws Exception {
    TaskPreference taskPreference = mock(TaskPreference.class);
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"), ConfigurationPropertyMother.create("Key2"));
    PluggableTaskConfigStore.store().setPreferenceFor("abc.def", taskPreference);
    PluggableTask task = new PluggableTask(new PluginConfiguration("abc.def", "1"), configuration);
    Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1");
    TaskConfig taskConfig = new TaskConfig();
    TaskProperty property1 = new TaskProperty("KEY1", "value1");
    TaskProperty property2 = new TaskProperty("Key2", null);
    taskConfig.addProperty(property1.getName());
    taskConfig.addProperty(property2.getName());
    when(taskPreference.getConfig()).thenReturn(taskConfig);
    task.setTaskConfigAttributes(attributeMap);
    assertThat(task.configAsMap().get("KEY1").get(PluggableTask.VALUE_KEY), is("value1"));
    assertThat(task.configAsMap().get("Key2").get(PluggableTask.VALUE_KEY), is(nullValue()));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskProperty(com.thoughtworks.go.domain.TaskProperty) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 8 with TaskPreference

use of com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference in project gocd by gocd.

the class PluggableTaskTest method shouldAddConfigurationProperties.

@Test
public void shouldAddConfigurationProperties() {
    List<ConfigurationProperty> configurationProperties = Arrays.asList(ConfigurationPropertyMother.create("key", "value", "encValue"), new ConfigurationProperty());
    PluginConfiguration pluginConfiguration = new PluginConfiguration("github.pr", "1.1");
    TaskPreference taskPreference = mock(TaskPreference.class);
    TaskConfig taskConfig = new TaskConfig();
    Configuration configuration = new Configuration();
    Property property = new Property("key");
    property.with(Property.SECURE, false);
    PluggableTaskConfigStore.store().setPreferenceFor(pluginConfiguration.getId(), taskPreference);
    TaskConfigProperty taskConfigProperty = taskConfig.addProperty("key");
    when(taskPreference.getConfig()).thenReturn(taskConfig);
    PluggableTask pluggableTask = new PluggableTask(pluginConfiguration, configuration);
    pluggableTask.addConfigurations(configurationProperties);
    assertThat(configuration.size(), is(2));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) TaskProperty(com.thoughtworks.go.domain.TaskProperty) 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) Test(org.junit.Test)

Example 9 with TaskPreference

use of com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference in project gocd by gocd.

the class PluggableTaskTest method shouldGetOnlyConfiguredPropertiesIfACertainPropertyDefinedByPluginIsNotConfiguredByUser.

@Test
public void shouldGetOnlyConfiguredPropertiesIfACertainPropertyDefinedByPluginIsNotConfiguredByUser() throws Exception {
    Task taskDetails = mock(Task.class);
    TaskConfig taskConfig = new TaskConfig();
    addProperty(taskConfig, "KEY2", "Key 2", 1);
    addProperty(taskConfig, "KEY1", "Key 1", 0);
    addProperty(taskConfig, "KEY3", "Key 3", 2);
    when(taskDetails.config()).thenReturn(taskConfig);
    when(taskDetails.view()).thenReturn(mock(TaskView.class));
    String pluginId = "plugin_with_all_details";
    PluggableTaskConfigStore.store().setPreferenceFor(pluginId, new TaskPreference(taskDetails));
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1", false, "value1"), ConfigurationPropertyMother.create("KEY2", false, "value2"));
    PluggableTask task = new PluggableTask(new PluginConfiguration(pluginId, "1"), configuration);
    List<TaskProperty> propertiesForDisplay = task.getPropertiesForDisplay();
    assertThat(propertiesForDisplay.size(), is(2));
    assertProperty(propertiesForDisplay.get(0), "Key 1", "value1", "key1");
    assertProperty(propertiesForDisplay.get(1), "Key 2", "value2", "key2");
}
Also used : Task(com.thoughtworks.go.plugin.api.task.Task) AntTask(com.thoughtworks.go.config.AntTask) TaskView(com.thoughtworks.go.plugin.api.task.TaskView) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskProperty(com.thoughtworks.go.domain.TaskProperty) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 10 with TaskPreference

use of com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference 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 && StringUtil.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)

Aggregations

TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)26 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)16 Test (org.junit.Test)14 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)12 Configuration (com.thoughtworks.go.domain.config.Configuration)11 TaskProperty (com.thoughtworks.go.domain.TaskProperty)8 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)8 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)7 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)5 JsonBasedPluggableTask (com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask)4 PluggableInstanceSettings (com.thoughtworks.go.server.ui.plugins.PluggableInstanceSettings)4 PluginView (com.thoughtworks.go.server.ui.plugins.PluginView)4 Before (org.junit.Before)4 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)3 Property (com.thoughtworks.go.plugin.api.config.Property)3 PluggableTaskPluginInfo (com.thoughtworks.go.server.ui.plugins.PluggableTaskPluginInfo)3 ArrayList (java.util.ArrayList)3 AntTask (com.thoughtworks.go.config.AntTask)2 PluggableTaskConfigStore (com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore)2