use of com.thoughtworks.go.plugin.api.task.TaskView 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.TaskView in project gocd by gocd.
the class PluggableTaskViewModelFactoryTest method setUp.
@BeforeEach
public void setUp() throws Exception {
cleanupTaskPreferences();
taskPreference = mock(TaskPreference.class);
PluggableTaskConfigStore.store().setPreferenceFor("plugin-1", taskPreference);
TaskView view = mock(TaskView.class);
when(taskPreference.getView()).thenReturn(view);
when(view.template()).thenReturn("<input type='text' ng-model='abc'></input>");
when(view.displayValue()).thenReturn("First plugin");
}
use of com.thoughtworks.go.plugin.api.task.TaskView in project gocd by gocd.
the class TaskPreferenceTest method shouldTestEquals.
@Test
public void shouldTestEquals() throws Exception {
Task task1 = mock(Task.class);
TaskConfig config1 = new TaskConfig();
TaskView taskView1 = mock(TaskView.class);
when(task1.config()).thenReturn(config1);
when(task1.view()).thenReturn(taskView1);
TaskPreference taskPreference1 = new TaskPreference(task1);
Task task2 = mock(Task.class);
TaskConfig config2 = new TaskConfig();
TaskView taskView2 = mock(TaskView.class);
when(task2.config()).thenReturn(config2);
when(task2.view()).thenReturn(taskView2);
TaskPreference taskPreference2 = new TaskPreference(task2);
TaskPreference taskPreference3 = new TaskPreference(task1);
Task task3 = mock(Task.class);
when(task3.config()).thenReturn(config1);
when(task3.view()).thenReturn(taskView1);
TaskPreference taskPreference4 = new TaskPreference(task3);
Task task5 = mock(Task.class);
TaskView taskView5 = mock(TaskView.class);
when(task5.config()).thenReturn(config1);
when(task5.view()).thenReturn(taskView5);
TaskPreference taskPreference5 = new TaskPreference(task5);
assertThat(taskPreference1.equals(taskPreference2), is(false));
assertThat(taskPreference1.equals(taskPreference3), is(true));
assertThat(taskPreference1.equals(taskPreference4), is(true));
assertThat(taskPreference1.equals(taskPreference5), is(false));
}
use of com.thoughtworks.go.plugin.api.task.TaskView in project gocd by gocd.
the class JsonBasedPluggableTaskTest method shouldGetTaskView.
@Test
public void shouldGetTaskView() {
String jsonResponse = "{\"displayValue\":\"MyTaskPlugin\", \"template\":\"<html>junk</html>\"}";
when(goPluginApiResponse.responseBody()).thenReturn(jsonResponse);
TaskView view = task.view();
assertThat(view.displayValue(), is("MyTaskPlugin"));
assertThat(view.template(), is("<html>junk</html>"));
ArgumentCaptor<GoPluginApiRequest> argument = ArgumentCaptor.forClass(GoPluginApiRequest.class);
verify(pluginManager).submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), argument.capture());
MatcherAssert.assertThat(argument.getValue().extension(), Matchers.is(PLUGGABLE_TASK_EXTENSION));
MatcherAssert.assertThat(argument.getValue().extensionVersion(), Matchers.is(JsonBasedTaskExtensionHandler_V1.VERSION));
MatcherAssert.assertThat(argument.getValue().requestName(), Matchers.is(TaskExtension.TASK_VIEW_REQUEST));
}
use of com.thoughtworks.go.plugin.api.task.TaskView in project gocd by gocd.
the class PluggableTaskPreferenceLoaderTest method shouldSetConfigForTheTaskCorrespondingToGivenPluginId.
@Test
public void shouldSetConfigForTheTaskCorrespondingToGivenPluginId() 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);
PluginManager pluginManager = mock(PluginManager.class);
final TaskExtension taskExtension = mock(TaskExtension.class);
when(taskExtension.canHandlePlugin(pluginId)).thenReturn(true);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
final Action<Task> action = (Action<Task>) invocationOnMock.getArguments()[1];
action.execute(task, descriptor);
return null;
}
}).when(taskExtension).doOnTask(eq(pluginId), any(Action.class));
PluggableTaskPreferenceLoader pluggableTaskPreferenceLoader = new PluggableTaskPreferenceLoader(pluginManager, taskExtension);
pluggableTaskPreferenceLoader.pluginLoaded(descriptor);
assertThat(PluggableTaskConfigStore.store().hasPreferenceFor(pluginId), is(true));
assertThat(PluggableTaskConfigStore.store().preferenceFor(pluginId), is(new TaskPreference(task)));
verify(pluginManager).addPluginChangeListener(pluggableTaskPreferenceLoader);
}
Aggregations