use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.
the class AuthorizationExtensionTest method shouldTalkToPlugin_To_GetRoleConfigurationView.
@Test
void shouldTalkToPlugin_To_GetRoleConfigurationView() {
String responseBody = "{ \"template\": \"<div>This is view snippet</div>\" }";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
String pluginConfigurationView = authorizationExtension.getRoleConfigurationView(PLUGIN_ID);
assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_GET_ROLE_CONFIG_VIEW, null);
assertThat(pluginConfigurationView).isEqualTo("<div>This is view snippet</div>");
}
use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.
the class AuthorizationExtensionTest method shouldTalkToPlugin_To_ValidateAuthConfig.
@Test
void shouldTalkToPlugin_To_ValidateAuthConfig() {
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()).isEqualTo(false);
assertThat(validationResult.getErrors()).hasSize(2).contains(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_GetAuthConfigView.
@Test
void shouldTalkToPlugin_To_GetAuthConfigView() {
String responseBody = "{ \"template\": \"<div>This is view snippet</div>\" }";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
String pluginConfigurationView = authorizationExtension.getAuthConfigView(PLUGIN_ID);
assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_GET_AUTH_CONFIG_VIEW, null);
assertThat(pluginConfigurationView).isEqualTo("<div>This is view snippet</div>");
}
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(GoPluginDescriptor.builder().id(PLUGIN_ID).build(), 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"));
}
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"));
}
Aggregations