use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.
the class AuthorizationExtensionTest method shouldTalkToPlugin_To_ValidateAuthConfig.
@Test
public void shouldTalkToPlugin_To_ValidateAuthConfig() throws Exception {
String responseBody = "[{\"message\":\"Url must not be blank.\",\"key\":\"Url\"},{\"message\":\"SearchBase must not be blank.\",\"key\":\"SearchBase\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
ValidationResult validationResult = authorizationExtension.validateAuthConfig(PLUGIN_ID, Collections.emptyMap());
assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_VALIDATE_AUTH_CONFIG, "{}");
assertThat(validationResult.isSuccessful(), is(false));
assertThat(validationResult.getErrors(), containsInAnyOrder(new ValidationError("Url", "Url must not be blank."), new ValidationError("SearchBase", "SearchBase must not be blank.")));
}
use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.
the class AuthorizationExtensionTest method shouldTalkToPlugin_To_GetPluginConfigurationMetadata.
@Test
public void shouldTalkToPlugin_To_GetPluginConfigurationMetadata() throws Exception {
String responseBody = "[{\"key\":\"username\",\"metadata\":{\"required\":true,\"secure\":false}},{\"key\":\"password\",\"metadata\":{\"required\":true,\"secure\":true}}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
List<PluginConfiguration> authConfigMetadata = authorizationExtension.getAuthConfigMetadata(PLUGIN_ID);
assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_GET_AUTH_CONFIG_METADATA, null);
assertThat(authConfigMetadata.size(), is(2));
assertThat(authConfigMetadata, containsInAnyOrder(new PluginConfiguration("username", new Metadata(true, false)), new PluginConfiguration("password", new Metadata(true, true))));
}
use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.
the class AbstractExtensionTest method shouldNotifySettingsChangeForPluginWhichSupportsNotification.
@Test
public void shouldNotifySettingsChangeForPluginWhichSupportsNotification() throws Exception {
String supportedVersion = "2.0";
Map<String, String> settings = Collections.singletonMap("foo", "bar");
ArgumentCaptor<GoPluginApiRequest> requestArgumentCaptor = ArgumentCaptor.forClass(GoPluginApiRequest.class);
extension.registerHandler(supportedVersion, new PluginSettingsJsonMessageHandler2_0());
when(pluginManager.resolveExtensionVersion(pluginId, extensionName, goSupportedVersions)).thenReturn(supportedVersion);
when(pluginManager.submitTo(eq(pluginId), eq(extensionName), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, ""));
extension.notifyPluginSettingsChange(pluginId, settings);
assertRequest(requestArgumentCaptor.getValue(), extensionName, supportedVersion, REQUEST_NOTIFY_PLUGIN_SETTINGS_CHANGE, "{\"foo\":\"bar\"}");
}
use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.
the class AnalyticsExtensionTest method shouldFetchStaticAssets.
@Test
public void shouldFetchStaticAssets() throws Exception {
String responseBody = "{ \"assets\": \"assets payload\" }";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ANALYTICS_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
String assets = analyticsExtension.getStaticAssets(PLUGIN_ID);
assertRequest(requestArgumentCaptor.getValue(), ANALYTICS_EXTENSION, "1.0", REQUEST_GET_STATIC_ASSETS, null);
assertThat(assets, is("assets payload"));
}
use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.
the class AnalyticsExtensionTest method shouldGetAnalytics.
@Test
public void shouldGetAnalytics() throws Exception {
String responseBody = "{ \"view_path\": \"path/to/view\", \"data\": \"{}\" }";
AnalyticsPluginInfo pluginInfo = new AnalyticsPluginInfo(new GoPluginDescriptor(PLUGIN_ID, null, null, null, null, false), null, null, null);
pluginInfo.setStaticAssetsPath("/assets/root");
metadataStore.setPluginInfo(pluginInfo);
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ANALYTICS_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
AnalyticsData pipelineAnalytics = analyticsExtension.getAnalytics(PLUGIN_ID, "pipeline", "pipeline_with_highest_wait_time", Collections.singletonMap("pipeline_name", "test_pipeline"));
String expectedRequestBody = "{" + "\"type\": \"pipeline\"," + "\"id\": \"pipeline_with_highest_wait_time\"," + " \"params\": {\"pipeline_name\": \"test_pipeline\"}}";
assertRequest(requestArgumentCaptor.getValue(), PluginConstants.ANALYTICS_EXTENSION, "1.0", REQUEST_GET_ANALYTICS, expectedRequestBody);
assertThat(pipelineAnalytics.getData(), is("{}"));
assertThat(pipelineAnalytics.getViewPath(), is("path/to/view"));
assertThat(pipelineAnalytics.getFullViewPath(), is("/assets/root/path/to/view"));
}
Aggregations