Search in sources :

Example 1 with Action

use of com.thoughtworks.go.plugin.infra.Action 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));
    when(pluginManager.hasReferenceFor(Task.class, pluginId)).thenReturn(true);
    when(pluginManager.isPluginOfType("task-plugin", pluginId)).thenReturn(false);
    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, Task.class, GoPlugin.class);
}
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.Test)

Example 2 with Action

use of com.thoughtworks.go.plugin.infra.Action in project gocd by gocd.

the class PluggableTaskPreferenceLoaderTest method shouldLoadPreferencesOnlyForTaskPlugins.

@Test
public void shouldLoadPreferencesOnlyForTaskPlugins() {
    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(false);
    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(false));
    verify(pluginManager).addPluginChangeListener(pluggableTaskPreferenceLoader, Task.class, GoPlugin.class);
}
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.Test)

Example 3 with Action

use of com.thoughtworks.go.plugin.infra.Action in project gocd by gocd.

the class TaskExtensionTest method shouldPerformTheActionOnTask.

@Test
public void shouldPerformTheActionOnTask() {
    Action action = mock(Action.class);
    final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
    when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(descriptor);
    extension.doOnTask(pluginId, action);
    verify(action).execute(any(JsonBasedPluggableTask.class), eq(descriptor));
}
Also used : Action(com.thoughtworks.go.plugin.infra.Action) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Aggregations

Action (com.thoughtworks.go.plugin.infra.Action)3 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)3 Test (org.junit.Test)3 Task (com.thoughtworks.go.plugin.api.task.Task)2 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)2 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)2 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2