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