use of com.thoughtworks.go.plugin.api.task.TaskView 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.plugin.api.task.TaskView in project gocd by gocd.
the class ConfigElementImplementationRegistrarTest method shouldRegisterViewEngineForPluggableTask.
@Test
public void shouldRegisterViewEngineForPluggableTask() {
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.api.task.TaskView in project gocd by gocd.
the class PluggableTaskPluginInfoBuilder method pluginInfoFor.
@Override
public PluggableTaskPluginInfo pluginInfoFor(GoPluginDescriptor descriptor) {
final TaskPreference[] tp = { null };
extension.doOnTask(descriptor.id(), (task, 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.TaskView 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);
}
Aggregations