Search in sources :

Example 1 with PluggableTaskConfigStore

use of com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore in project gocd by gocd.

the class TaskViewServiceTest method shouldNotThrowNullPointerExceptionWhenPluginDescriptorOrTaskPreferenceBecomesNullDueToRaceCondition.

@Test
public void shouldNotThrowNullPointerExceptionWhenPluginDescriptorOrTaskPreferenceBecomesNullDueToRaceCondition() throws Exception {
    PluggableTaskConfigStore pluggableTaskConfigStore = mock(PluggableTaskConfigStore.class);
    Object original = ReflectionUtil.getStaticField(PluggableTaskConfigStore.class, "PLUGGABLE_TASK_CONFIG_STORE");
    try {
        ReflectionUtil.setStaticField(PluggableTaskConfigStore.class, "PLUGGABLE_TASK_CONFIG_STORE", pluggableTaskConfigStore);
        String pluginId = "some.plugin.id";
        when(pluggableTaskConfigStore.pluginIds()).thenReturn(s(pluginId));
        when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(null);
        TaskViewService taskViewService = new TaskViewService(registry, pluginManager);
        taskViewService.getTaskViewModelsWith(mock(Task.class));
    } finally {
        ReflectionUtil.setStaticField(PluggableTaskConfigStore.class, "PLUGGABLE_TASK_CONFIG_STORE", original);
    }
}
Also used : ExecTask(com.thoughtworks.go.config.ExecTask) Task(com.thoughtworks.go.domain.Task) FetchTask(com.thoughtworks.go.config.FetchTask) AntTask(com.thoughtworks.go.config.AntTask) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) PluggableTaskConfigStore(com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore) Test(org.junit.Test)

Example 2 with PluggableTaskConfigStore

use of com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore in project gocd by gocd.

the class PluggableTaskPluginInfoBuilderTest method pluginInfoFor_ShouldReturnNullWhenPluginIsNotFound.

@Test
public void pluginInfoFor_ShouldReturnNullWhenPluginIsNotFound() throws Exception {
    PluginManager pluginManager = mock(PluginManager.class);
    PluggableTaskConfigStore packageMetadataStore = mock(PluggableTaskConfigStore.class);
    PluggableTaskPluginInfoBuilder builder = new PluggableTaskPluginInfoBuilder(pluginManager, packageMetadataStore);
    PluggableTaskPluginInfo pluginInfo = builder.pluginInfoFor("docker-plugin");
    assertEquals(null, pluginInfo);
}
Also used : PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) PluggableTaskPluginInfo(com.thoughtworks.go.server.ui.plugins.PluggableTaskPluginInfo) PluggableTaskConfigStore(com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore) Test(org.junit.Test)

Example 3 with PluggableTaskConfigStore

use of com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore 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 4 with PluggableTaskConfigStore

use of com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore in project gocd by gocd.

the class PluggableTaskPluginInfoBuilderTest method pluginInfoFor_ShouldProvidePluginInfoForAPlugin.

@Test
public void pluginInfoFor_ShouldProvidePluginInfoForAPlugin() 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);
    PluggableTaskPluginInfo pluginInfo = builder.pluginInfoFor(plugin.id());
    PluggableTaskPluginInfo expectedPluginInfo = new PluggableTaskPluginInfo(plugin, taskView.displayValue(), new PluggableInstanceSettings(configurations(taskConfig), new PluginView(taskView.template())));
    assertEquals(expectedPluginInfo, pluginInfo);
}
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)

Aggregations

PluggableTaskConfigStore (com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore)4 Test (org.junit.Test)4 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)3 PluggableTaskPluginInfo (com.thoughtworks.go.server.ui.plugins.PluggableTaskPluginInfo)3 JsonBasedPluggableTask (com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask)2 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)2 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)2 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)2 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)2 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)2 PluggableInstanceSettings (com.thoughtworks.go.server.ui.plugins.PluggableInstanceSettings)2 PluginView (com.thoughtworks.go.server.ui.plugins.PluginView)2 AntTask (com.thoughtworks.go.config.AntTask)1 ExecTask (com.thoughtworks.go.config.ExecTask)1 FetchTask (com.thoughtworks.go.config.FetchTask)1 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)1 Task (com.thoughtworks.go.domain.Task)1