use of com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension in project gocd by gocd.
the class PluginServiceTest method shouldNotSavePluginSettingsIfPluginDoesNotExist.
@Test
public void shouldNotSavePluginSettingsIfPluginDoesNotExist() {
PluginSettings pluginSettings = new PluginSettings("non-existent-plugin");
Username currentUser = new Username("admin");
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
when(securityService.isUserAdmin(currentUser)).thenReturn(true);
for (GoPluginExtension extension : extensions) {
when(extension.canHandlePlugin("non-existent-plugin")).thenReturn(false);
}
pluginService.savePluginSettings(currentUser, result, pluginSettings);
assertThat(result.httpCode(), is(422));
assertThat(result.toString(), containsString("Plugin 'non-existent-plugin' does not exist or does not implement settings validation"));
}
use of com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension in project gocd by gocd.
the class PluginService method validatePluginSettingsFor.
public void validatePluginSettingsFor(PluginSettings pluginSettings) {
String pluginId = pluginSettings.getPluginId();
PluginSettingsConfiguration configuration = pluginSettings.toPluginSettingsConfiguration();
GoPluginExtension extension = findExtensionWhichCanHandleSettingsFor(pluginId);
if (extension == null)
throw new IllegalArgumentException(String.format("Plugin '%s' does not exist or does not implement settings validation.", pluginId));
ValidationResult result = extension.validatePluginSettings(pluginId, configuration);
if (!result.isSuccessful()) {
for (ValidationError error : result.getErrors()) {
pluginSettings.populateErrorMessageFor(error.getKey(), error.getMessage());
}
}
}
use of com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension in project gocd by gocd.
the class PluginService method validatePluginSettings.
void validatePluginSettings(PluginSettings pluginSettings) {
pluginSettings.validateTree();
if (pluginSettings.hasErrors()) {
return;
}
final String pluginId = pluginSettings.getPluginId();
final PluginSettingsConfiguration configuration = pluginSettings.toPluginSettingsConfiguration();
final GoPluginExtension extension = findExtensionWhichCanHandleSettingsFor(pluginId);
if (extension == null) {
throw new IllegalArgumentException(String.format("Plugin '%s' does not exist or does not implement settings validation.", pluginId));
}
final ValidationResult result = extension.validatePluginSettings(pluginId, configuration);
if (!result.isSuccessful()) {
for (ValidationError error : result.getErrors()) {
pluginSettings.populateErrorMessageFor(error.getKey(), error.getMessage());
}
}
}
use of com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension in project gocd by gocd.
the class PluginServiceTest method shouldCallValidationOnPlugin.
@Test
public void shouldCallValidationOnPlugin() throws Exception {
for (GoPluginExtension extension : extensions) {
String pluginId = UUID.randomUUID().toString();
PluginSettingsMetadataStore.getInstance().addMetadataFor(pluginId, extension.extensionName(), null, null);
when(extension.canHandlePlugin(pluginId)).thenReturn(true);
when(extension.validatePluginSettings(eq(pluginId), any(PluginSettingsConfiguration.class))).thenReturn(new ValidationResult());
PluginSettings pluginSettings = new PluginSettings(pluginId);
pluginService.validatePluginSettingsFor(pluginSettings);
verify(extension).validatePluginSettings(eq(pluginId), any(PluginSettingsConfiguration.class));
}
}
use of com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension in project gocd by gocd.
the class PluginSettingsRequestProcessorTest method shouldRouteToTheRightExtensionBasedOnTheRequest_WhenAPluginHasMultipleExtensions.
@Test
public void shouldRouteToTheRightExtensionBasedOnTheRequest_WhenAPluginHasMultipleExtensions() throws Exception {
GoPluginExtension anotherPluginExtension = mock(GoPluginExtension.class);
String pluginId = "plugin-foo-id";
Map<String, String> pluginSettings = m("k1", "v1", "k2", "v2");
when(pluginDescriptor.id()).thenReturn(pluginId);
when(pluginSqlMapDao.findPlugin(pluginId)).thenReturn(new Plugin(pluginId, "{\"k1\": \"v1\",\"k2\": \"v2\"}"));
processor = new PluginSettingsRequestProcessor(applicationAccessor, pluginSqlMapDao, Arrays.asList(pluginExtension, anotherPluginExtension));
DefaultGoApiRequest requestForExtension1 = new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "1.0", new GoPluginIdentifier("extension1", singletonList("1.0")));
setupExpectationsFor(pluginExtension, pluginId, "extension1");
setupExpectationsFor(anotherPluginExtension, pluginId, "extension2");
processor.process(pluginDescriptor, requestForExtension1);
verify(pluginExtension).pluginSettingsJSON(eq(pluginId), anyMapOf(String.class, String.class));
verify(anotherPluginExtension, never()).pluginSettingsJSON(eq(pluginId), anyMapOf(String.class, String.class));
Mockito.reset(pluginExtension, anotherPluginExtension);
DefaultGoApiRequest requestForExtension2 = new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "1.0", new GoPluginIdentifier("extension2", singletonList("1.0")));
setupExpectationsFor(pluginExtension, pluginId, "extension1");
setupExpectationsFor(anotherPluginExtension, pluginId, "extension2");
processor.process(pluginDescriptor, requestForExtension2);
verify(pluginExtension, never()).pluginSettingsJSON(eq(pluginId), anyMapOf(String.class, String.class));
verify(anotherPluginExtension).pluginSettingsJSON(eq(pluginId), anyMapOf(String.class, String.class));
Mockito.reset(pluginExtension, anotherPluginExtension);
}
Aggregations