Search in sources :

Example 31 with DefaultGoPluginApiResponse

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>");
}
Also used : DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.jupiter.api.Test)

Example 32 with DefaultGoPluginApiResponse

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."));
}
Also used : DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 33 with DefaultGoPluginApiResponse

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>");
}
Also used : DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.jupiter.api.Test)

Example 34 with DefaultGoPluginApiResponse

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"));
}
Also used : AnalyticsData(com.thoughtworks.go.plugin.domain.analytics.AnalyticsData) AnalyticsPluginInfo(com.thoughtworks.go.plugin.domain.analytics.AnalyticsPluginInfo) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.jupiter.api.Test)

Example 35 with DefaultGoPluginApiResponse

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"));
}
Also used : DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)38 Test (org.junit.jupiter.api.Test)25 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)18 Test (org.junit.Test)12 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)9 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)9 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)4 User (com.thoughtworks.go.plugin.domain.authorization.User)3 SecurityAuthConfigs (com.thoughtworks.go.config.SecurityAuthConfigs)2 AuthenticationResponse (com.thoughtworks.go.plugin.domain.authorization.AuthenticationResponse)2 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)2 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)2 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)1 PluginSettingsJsonMessageHandler2_0 (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsJsonMessageHandler2_0)1 AnalyticsData (com.thoughtworks.go.plugin.domain.analytics.AnalyticsData)1 AnalyticsPluginInfo (com.thoughtworks.go.plugin.domain.analytics.AnalyticsPluginInfo)1 SupportedAnalytics (com.thoughtworks.go.plugin.domain.analytics.SupportedAnalytics)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1