use of com.thoughtworks.go.domain.Plugin in project gocd by gocd.
the class PluginSettingsTest method shouldPopulateSettingsMapFromPluginFromDB.
@Test
public void shouldPopulateSettingsMapFromPluginFromDB() {
Map<String, String> configuration = new HashMap<>();
configuration.put("k1", "v1");
configuration.put("k2", "");
configuration.put("k3", null);
Plugin plugin = new Plugin(PLUGIN_ID, toJSON(configuration));
PluginSettings pluginSettings = new PluginSettings(PLUGIN_ID);
pluginSettings.populateSettingsMap(plugin);
assertThat(pluginSettings.getPluginSettingsKeys().size(), is(3));
assertThat(pluginSettings.getValueFor("k1"), is("v1"));
assertThat(pluginSettings.getValueFor("k2"), is(""));
assertThat(pluginSettings.getValueFor("k3"), is(nullValue()));
}
use of com.thoughtworks.go.domain.Plugin in project gocd by gocd.
the class PluginSettingsRequestProcessorTest method shouldAccept2_0AsAnAPIVersion.
@Test
public void shouldAccept2_0AsAnAPIVersion() {
when(pluginDescriptor.id()).thenReturn("plugin-foo-id");
when(pluginSqlMapDao.findPlugin("plugin-foo-id")).thenReturn(new Plugin("plugin-foo-id", "{\"k1\": \"v1\",\"k2\": \"v2\"}"));
GoApiResponse response = processor.process(pluginDescriptor, new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "2.0", null));
assertThat(response.responseCode(), is(200));
}
use of com.thoughtworks.go.domain.Plugin in project gocd by gocd.
the class PluginSettingsRequestProcessorTest method shouldGetPluginSettingsForPluginThatExistsInDB.
@Test
public void shouldGetPluginSettingsForPluginThatExistsInDB() {
when(pluginDescriptor.id()).thenReturn("plugin-foo-id");
when(pluginSqlMapDao.findPlugin("plugin-foo-id")).thenReturn(new Plugin("plugin-foo-id", "{\"k1\": \"v1\",\"k2\": \"v2\"}"));
String requestBody = "expected-request";
String responseBody = "expected-response";
when(jsonMessageHandler.responseMessagePluginSettingsGet(requestArgumentCaptor.capture())).thenReturn(responseBody);
DefaultGoApiRequest apiRequest = new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "1.0", null);
apiRequest.setRequestBody(requestBody);
GoApiResponse response = processor.process(pluginDescriptor, apiRequest);
assertThat(response.responseCode(), is(200));
assertThat(response.responseBody(), is(responseBody));
Map<String, String> settingsMap = new HashMap<>();
settingsMap.put("k1", "v1");
settingsMap.put("k2", "v2");
assertEquals(requestArgumentCaptor.getValue().getSettingsAsKeyValuePair(), settingsMap);
}
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());
requestArgumentCaptor = ArgumentCaptor.forClass(PluginSettings.class);
processor = new PluginSettingsRequestProcessor(applicationAccessor, pluginSqlMapDao);
processor.getMessageHandlerMap().put("1.0", jsonMessageHandler);
}
use of com.thoughtworks.go.domain.Plugin in project gocd by gocd.
the class PluginServiceTest method setUp.
@Before
public void setUp() {
initMocks(this);
PluginSettingsMetadataStore.getInstance().clear();
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", 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", configuration2, "template-2");
extensions = Arrays.asList(packageRepositoryExtension, scmExtension, taskExtension, notificationExtension, configRepoExtension, authenticationExtension);
pluginService = new PluginService(extensions, pluginDao, builder);
}
Aggregations