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")));
}
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));
}
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;
}
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()));
}
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"));
}
Aggregations