Search in sources :

Example 26 with DefaultGoPluginApiResponse

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.")));
}
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.Test)

Example 27 with DefaultGoPluginApiResponse

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

Example 28 with DefaultGoPluginApiResponse

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\"}");
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) PluginSettingsJsonMessageHandler2_0(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsJsonMessageHandler2_0) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 29 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.Test)

Example 30 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(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"));
}
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) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Aggregations

DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)30 Test (org.junit.Test)30 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)10 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)6 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)6 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)4 User (com.thoughtworks.go.plugin.access.authorization.models.User)3 SecurityAuthConfigs (com.thoughtworks.go.config.SecurityAuthConfigs)2 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.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 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)1 Matchers.anyString (org.mockito.Matchers.anyString)1