use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.
the class PluggableTaskPluginInfoBuilderTest method allPluginInfos_ShouldReturnAListOfAllPluginInfos.
@Test
public void allPluginInfos_ShouldReturnAListOfAllPluginInfos() throws Exception {
GoPluginDescriptor.About about = new GoPluginDescriptor.About("Plugin Descriptor Validator", "1.0.1", "12.4", "Validates its own plugin descriptor", new GoPluginDescriptor.Vendor("ThoughtWorks Go Team", "www.thoughtworks.com"), Arrays.asList("Linux", "Windows", "Mac OS X"));
GoPluginDescriptor plugin = new GoPluginDescriptor("docker-plugin", "1.0", about, null, null, false);
PluginManager pluginManager = mock(PluginManager.class);
PluggableTaskConfigStore packageMetadataStore = mock(PluggableTaskConfigStore.class);
when(packageMetadataStore.pluginIds()).thenReturn(Collections.singleton(plugin.id()));
when(pluginManager.getPluginDescriptorFor(plugin.id())).thenReturn(plugin);
JsonBasedPluggableTask jsonBasedPluggableTask = mock(JsonBasedPluggableTask.class);
TaskView taskView = new TaskView() {
@Override
public String displayValue() {
return "task display value";
}
@Override
public String template() {
return "pluggable task view template";
}
};
TaskConfig taskConfig = new TaskConfig();
taskConfig.add(new TaskConfigProperty("key1", null));
taskConfig.add(new TaskConfigProperty("key2", null));
when(jsonBasedPluggableTask.config()).thenReturn(taskConfig);
when(jsonBasedPluggableTask.view()).thenReturn(taskView);
TaskPreference taskPreference = new TaskPreference(jsonBasedPluggableTask);
when(packageMetadataStore.preferenceFor(plugin.id())).thenReturn(taskPreference);
PluggableTaskPluginInfoBuilder builder = new PluggableTaskPluginInfoBuilder(pluginManager, packageMetadataStore);
Collection<PluggableTaskPluginInfo> pluginInfos = builder.allPluginInfos();
PluggableTaskPluginInfo expectedPluginInfo = new PluggableTaskPluginInfo(plugin, taskView.displayValue(), new PluggableInstanceSettings(configurations(taskConfig), new PluginView(taskView.template())));
assertEquals(Arrays.asList(expectedPluginInfo), pluginInfos);
}
use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.
the class PluggableTaskServiceTest method isValidShouldValidateTaskAgainstPlugin.
@Test
public void isValidShouldValidateTaskAgainstPlugin() {
TaskConfig taskConfig = mock(TaskConfig.class);
ValidationResult validationResult = mock(ValidationResult.class);
PluggableTask pluggableTask = mock(PluggableTask.class);
PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
when(pluggableTask.isValid()).thenReturn(true);
when(pluggableTask.getPluginConfiguration()).thenReturn(pluginConfiguration);
when(pluggableTask.toTaskConfig()).thenReturn(taskConfig);
when(taskExtension.validate(pluginConfiguration.getId(), taskConfig)).thenReturn(validationResult);
when(validationResult.isSuccessful()).thenReturn(true);
assertTrue(pluggableTaskService.isValid(pluggableTask));
}
use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.
the class PluggableTaskServiceTest method setUp.
@Before
public void setUp() throws Exception {
taskExtension = mock(TaskExtension.class);
localizer = mock(Localizer.class);
pluggableTaskService = new PluggableTaskService(taskExtension, localizer);
final TaskPreference preference = mock(TaskPreference.class);
final TaskConfig taskConfig = new TaskConfig();
final TaskConfigProperty key1 = taskConfig.addProperty("KEY1");
key1.with(Property.REQUIRED, true);
taskConfig.addProperty("KEY2");
when(preference.getConfig()).thenReturn(taskConfig);
PluggableTaskConfigStore.store().setPreferenceFor(pluginId, preference);
}
use of com.thoughtworks.go.plugin.api.task.TaskConfig 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.task.TaskConfig in project gocd by gocd.
the class MagicalGoConfigXmlLoaderTest method shouldBeAbleToResolveSecureConfigPropertiesForPluggableTasks.
@Test
public void shouldBeAbleToResolveSecureConfigPropertiesForPluggableTasks() throws Exception {
String encryptedValue = new GoCipher().encrypt("password");
String configString = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + " <pipelines>" + "<pipeline name='pipeline1'>" + " <materials>" + " <svn url='svnurl' username='admin' password='%s'/>" + " </materials>" + " <stage name='mingle'>" + " <jobs>" + " <job name='do-something'><tasks>" + " <task>" + " <pluginConfiguration id='plugin-id-1' version='1.0'/>" + " <configuration>" + " <property><key>username</key><value>godev</value></property>" + " <property><key>password</key><value>password</value></property>" + " </configuration>" + " </task> </tasks>" + " </job>" + " </jobs>" + " </stage>" + "</pipeline></pipelines>" + "</cruise>";
//meta data of package
PluggableTaskConfigStore.store().setPreferenceFor("plugin-id-1", new TaskPreference(new com.thoughtworks.go.plugin.api.task.Task() {
@Override
public TaskConfig config() {
TaskConfig taskConfig = new TaskConfig();
taskConfig.addProperty("username").with(Property.SECURE, false);
taskConfig.addProperty("password").with(Property.SECURE, true);
return taskConfig;
}
@Override
public TaskExecutor executor() {
return null;
}
@Override
public TaskView view() {
return null;
}
@Override
public ValidationResult validate(TaskConfig configuration) {
return null;
}
}));
GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(configString);
PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("pipeline1"));
PluggableTask task = (PluggableTask) pipelineConfig.getStage("mingle").getJobs().getJob(new CaseInsensitiveString("do-something")).getTasks().first();
assertFalse(task.getConfiguration().getProperty("username").isSecure());
assertTrue(task.getConfiguration().getProperty("password").isSecure());
}
Aggregations