use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.
the class PluggableTaskPluginInfoBuilderTest method setUp.
@Before
public void setUp() throws Exception {
extension = mock(TaskExtension.class);
TaskConfig taskConfig = new TaskConfig();
taskConfig.add(new TaskConfigProperty("username", null).with(Property.REQUIRED, true).with(Property.SECURE, false));
taskConfig.add(new TaskConfigProperty("password", null).with(Property.REQUIRED, true).with(Property.SECURE, true));
TaskView taskView = new TaskView() {
@Override
public String displayValue() {
return "my task plugin";
}
@Override
public String template() {
return "some html";
}
};
final Task task = mock(Task.class);
when(task.config()).thenReturn(taskConfig);
when(task.view()).thenReturn(taskView);
final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
String pluginId = "plugin1";
when(descriptor.id()).thenReturn(pluginId);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
final Action<Task> action = (Action<Task>) invocation.getArguments()[1];
action.execute(task, descriptor);
return null;
}
}).when(extension).doOnTask(eq("plugin1"), any(Action.class));
}
use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.
the class PluggableTaskPreferenceLoaderTest method shouldRemoveConfigForTheTaskCorrespondingToGivenPluginId.
@Test
public void shouldRemoveConfigForTheTaskCorrespondingToGivenPluginId() throws Exception {
final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
String pluginId = "test-plugin-id";
when(descriptor.id()).thenReturn(pluginId);
final Task task = mock(Task.class);
TaskConfig config = new TaskConfig();
TaskView taskView = mock(TaskView.class);
when(task.config()).thenReturn(config);
when(task.view()).thenReturn(taskView);
PluggableTaskConfigStore.store().setPreferenceFor(pluginId, new TaskPreference(task));
PluginManager pluginManager = mock(PluginManager.class);
PluggableTaskPreferenceLoader pluggableTaskPreferenceLoader = new PluggableTaskPreferenceLoader(pluginManager, taskExtension);
assertThat(PluggableTaskConfigStore.store().hasPreferenceFor(pluginId), is(true));
pluggableTaskPreferenceLoader.pluginUnLoaded(descriptor);
assertThat(PluggableTaskConfigStore.store().hasPreferenceFor(pluginId), is(false));
verify(pluginManager).addPluginChangeListener(pluggableTaskPreferenceLoader);
}
use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.
the class PluggableTaskPluginInfoBuilder method pluginInfoFor.
public PluggableTaskPluginInfo pluginInfoFor(GoPluginDescriptor descriptor) {
final TaskPreference[] tp = { null };
extension.doOnTask(descriptor.id(), new Action<Task>() {
@Override
public void execute(Task task, GoPluginDescriptor pluginDescriptor) {
tp[0] = new TaskPreference(task);
}
});
TaskConfig config = tp[0].getConfig();
TaskView view = tp[0].getView();
if (config == null) {
throw new RuntimeException(format("Plugin[%s] returned null task configuration", descriptor.id()));
}
if (view == null) {
throw new RuntimeException(format("Plugin[%s] returned null task view", descriptor.id()));
}
String displayName = view.displayValue();
PluggableInstanceSettings taskSettings = new PluggableInstanceSettings(configurations(config), new PluginView(view.template()));
return new PluggableTaskPluginInfo(descriptor, displayName, taskSettings);
}
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