Search in sources :

Example 21 with Property

use of com.thoughtworks.go.plugin.api.config.Property in project gocd by gocd.

the class RepositoryConfigurationTest method shouldGetAllRepoConfigurationsSortedByDisplayOrder.

@Test
public void shouldGetAllRepoConfigurationsSortedByDisplayOrder() throws Exception {
    Property c1 = new PackageMaterialProperty("k1").with(Property.DISPLAY_ORDER, 2);
    Property c2 = new PackageMaterialProperty("k2").with(Property.DISPLAY_ORDER, 0);
    Property c3 = new PackageMaterialProperty("k3").with(Property.DISPLAY_ORDER, 1);
    RepositoryConfiguration repoConfigurations = new RepositoryConfiguration();
    repoConfigurations.add(c1);
    repoConfigurations.add(c2);
    repoConfigurations.add(c3);
    assertThat(repoConfigurations.list().get(0), is(c2));
    assertThat(repoConfigurations.list().get(1), is(c3));
    assertThat(repoConfigurations.list().get(2), is(c1));
}
Also used : Property(com.thoughtworks.go.plugin.api.config.Property) Test(org.junit.Test)

Example 22 with Property

use of com.thoughtworks.go.plugin.api.config.Property in project gocd by gocd.

the class TaskConfigTest method shouldAddPropertyWithGiveName.

@Test
public void shouldAddPropertyWithGiveName() throws Exception {
    String abcd = "Abcd";
    String abcdDefault = "first of alphabets";
    String wxyz = "wxyz";
    String wxyzDefault = "last of alphabets";
    taskConfig.addProperty(wxyz).withDefault(wxyzDefault);
    taskConfig.addProperty(abcd).withDefault(abcdDefault);
    List<? extends Property> properties = taskConfig.list();
    assertThat(properties.size(), is(2));
    for (Property property : properties) {
        assertThat(property != null, is(true));
        assertThat(property instanceof TaskConfigProperty, is(true));
    }
    assertThat(taskConfig.get(abcd) != null, is(true));
    assertThat(taskConfig.get(abcd).getValue(), is(abcdDefault));
    assertThat(taskConfig.get(wxyz) != null, is(true));
    assertThat(taskConfig.get(wxyz).getValue(), is(wxyzDefault));
}
Also used : Property(com.thoughtworks.go.plugin.api.config.Property) Test(org.junit.Test)

Example 23 with Property

use of com.thoughtworks.go.plugin.api.config.Property in project gocd by gocd.

the class PluggableTask method getPropertiesForDisplay.

@Override
public List<TaskProperty> getPropertiesForDisplay() {
    ArrayList<TaskProperty> taskProperties = new ArrayList<>();
    if (PluggableTaskConfigStore.store().hasPreferenceFor(pluginConfiguration.getId())) {
        TaskPreference preference = taskPreference();
        List<? extends Property> propertyDefinitions = preference.getConfig().list();
        for (Property propertyDefinition : propertyDefinitions) {
            ConfigurationProperty configuredProperty = configuration.getProperty(propertyDefinition.getKey());
            if (configuredProperty == null)
                continue;
            taskProperties.add(new TaskProperty(propertyDefinition.getOption(Property.DISPLAY_NAME), configuredProperty.getDisplayValue(), configuredProperty.getConfigKeyName()));
        }
        return taskProperties;
    }
    for (ConfigurationProperty property : configuration) {
        taskProperties.add(new TaskProperty(property.getConfigKeyName(), property.getDisplayValue()));
    }
    return taskProperties;
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ArrayList(java.util.ArrayList) TaskProperty(com.thoughtworks.go.domain.TaskProperty) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) TaskProperty(com.thoughtworks.go.domain.TaskProperty) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)

Example 24 with Property

use of com.thoughtworks.go.plugin.api.config.Property in project gocd by gocd.

the class PluggableTask method setTaskConfigAttributes.

@Override
protected void setTaskConfigAttributes(Map attributes) {
    TaskConfig taskConfig = PluggableTaskConfigStore.store().preferenceFor(pluginConfiguration.getId()).getConfig();
    for (Property property : taskConfig.list()) {
        String key = property.getKey();
        if (attributes.containsKey(key)) {
            Boolean isSecure = property.getOption(Property.SECURE);
            if (configuration.getProperty(key) == null) {
                configuration.addNewConfiguration(property.getKey(), isSecure);
            }
            configuration.getProperty(key).setConfigurationValue(new ConfigurationValue((String) attributes.get(key)));
            configuration.getProperty(key).handleSecureValueConfiguration(isSecure);
        }
    }
}
Also used : ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) TaskProperty(com.thoughtworks.go.domain.TaskProperty) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty)

Example 25 with Property

use of com.thoughtworks.go.plugin.api.config.Property in project gocd by gocd.

the class JsonBasedPluggableTaskTest method shouldGetTheTaskConfig.

@Test
public void shouldGetTheTaskConfig() {
    String jsonResponse = "{" + "\"URL\":{\"default-value\":\"\",\"secure\":false,\"required\":true}," + "\"USER\":{\"default-value\":\"foo\",\"secure\":true,\"required\":true}," + "\"PASSWORD\":{}" + "}";
    when(goPluginApiResponse.responseBody()).thenReturn(jsonResponse);
    TaskConfig config = task.config();
    Property url = config.get("URL");
    assertThat(url.getOption(Property.REQUIRED), is(true));
    assertThat(url.getOption(Property.SECURE), is(false));
    Property user = config.get("USER");
    assertThat(user.getOption(Property.REQUIRED), is(true));
    assertThat(user.getOption(Property.SECURE), is(true));
    Property password = config.get("PASSWORD");
    assertThat(password.getOption(Property.REQUIRED), is(true));
    assertThat(password.getOption(Property.SECURE), is(false));
    ArgumentCaptor<GoPluginApiRequest> argument = ArgumentCaptor.forClass(GoPluginApiRequest.class);
    verify(pluginManager).submitTo(eq(pluginId), argument.capture());
    MatcherAssert.assertThat(argument.getValue().extension(), Matchers.is(TaskExtension.TASK_EXTENSION));
    MatcherAssert.assertThat(argument.getValue().extensionVersion(), Matchers.is(JsonBasedTaskExtensionHandler_V1.VERSION));
    MatcherAssert.assertThat(argument.getValue().requestName(), Matchers.is(TaskExtension.CONFIGURATION_REQUEST));
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) Test(org.junit.Test)

Aggregations

Property (com.thoughtworks.go.plugin.api.config.Property)26 Test (org.junit.Test)15 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)13 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)8 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)4 TaskProperty (com.thoughtworks.go.domain.TaskProperty)3 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)3 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)3 ArrayList (java.util.ArrayList)3 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)2 Configuration (com.thoughtworks.go.domain.config.Configuration)2 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)2 PluginConfiguration (com.thoughtworks.go.server.ui.plugins.PluginConfiguration)2 HashMap (java.util.HashMap)2 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)1 PluginSettingsProperty (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsProperty)1 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)1 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)1 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)1 GoCipher (com.thoughtworks.go.security.GoCipher)1