Search in sources :

Example 16 with TaskPreference

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

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

the class PluggableTaskServiceTest method setUp.

@Before
public void setUp() throws Exception {
    taskExtension = mock(TaskExtension.class);
    localizer = mock(Localizer.class);
    pluggableTaskService = new PluggableTaskService(taskExtension, localizer);
    final TaskPreference preference = mock(TaskPreference.class);
    final TaskConfig taskConfig = new TaskConfig();
    final TaskConfigProperty key1 = taskConfig.addProperty("KEY1");
    key1.with(Property.REQUIRED, true);
    taskConfig.addProperty("KEY2");
    when(preference.getConfig()).thenReturn(taskConfig);
    PluggableTaskConfigStore.store().setPreferenceFor(pluginId, preference);
}
Also used : TaskExtension(com.thoughtworks.go.plugin.access.pluggabletask.TaskExtension) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Localizer(com.thoughtworks.go.i18n.Localizer) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Before(org.junit.Before)

Example 18 with TaskPreference

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

the class ConfigElementImplementationRegistrarTest method shouldRegisterViewEngineForPluggableTask.

@Test
public void shouldRegisterViewEngineForPluggableTask() throws Exception {
    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.Test)

Example 19 with TaskPreference

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

the class PluggableTask method getPropertiesForDisplay.

@Override
public List<TaskProperty> getPropertiesForDisplay() {
    ArrayList<TaskProperty> taskProperties = new ArrayList<>();
    if (PluggableTaskConfigStore.store().hasPreferenceFor(pluginConfiguration.getId())) {
        TaskPreference preference = taskPreference();
        List<? extends Property> propertyDefinitions = preference.getConfig().list();
        for (Property propertyDefinition : propertyDefinitions) {
            ConfigurationProperty configuredProperty = configuration.getProperty(propertyDefinition.getKey());
            if (configuredProperty == null)
                continue;
            taskProperties.add(new TaskProperty(propertyDefinition.getOption(Property.DISPLAY_NAME), configuredProperty.getDisplayValue(), configuredProperty.getConfigKeyName()));
        }
        return taskProperties;
    }
    for (ConfigurationProperty property : configuration) {
        taskProperties.add(new TaskProperty(property.getConfigKeyName(), property.getDisplayValue()));
    }
    return taskProperties;
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ArrayList(java.util.ArrayList) TaskProperty(com.thoughtworks.go.domain.TaskProperty) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) TaskProperty(com.thoughtworks.go.domain.TaskProperty) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)

Example 20 with TaskPreference

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

the class MagicalGoConfigXmlLoaderTest method shouldBeAbleToResolveSecureConfigPropertiesForPluggableTasks.

@Test
public void shouldBeAbleToResolveSecureConfigPropertiesForPluggableTasks() throws Exception {
    String encryptedValue = new GoCipher().encrypt("password");
    String configString = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + " <pipelines>" + "<pipeline name='pipeline1'>" + "    <materials>" + "      <svn url='svnurl' username='admin' password='%s'/>" + "    </materials>" + "  <stage name='mingle'>" + "    <jobs>" + "      <job name='do-something'><tasks>" + "        <task>" + "          <pluginConfiguration id='plugin-id-1' version='1.0'/>" + "          <configuration>" + "            <property><key>username</key><value>godev</value></property>" + "            <property><key>password</key><value>password</value></property>" + "          </configuration>" + "        </task> </tasks>" + "      </job>" + "    </jobs>" + "  </stage>" + "</pipeline></pipelines>" + "</cruise>";
    //meta data of package
    PluggableTaskConfigStore.store().setPreferenceFor("plugin-id-1", new TaskPreference(new com.thoughtworks.go.plugin.api.task.Task() {

        @Override
        public TaskConfig config() {
            TaskConfig taskConfig = new TaskConfig();
            taskConfig.addProperty("username").with(Property.SECURE, false);
            taskConfig.addProperty("password").with(Property.SECURE, true);
            return taskConfig;
        }

        @Override
        public TaskExecutor executor() {
            return null;
        }

        @Override
        public TaskView view() {
            return null;
        }

        @Override
        public ValidationResult validate(TaskConfig configuration) {
            return null;
        }
    }));
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(configString);
    PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("pipeline1"));
    PluggableTask task = (PluggableTask) pipelineConfig.getStage("mingle").getJobs().getJob(new CaseInsensitiveString("do-something")).getTasks().first();
    assertFalse(task.getConfiguration().getProperty("username").isSecure());
    assertTrue(task.getConfiguration().getProperty("password").isSecure());
}
Also used : PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) GoCipher(com.thoughtworks.go.security.GoCipher) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) Matchers.containsString(org.hamcrest.Matchers.containsString) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Aggregations

TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)26 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)16 Test (org.junit.Test)14 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)12 Configuration (com.thoughtworks.go.domain.config.Configuration)11 TaskProperty (com.thoughtworks.go.domain.TaskProperty)8 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)8 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)7 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)5 JsonBasedPluggableTask (com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask)4 PluggableInstanceSettings (com.thoughtworks.go.server.ui.plugins.PluggableInstanceSettings)4 PluginView (com.thoughtworks.go.server.ui.plugins.PluginView)4 Before (org.junit.Before)4 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)3 Property (com.thoughtworks.go.plugin.api.config.Property)3 PluggableTaskPluginInfo (com.thoughtworks.go.server.ui.plugins.PluggableTaskPluginInfo)3 ArrayList (java.util.ArrayList)3 AntTask (com.thoughtworks.go.config.AntTask)2 PluggableTaskConfigStore (com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore)2