Search in sources :

Example 1 with Task

use of com.thoughtworks.go.plugin.api.task.Task in project gocd by gocd.

the class PluggableTaskTest method shouldPopulatePropertiesForDisplayRetainingOrderAndDisplayNameIfConfigured.

@Test
public void shouldPopulatePropertiesForDisplayRetainingOrderAndDisplayNameIfConfigured() throws Exception {
    Task taskDetails = mock(Task.class);
    TaskConfig taskConfig = new TaskConfig();
    addProperty(taskConfig, "KEY2", "Key 2", 1);
    addProperty(taskConfig, "KEY1", "Key 1", 0);
    addProperty(taskConfig, "KEY3", "Key 3", 2);
    when(taskDetails.config()).thenReturn(taskConfig);
    when(taskDetails.view()).thenReturn(mock(TaskView.class));
    String pluginId = "plugin_with_all_details";
    PluggableTaskConfigStore.store().setPreferenceFor(pluginId, new TaskPreference(taskDetails));
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY3", true, "encryptedValue1"), ConfigurationPropertyMother.create("KEY1", false, "value1"), ConfigurationPropertyMother.create("KEY2", false, "value2"));
    PluggableTask task = new PluggableTask(new PluginConfiguration(pluginId, "1"), configuration);
    List<TaskProperty> propertiesForDisplay = task.getPropertiesForDisplay();
    assertThat(propertiesForDisplay.size(), is(3));
    assertProperty(propertiesForDisplay.get(0), "Key 1", "value1", "key1");
    assertProperty(propertiesForDisplay.get(1), "Key 2", "value2", "key2");
    assertProperty(propertiesForDisplay.get(2), "Key 3", "****", "key3");
}
Also used : Task(com.thoughtworks.go.plugin.api.task.Task) AntTask(com.thoughtworks.go.config.AntTask) TaskView(com.thoughtworks.go.plugin.api.task.TaskView) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskProperty(com.thoughtworks.go.domain.TaskProperty) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 2 with Task

use of com.thoughtworks.go.plugin.api.task.Task in project gocd by gocd.

the class PluggableTaskTest method shouldGetOnlyConfiguredPropertiesIfACertainPropertyDefinedByPluginIsNotConfiguredByUser.

@Test
public void shouldGetOnlyConfiguredPropertiesIfACertainPropertyDefinedByPluginIsNotConfiguredByUser() throws Exception {
    Task taskDetails = mock(Task.class);
    TaskConfig taskConfig = new TaskConfig();
    addProperty(taskConfig, "KEY2", "Key 2", 1);
    addProperty(taskConfig, "KEY1", "Key 1", 0);
    addProperty(taskConfig, "KEY3", "Key 3", 2);
    when(taskDetails.config()).thenReturn(taskConfig);
    when(taskDetails.view()).thenReturn(mock(TaskView.class));
    String pluginId = "plugin_with_all_details";
    PluggableTaskConfigStore.store().setPreferenceFor(pluginId, new TaskPreference(taskDetails));
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1", false, "value1"), ConfigurationPropertyMother.create("KEY2", false, "value2"));
    PluggableTask task = new PluggableTask(new PluginConfiguration(pluginId, "1"), configuration);
    List<TaskProperty> propertiesForDisplay = task.getPropertiesForDisplay();
    assertThat(propertiesForDisplay.size(), is(2));
    assertProperty(propertiesForDisplay.get(0), "Key 1", "value1", "key1");
    assertProperty(propertiesForDisplay.get(1), "Key 2", "value2", "key2");
}
Also used : Task(com.thoughtworks.go.plugin.api.task.Task) AntTask(com.thoughtworks.go.config.AntTask) TaskView(com.thoughtworks.go.plugin.api.task.TaskView) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskProperty(com.thoughtworks.go.domain.TaskProperty) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 3 with Task

use of com.thoughtworks.go.plugin.api.task.Task 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 4 with Task

use of com.thoughtworks.go.plugin.api.task.Task 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 5 with Task

use of com.thoughtworks.go.plugin.api.task.Task 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.Test)

Aggregations

Task (com.thoughtworks.go.plugin.api.task.Task)6 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)6 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)6 Test (org.junit.Test)6 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)3 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)3 AntTask (com.thoughtworks.go.config.AntTask)2 TaskProperty (com.thoughtworks.go.domain.TaskProperty)2 Configuration (com.thoughtworks.go.domain.config.Configuration)2 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)2 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)2 Action (com.thoughtworks.go.plugin.infra.Action)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2