use of com.thoughtworks.go.server.domain.PluginSettings in project gocd by gocd.
the class PluginServiceTest method shouldUpdatePluginSettingsWithErrorsIfExists.
@Test
public void shouldUpdatePluginSettingsWithErrorsIfExists() {
PluginSettingsMetadataStore.getInstance().addMetadataFor("plugin-id-4", PluginConstants.NOTIFICATION_EXTENSION, null, null);
when(notificationExtension.canHandlePlugin("plugin-id-4")).thenReturn(true);
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("p4-k1", "m1"));
validationResult.addError(new ValidationError("p4-k3", "m3"));
when(notificationExtension.validatePluginSettings(eq("plugin-id-4"), any(PluginSettingsConfiguration.class))).thenReturn(validationResult);
Map<String, String> parameterMap = new HashMap<>();
parameterMap.put("p4-k1", "v1");
parameterMap.put("p4-k2", "v2");
parameterMap.put("p4-k3", "v3");
PluginSettings pluginSettings = new PluginSettings("plugin-id-4");
pluginSettings.populateSettingsMap(parameterMap);
pluginService.validatePluginSettingsFor(pluginSettings);
assertThat(pluginSettings.hasErrors(), is(true));
assertThat(pluginSettings.getErrorFor("p4-k1"), is(Arrays.asList("m1")));
assertThat(pluginSettings.getErrorFor("p4-k3"), is(Arrays.asList("m3")));
}
use of com.thoughtworks.go.server.domain.PluginSettings 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.server.domain.PluginSettings in project gocd by gocd.
the class PluginSettingsRequestProcessor method process.
@Override
public GoApiResponse process(GoPluginDescriptor pluginDescriptor, GoApiRequest goPluginApiRequest) {
try {
GoPluginExtension extension = extensionFor(pluginDescriptor.id(), goPluginApiRequest.pluginIdentifier().getExtension());
PluginSettings pluginSettings = pluginSettingsFor(pluginDescriptor.id());
DefaultGoApiResponse response = new DefaultGoApiResponse(200);
response.setResponseBody(extension.pluginSettingsJSON(pluginDescriptor.id(), pluginSettings.getSettingsAsKeyValuePair()));
return response;
} catch (Exception e) {
LOGGER.error(format("Error processing PluginSettings request from plugin: %s.", pluginDescriptor.id()), e);
DefaultGoApiResponse errorResponse = new DefaultGoApiResponse(400);
errorResponse.setResponseBody(format("Error while processing get PluginSettings request - %s", e.getMessage()));
return errorResponse;
}
}
use of com.thoughtworks.go.server.domain.PluginSettings in project gocd by gocd.
the class PluginSettingsRequestProcessor method pluginSettingsFor.
private PluginSettings pluginSettingsFor(String pluginId) {
Plugin plugin = pluginSqlMapDao.findPlugin(pluginId);
PluginSettings pluginSettings = new PluginSettings(pluginId);
if (!(plugin instanceof NullPlugin)) {
pluginSettings.populateSettingsMap(plugin);
}
return pluginSettings;
}
use of com.thoughtworks.go.server.domain.PluginSettings in project gocd by gocd.
the class PluginService method isRequestFresh.
private boolean isRequestFresh(String md5, PluginSettings pluginSettings, LocalizedOperationResult result) {
PluginSettings storedPluginSettings = loadStoredPluginSettings(pluginSettings.getPluginId());
if (storedPluginSettings == null) {
result.notFound(LocalizedMessage.string("RESOURCE_NOT_FOUND", "Plugin Settings", pluginSettings.getPluginId()), HealthStateType.notFound());
return false;
}
boolean freshRequest = entityHashingService.md5ForEntity(pluginSettings).equals(md5);
if (!freshRequest) {
result.stale(LocalizedMessage.string("STALE_RESOURCE_CONFIG", "Plugin Settings", pluginSettings.getPluginId()));
}
return freshRequest;
}
Aggregations