Search in sources :

Example 1 with TaskView

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);
}
Also used : TaskView(com.thoughtworks.go.plugin.api.task.TaskView) JsonBasedPluggableTask(com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask) PluggableTaskPluginInfo(com.thoughtworks.go.server.ui.plugins.PluggableTaskPluginInfo) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) PluggableInstanceSettings(com.thoughtworks.go.server.ui.plugins.PluggableInstanceSettings) PluginView(com.thoughtworks.go.server.ui.plugins.PluginView) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PluggableTaskConfigStore(com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 2 with TaskView

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");
}
Also used : TaskView(com.thoughtworks.go.plugin.api.task.TaskView) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with TaskView

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));
}
Also used : Task(com.thoughtworks.go.plugin.api.task.Task) TaskView(com.thoughtworks.go.plugin.api.task.TaskView) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) Test(org.junit.jupiter.api.Test)

Example 4 with TaskView

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));
}
Also used : TaskView(com.thoughtworks.go.plugin.api.task.TaskView) GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) Test(org.junit.jupiter.api.Test)

Example 5 with TaskView

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);
}
Also used : Task(com.thoughtworks.go.plugin.api.task.Task) TaskView(com.thoughtworks.go.plugin.api.task.TaskView) Action(com.thoughtworks.go.plugin.infra.Action) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

TaskView (com.thoughtworks.go.plugin.api.task.TaskView)14 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)9 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)8 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)6 Test (org.junit.jupiter.api.Test)6 Task (com.thoughtworks.go.plugin.api.task.Task)5 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)5 JsonBasedPluggableTask (com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask)4 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)4 Action (com.thoughtworks.go.plugin.infra.Action)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)2 Configuration (com.thoughtworks.go.domain.config.Configuration)2 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)2 PluggableTaskConfigStore (com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore)2 PluggableInstanceSettings (com.thoughtworks.go.server.ui.plugins.PluggableInstanceSettings)2 PluggableTaskPluginInfo (com.thoughtworks.go.server.ui.plugins.PluggableTaskPluginInfo)2 PluginView (com.thoughtworks.go.server.ui.plugins.PluginView)2 Before (org.junit.Before)2