use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class MissingPluggableTaskViewModelTest method shouldReturnPluginIdAsDisplayValue.
@Test
public void shouldReturnPluginIdAsDisplayValue() throws Exception {
PluginConfiguration pluginConfiguration = new PluginConfiguration("test-plugin-1", "1.0");
PluggableTask pluggableTask = new PluggableTask(pluginConfiguration, new Configuration());
MissingPluggableTaskViewModel viewModel = new MissingPluggableTaskViewModel(pluggableTask, null);
assertThat(viewModel.getParameters().get("template"), is(String.format("Associated plugin '%s' not found. Please contact the Go admin to install the plugin.", pluginConfiguration.getId())));
assertThat(viewModel.getTypeForDisplay(), is(pluginConfiguration.getId()));
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PluggableTaskViewModelFactoryTest method assertPluggableViewModel.
private void assertPluggableViewModel(String actionName, String expectedTemplatePath) {
PluggableTask pluggableTask = new PluggableTask(new PluginConfiguration("plugin-1", "2"), new Configuration());
PluggableTaskViewModelFactory factory = new PluggableTaskViewModelFactory();
PluggableViewModel<PluggableTask> viewModel = factory.viewModelFor(pluggableTask, actionName);
assertThat(viewModel.getModel(), is(pluggableTask));
assertThat(viewModel.getTaskType(), is("pluggable_task_plugin_1"));
assertThat(viewModel.getTemplatePath(), is(expectedTemplatePath));
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PluggableTaskViewModelFactoryTest method getModelWithTaskTemplateHavingValue.
private PluggableViewModel<PluggableTask> getModelWithTaskTemplateHavingValue(final String templateContentValue) {
when(taskPreference.getView()).thenReturn(new TaskView() {
@Override
public String displayValue() {
return "view";
}
@Override
public String template() {
return templateContentValue;
}
});
PluggableTask pluggableTask = new PluggableTask(new PluginConfiguration("plugin-1", "2"), new Configuration());
PluggableTaskViewModelFactory factory = new PluggableTaskViewModelFactory();
return factory.viewModelFor(pluggableTask, "new");
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class PluggableTaskViewModelFactoryTest method dataForViewShouldBeGotFromTheTaskInJSONFormat.
@Test
public void dataForViewShouldBeGotFromTheTaskInJSONFormat() throws Exception {
Configuration configuration = new Configuration(create("key1", false, "value1"), create("KEY2", false, "value2"));
PluggableTask taskConfig = new PluggableTask(new PluginConfiguration("plugin-1", "2"), configuration);
PluggableTaskViewModelFactory factory = new PluggableTaskViewModelFactory();
PluggableViewModel<PluggableTask> viewModel = factory.viewModelFor(taskConfig, "new");
String actualData = (String) viewModel.getParameters().get("data");
Gson gson = new Gson();
Map actual = gson.fromJson(actualData, Map.class);
Map expected = gson.fromJson("{\"KEY2\":{\"value\":\"value2\"},\"key1\":{\"value\":\"value1\"}}", Map.class);
assertEquals(expected, actual);
}
use of com.thoughtworks.go.config.pluggabletask.PluggableTask in project gocd by gocd.
the class MagicalGoConfigXmlLoaderTest method shouldAllowPluggableTaskConfiguration.
@Test
public void shouldAllowPluggableTaskConfiguration() throws Exception {
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>url</key><value>http://fake-go-server</value></property>" + " <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>";
CruiseConfig cruiseConfig = ConfigMigrator.loadWithMigration(configString).configForEdit;
PipelineConfig pipelineConfig = cruiseConfig.getAllPipelineConfigs().get(0);
JobConfig jobConfig = pipelineConfig.getFirstStageConfig().getJobs().get(0);
Tasks tasks = jobConfig.getTasks();
assertThat(tasks.size(), is(1));
assertThat(tasks.get(0) instanceof PluggableTask, is(true));
PluggableTask task = (PluggableTask) tasks.get(0);
assertThat(task.getTaskType(), is("pluggable_task_plugin_id_1"));
assertThat(task.getTypeForDisplay(), is("Pluggable Task"));
final Configuration configuration = task.getConfiguration();
assertThat(configuration.listOfConfigKeys().size(), is(3));
assertThat(configuration.listOfConfigKeys(), is(asList("url", "username", "password")));
Collection values = CollectionUtils.collect(configuration.listOfConfigKeys(), new Transformer() {
@Override
public Object transform(Object o) {
ConfigurationProperty property = configuration.getProperty((String) o);
return property.getConfigurationValue().getValue();
}
});
assertThat(new ArrayList<>(values), is(asList("http://fake-go-server", "godev", "password")));
}
Aggregations