Search in sources :

Example 16 with Plugin

use of com.thoughtworks.go.domain.Plugin in project gocd by gocd.

the class PluginSqlMapDaoIntegrationTest method shouldReturnCorrectPluginIfPluginIdExists.

@Test
public void shouldReturnCorrectPluginIfPluginIdExists() throws Exception {
    Plugin plugin = savePlugin("plugin-id");
    assertThat(goCache.get(pluginSqlMapDao.cacheKeyForPluginSettings("plugin-id")), is(nullValue()));
    Plugin pluginInDB = pluginSqlMapDao.findPlugin("plugin-id");
    assertThat(pluginInDB, is(plugin));
    assertThat(goCache.get(pluginSqlMapDao.cacheKeyForPluginSettings("plugin-id")), is(pluginInDB));
}
Also used : Plugin(com.thoughtworks.go.domain.Plugin) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Test(org.junit.Test)

Example 17 with Plugin

use of com.thoughtworks.go.domain.Plugin in project gocd by gocd.

the class PluginServiceTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    Map<String, String> configuration = new HashMap<>();
    configuration.put("p1-k1", "v1");
    configuration.put("p1-k2", "");
    configuration.put("p1-k3", null);
    Plugin plugin = new Plugin("plugin-id-1", toJSON(configuration));
    plugin.setId(1L);
    when(pluginDao.findPlugin("plugin-id-1")).thenReturn(plugin);
    when(pluginDao.findPlugin("plugin-id-2")).thenReturn(new NullPlugin());
    PluginSettingsConfiguration configuration1 = new PluginSettingsConfiguration();
    configuration1.add(new PluginSettingsProperty("p1-k1"));
    configuration1.add(new PluginSettingsProperty("p1-k2"));
    configuration1.add(new PluginSettingsProperty("p1-k3"));
    PluginSettingsMetadataStore.getInstance().addMetadataFor("plugin-id-1", PluginConstants.CONFIG_REPO_EXTENSION, configuration1, "template-1");
    PluginSettingsConfiguration configuration2 = new PluginSettingsConfiguration();
    configuration2.add(new PluginSettingsProperty("p2-k1"));
    configuration2.add(new PluginSettingsProperty("p2-k2"));
    configuration2.add(new PluginSettingsProperty("p2-k3"));
    PluginSettingsMetadataStore.getInstance().addMetadataFor("plugin-id-2", PluginConstants.CONFIG_REPO_EXTENSION, configuration2, "template-2");
    when(packageRepositoryExtension.extensionName()).thenReturn(PluginConstants.PACKAGE_MATERIAL_EXTENSION);
    when(scmExtension.extensionName()).thenReturn(PluginConstants.SCM_EXTENSION);
    when(taskExtension.extensionName()).thenReturn(PluginConstants.PLUGGABLE_TASK_EXTENSION);
    when(notificationExtension.extensionName()).thenReturn(PluginConstants.NOTIFICATION_EXTENSION);
    when(configRepoExtension.extensionName()).thenReturn(PluginConstants.CONFIG_REPO_EXTENSION);
    extensions = Arrays.asList(packageRepositoryExtension, scmExtension, taskExtension, notificationExtension, configRepoExtension);
    pluginService = new PluginService(extensions, pluginDao, securityService, entityHashingService, defaultPluginInfoFinder);
}
Also used : NullPlugin(com.thoughtworks.go.domain.NullPlugin) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) PluginSettingsProperty(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsProperty) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) Before(org.junit.Before)

Example 18 with Plugin

use of com.thoughtworks.go.domain.Plugin in project gocd by gocd.

the class PluginServiceTest method shouldNotifyPluginThatPluginSettingsHaveChangedAfterSaving.

@Test
public void shouldNotifyPluginThatPluginSettingsHaveChangedAfterSaving() {
    String pluginId = "plugin-id-2";
    Map<String, String> parameterMap = m("p2-k1", "v1");
    PluginSettings pluginSettings = new PluginSettings(pluginId).populateSettingsMap(parameterMap);
    Username currentUser = new Username("admin");
    when(securityService.isUserAdmin(currentUser)).thenReturn(true);
    when(configRepoExtension.canHandlePlugin(pluginId)).thenReturn(true);
    when(configRepoExtension.validatePluginSettings(eq(pluginId), any(PluginSettingsConfiguration.class))).thenReturn(new ValidationResult());
    pluginService.savePluginSettings(currentUser, new HttpLocalizedOperationResult(), pluginSettings);
    Plugin plugin = new Plugin(pluginId, toJSON(parameterMap));
    verify(pluginDao).saveOrUpdate(plugin);
    verify(configRepoExtension).notifyPluginSettingsChange(pluginId, pluginSettings.getSettingsAsKeyValuePair());
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginSettings(com.thoughtworks.go.server.domain.PluginSettings) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) Test(org.junit.Test)

Example 19 with Plugin

use of com.thoughtworks.go.domain.Plugin in project gocd by gocd.

the class PluginServiceTest method shouldUpdatePluginSettingsToDBIfItExists.

@Test
public void shouldUpdatePluginSettingsToDBIfItExists() {
    Map<String, String> parameterMap = new HashMap<>();
    parameterMap.put("p1-k1", "v1");
    parameterMap.put("p1-k2", "v2");
    parameterMap.put("p1-k3", null);
    PluginSettings pluginSettings = new PluginSettings("plugin-id-1");
    pluginSettings.populateSettingsMap(parameterMap);
    pluginService.savePluginSettingsFor(pluginSettings);
    Plugin plugin = new Plugin("plugin-id-1", toJSON(parameterMap));
    plugin.setId(1L);
    verify(pluginDao).saveOrUpdate(plugin);
}
Also used : PluginSettings(com.thoughtworks.go.server.domain.PluginSettings) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) Test(org.junit.Test)

Example 20 with Plugin

use of com.thoughtworks.go.domain.Plugin in project gocd by gocd.

the class PluginSettingsRequestProcessorTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    Map<String, String> configuration = new HashMap<>();
    configuration.put("k1", "v1");
    configuration.put("k2", "v2");
    when(pluginSqlMapDao.findPlugin("plugin-id-1")).thenReturn(new Plugin("plugin-id-1", JsonHelper.toJsonString(configuration)));
    when(pluginSqlMapDao.findPlugin("plugin-id-2")).thenReturn(new NullPlugin());
    when(pluginExtension.extensionName()).thenReturn("extension1");
    processor = new PluginSettingsRequestProcessor(applicationAccessor, pluginSqlMapDao, singletonList(pluginExtension));
}
Also used : HashMap(java.util.HashMap) NullPlugin(com.thoughtworks.go.domain.NullPlugin) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) Before(org.junit.Before)

Aggregations

Plugin (com.thoughtworks.go.domain.Plugin)23 NullPlugin (com.thoughtworks.go.domain.NullPlugin)22 Test (org.junit.Test)15 PluginSettings (com.thoughtworks.go.server.domain.PluginSettings)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)4 DefaultGoApiRequest (com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest)4 GoPluginIdentifier (com.thoughtworks.go.plugin.api.GoPluginIdentifier)3 GoApiResponse (com.thoughtworks.go.plugin.api.response.GoApiResponse)3 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)3 Username (com.thoughtworks.go.server.domain.Username)3 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)2 GoPluginExtension (com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension)1 PluginSettingsProperty (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsProperty)1 DefaultGoApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse)1 Map (java.util.Map)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallback (org.springframework.transaction.support.TransactionCallback)1