Search in sources :

Example 41 with PluginConfiguration

use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.

the class PluggableTaskBuilderTest method shouldReturnConfigValueInExecConfig.

@Test
public void shouldReturnConfigValueInExecConfig() throws Exception {
    TaskConfig defaultTaskConfig = new TaskConfig();
    String propertyName = "URL";
    String defaultValue = "ABC.TXT";
    HashMap<String, String> configValue = new HashMap<>();
    configValue.put("value", "XYZ.TXT");
    Map<String, Map<String, String>> configMap = new HashMap<>();
    configMap.put(propertyName, configValue);
    PluggableTask task = mock(PluggableTask.class);
    when(task.getPluginConfiguration()).thenReturn(new PluginConfiguration());
    when(task.configAsMap()).thenReturn(configMap);
    PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, task, TEST_PLUGIN_ID, "test-directory");
    defaultTaskConfig.addProperty(propertyName).withDefault(defaultValue);
    TaskConfig config = taskBuilder.buildTaskConfig(defaultTaskConfig);
    assertThat(config.getValue(propertyName), is(configValue.get("value")));
}
Also used : HashMap(java.util.HashMap) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 42 with PluginConfiguration

use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.

the class PluggableTaskBuilderTest method shouldReturnDefaultValueInExecConfigWhenConfigValueIsEmptyString.

@Test
public void shouldReturnDefaultValueInExecConfigWhenConfigValueIsEmptyString() throws Exception {
    TaskConfig defaultTaskConfig = new TaskConfig();
    String propertyName = "URL";
    String defaultValue = "ABC.TXT";
    Map<String, Map<String, String>> configMap = new HashMap<>();
    HashMap<String, String> configValue = new HashMap<>();
    configValue.put("value", "");
    configMap.put(propertyName, configValue);
    PluggableTask task = mock(PluggableTask.class);
    when(task.getPluginConfiguration()).thenReturn(new PluginConfiguration());
    when(task.configAsMap()).thenReturn(configMap);
    PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, task, TEST_PLUGIN_ID, "test-directory");
    defaultTaskConfig.addProperty(propertyName).withDefault(defaultValue);
    TaskConfig config = taskBuilder.buildTaskConfig(defaultTaskConfig);
    assertThat(config.getValue(propertyName), is(defaultValue));
}
Also used : HashMap(java.util.HashMap) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 43 with PluginConfiguration

use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.

the class SCMMother method create.

public static SCM create(String id, String name, String pluginId, String pluginVersion, Configuration configuration) {
    SCM scm = new SCM();
    scm.setId(id);
    scm.setName(name);
    scm.setPluginConfiguration(new PluginConfiguration(pluginId, pluginVersion));
    scm.setConfiguration(configuration);
    return scm;
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration)

Example 44 with PluginConfiguration

use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.

the class SCMTest method shouldNotOverwriteValuesIfTheyAreNotAvailableInConfigAttributesMap.

@Test
public void shouldNotOverwriteValuesIfTheyAreNotAvailableInConfigAttributesMap() throws Exception {
    SCMConfigurations scmConfigurations = new SCMConfigurations();
    scmConfigurations.add(new SCMConfiguration("KEY1"));
    scmConfigurations.add(new SCMConfiguration("Key2"));
    SCMPreference scmPreference = mock(SCMPreference.class);
    when(scmPreference.getScmConfigurations()).thenReturn(scmConfigurations);
    SCMMetadataStore.getInstance().setPreferenceFor("plugin-id", scmPreference);
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"), ConfigurationPropertyMother.create("Key2"));
    SCM scm = new SCM("scm-id", new PluginConfiguration("plugin-id", "1"), configuration);
    Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1");
    scm.setConfigAttributes(attributeMap);
    assertThat(scm.getConfigAsMap().get("KEY1").get(SCM.VALUE_KEY), is("value1"));
    assertThat(scm.getConfigAsMap().get("Key2").get(SCM.VALUE_KEY), is(nullValue()));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) SCMPreference(com.thoughtworks.go.plugin.access.scm.SCMPreference) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfigurations(com.thoughtworks.go.plugin.access.scm.SCMConfigurations) Test(org.junit.Test)

Example 45 with PluginConfiguration

use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.

the class SCMTest method shouldIgnoreKeysPresentInConfigAttributesMapButNotPresentInConfigStore.

@Test
public void shouldIgnoreKeysPresentInConfigAttributesMapButNotPresentInConfigStore() throws Exception {
    SCMConfigurations scmConfigurations = new SCMConfigurations();
    scmConfigurations.add(new SCMConfiguration("KEY1"));
    SCMPreference scmPreference = mock(SCMPreference.class);
    when(scmPreference.getScmConfigurations()).thenReturn(scmConfigurations);
    SCMMetadataStore.getInstance().setPreferenceFor("plugin-id", scmPreference);
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
    SCM scm = new SCM("scm-id", new PluginConfiguration("plugin-id", "1"), configuration);
    Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1", "Key2", "value2");
    scm.setConfigAttributes(attributeMap);
    assertThat(scm.getConfigAsMap().get("KEY1").get(SCM.VALUE_KEY), is("value1"));
    assertFalse(scm.getConfigAsMap().containsKey("Key2"));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) SCMPreference(com.thoughtworks.go.plugin.access.scm.SCMPreference) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfigurations(com.thoughtworks.go.plugin.access.scm.SCMConfigurations) Test(org.junit.Test)

Aggregations

PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)83 Test (org.junit.Test)72 Configuration (com.thoughtworks.go.domain.config.Configuration)61 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)28 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)18 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)18 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)13 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)12 SCM (com.thoughtworks.go.domain.scm.SCM)11 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)10 TaskProperty (com.thoughtworks.go.domain.TaskProperty)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)8 Map (java.util.Map)8 SCMConfiguration (com.thoughtworks.go.plugin.access.scm.SCMConfiguration)7 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)6 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)5 SCMConfigurations (com.thoughtworks.go.plugin.access.scm.SCMConfigurations)5 HashMap (java.util.HashMap)5 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)4 SCMPreference (com.thoughtworks.go.plugin.access.scm.SCMPreference)4