Search in sources :

Example 36 with PluginConfiguration

use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.

the class SCMTest method shouldAddPropertyComingFromAttributesMapIfPresentInConfigStoreEvenIfItISNotPresentInCurrentConfiguration.

@Test
public void shouldAddPropertyComingFromAttributesMapIfPresentInConfigStoreEvenIfItISNotPresentInCurrentConfiguration() throws Exception {
    SCMConfigurations scmConfigurations = new SCMConfigurations();
    scmConfigurations.add(new SCMConfiguration("KEY1"));
    scmConfigurations.add(new SCMConfiguration("Key2"));
    SCMPreference scmPreference = mock(SCMPreference.class);
    when(scmPreference.getScmConfigurations()).thenReturn(scmConfigurations);
    SCMMetadataStore.getInstance().setPreferenceFor("plugin-id", scmPreference);
    Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
    SCM scm = new SCM("scm-id", new PluginConfiguration("plugin-id", "1"), configuration);
    Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1", "Key2", "value2");
    scm.setConfigAttributes(attributeMap);
    assertThat(scm.getConfigAsMap().get("KEY1").get(SCM.VALUE_KEY), is("value1"));
    assertThat(scm.getConfigAsMap().get("Key2").get(SCM.VALUE_KEY), is("value2"));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) SCMPreference(com.thoughtworks.go.plugin.access.scm.SCMPreference) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfigurations(com.thoughtworks.go.plugin.access.scm.SCMConfigurations) Test(org.junit.Test)

Example 37 with PluginConfiguration

use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.

the class SCMTest method shouldSetConfigAttributesAsAvailable.

@Test
public void shouldSetConfigAttributesAsAvailable() throws Exception {
    SCMConfigurations scmConfigurations = new SCMConfigurations();
    scmConfigurations.add(new SCMConfiguration("url"));
    scmConfigurations.add(new SCMConfiguration("username"));
    scmConfigurations.add(new SCMConfiguration("password").with(SECURE, true));
    SCMMetadataStore.getInstance().addMetadataFor("plugin-id", scmConfigurations, null);
    Map<String, String> attributeMap = DataStructureUtils.m(SCM.SCM_ID, "scm-id", SCM.NAME, "scm-name", SCM.AUTO_UPDATE, "false", "url", "http://localhost", "username", "user", "password", "pass");
    SCM scm = new SCM(null, new PluginConfiguration("plugin-id", "1"), new Configuration());
    scm.setConfigAttributes(attributeMap);
    assertThat(scm.getId(), is("scm-id"));
    assertThat(scm.getName(), is("scm-name"));
    assertThat(scm.isAutoUpdate(), is(false));
    assertThat(scm.getPluginConfiguration().getId(), is("plugin-id"));
    assertThat(scm.getConfigAsMap().get("url").get(SCM.VALUE_KEY), is("http://localhost"));
    assertThat(scm.getConfigAsMap().get("username").get(SCM.VALUE_KEY), is("user"));
    assertThat(scm.getConfigAsMap().get("password").get(SCM.VALUE_KEY), is("pass"));
    assertThat(scm.getConfiguration().getProperty("password").getConfigurationValue(), is(nullValue()));
    assertThat(scm.getConfiguration().getProperty("password").getEncryptedConfigurationValue(), is(not(nullValue())));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfigurations(com.thoughtworks.go.plugin.access.scm.SCMConfigurations) Test(org.junit.Test)

Example 38 with PluginConfiguration

use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.

the class SCMTest method shouldThrowUpOnSetConfigAttributesIfPluginIsNotAvailable.

@Test
public void shouldThrowUpOnSetConfigAttributesIfPluginIsNotAvailable() throws Exception {
    try {
        Map<String, String> attributeMap = DataStructureUtils.m(SCM.SCM_ID, "scm-id", SCM.NAME, "scm-name", SCM.AUTO_UPDATE, "false", "url", "http://localhost");
        SCM scm = new SCM(null, new PluginConfiguration("plugin-id", "1"), new Configuration());
        scm.setConfigAttributes(attributeMap);
        fail("should have thrown exception");
    } catch (Exception e) {
        assertThat(e, instanceOf(RuntimeException.class));
        assertThat(e.getMessage(), is("metadata unavailable for plugin: plugin-id"));
    }
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Test(org.junit.Test)

Example 39 with PluginConfiguration

use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.

the class TaskViewService method allPluginTasks.

private List<PluggableTask> allPluginTasks() {
    final ArrayList<PluggableTask> tasks = new ArrayList<>();
    for (final String pluginId : PluggableTaskConfigStore.store().pluginIds()) {
        GoPluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptorFor(pluginId);
        TaskPreference taskPreference = PluggableTaskConfigStore.store().preferenceFor(pluginId);
        if (pluginDescriptor != null && taskPreference != null) {
            tasks.add(new PluggableTask(new PluginConfiguration(pluginId, pluginDescriptor.version()), getConfiguration(taskPreference.getConfig())));
        }
    }
    return tasks;
}
Also used : ArrayList(java.util.ArrayList) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)

Example 40 with PluginConfiguration

use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.

the class PluggableTaskBuilderTest method shouldPublishErrorMessageIfPluginThrowsAnException.

@Test
public void shouldPublishErrorMessageIfPluginThrowsAnException() throws CruiseControlException {
    PluggableTask task = mock(PluggableTask.class);
    when(task.getPluginConfiguration()).thenReturn(new PluginConfiguration());
    PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, pluggableTask, TEST_PLUGIN_ID, "test-directory") {

        @Override
        protected ExecutionResult executeTask(Task task, DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext, String consoleLogCharset) {
            throw new RuntimeException("err");
        }
    };
    try {
        taskBuilder.build(goPublisher, variableContext, taskExtension, null, null, "utf-8");
        fail("expected exception to be thrown");
    } catch (Exception e) {
        ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
        verify(goPublisher).taggedConsumeLine(eq(DefaultGoPublisher.ERR), captor.capture());
        String error = "Error: err";
        assertThat(captor.getValue(), is(error));
        assertThat(e.getMessage(), is(new RuntimeException("err").toString()));
    }
}
Also used : PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) ArgumentCaptor(org.mockito.ArgumentCaptor) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) CruiseControlException(com.thoughtworks.go.util.command.CruiseControlException) Test(org.junit.Test)

Aggregations

PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)83 Test (org.junit.Test)72 Configuration (com.thoughtworks.go.domain.config.Configuration)61 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)28 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)18 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)18 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)13 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)12 SCM (com.thoughtworks.go.domain.scm.SCM)11 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)10 TaskProperty (com.thoughtworks.go.domain.TaskProperty)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)8 Map (java.util.Map)8 SCMConfiguration (com.thoughtworks.go.plugin.access.scm.SCMConfiguration)7 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)6 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)5 SCMConfigurations (com.thoughtworks.go.plugin.access.scm.SCMConfigurations)5 HashMap (java.util.HashMap)5 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)4 SCMPreference (com.thoughtworks.go.plugin.access.scm.SCMPreference)4