Search in sources :

Example 11 with TaskView

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");
}
Also used : TaskView(com.thoughtworks.go.plugin.api.task.TaskView) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask)

Example 12 with TaskView

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));
}
Also used : TaskView(com.thoughtworks.go.plugin.api.task.TaskView) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.jupiter.api.Test)

Example 13 with TaskView

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);
}
Also used : TaskView(com.thoughtworks.go.plugin.api.task.TaskView) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) PluginView(com.thoughtworks.go.plugin.domain.common.PluginView) PluggableTaskPluginInfo(com.thoughtworks.go.plugin.domain.pluggabletask.PluggableTaskPluginInfo) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig)

Example 14 with TaskView

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);
}
Also used : PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) Task(com.thoughtworks.go.plugin.api.task.Task) TaskView(com.thoughtworks.go.plugin.api.task.TaskView) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) 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