use of com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference 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.access.pluggabletask.TaskPreference 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.access.pluggabletask.TaskPreference in project gocd by gocd.
the class ConfigElementImplementationRegistrarTest method shouldRegisterViewEngineForPluggableTask.
@Test
public void shouldRegisterViewEngineForPluggableTask() throws Exception {
TaskPreference taskPreference = mock(TaskPreference.class);
TaskView view = mock(TaskView.class);
when(taskPreference.getView()).thenReturn(view);
when(view.template()).thenReturn("plugin-template-value");
when(view.displayValue()).thenReturn("Plugin display value");
PluggableTaskConfigStore.store().setPreferenceFor("plugin1", taskPreference);
PluggableTask pluggableTask = new PluggableTask(new PluginConfiguration("plugin1", "2"), new Configuration());
PluggableViewModel<PluggableTask> pluggableTaskViewModel = registry.getViewModelFor(pluggableTask, "new");
assertEquals(PluggableTaskViewModel.class, pluggableTaskViewModel.getClass());
assertThat(pluggableTaskViewModel.getModel(), is(pluggableTask));
}
use of com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference 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.access.pluggabletask.TaskPreference 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