Search in sources :

Example 21 with DefaultGoPluginApiResponse

use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.

the class ArtifactExtensionTest method shouldGetPluggableArtifactViewFromPlugin.

@Test
public void shouldGetPluggableArtifactViewFromPlugin() {
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, "{ \"template\": \"pluggable-artifact-view\"}"));
    String view = artifactExtension.getPublishArtifactView(PLUGIN_ID);
    final GoPluginApiRequest request = requestArgumentCaptor.getValue();
    assertThat(request.extension(), is(ARTIFACT_EXTENSION));
    assertThat(request.requestName(), is(REQUEST_PUBLISH_ARTIFACT_VIEW));
    assertNull(request.requestBody());
    assertThat(view, is("pluggable-artifact-view"));
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.Test)

Example 22 with DefaultGoPluginApiResponse

use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.

the class AuthorizationExtensionTest method shouldTalkToPlugin_To_GetRoleConfigurationView.

@Test
public void shouldTalkToPlugin_To_GetRoleConfigurationView() throws Exception {
    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, is("<div>This is view snippet</div>"));
}
Also used : DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.Test)

Example 23 with DefaultGoPluginApiResponse

use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.

the class AuthorizationExtensionTest method shouldTalkToPlugin_To_GetCapabilities.

@Test
public void shouldTalkToPlugin_To_GetCapabilities() throws Exception {
    String responseBody = "{\"supported_auth_type\":\"password\",\"can_search\":true}";
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
    com.thoughtworks.go.plugin.domain.authorization.Capabilities capabilities = authorizationExtension.getCapabilities(PLUGIN_ID);
    assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_GET_CAPABILITIES, null);
    assertThat(capabilities.getSupportedAuthType().toString(), is(SupportedAuthType.Password.toString()));
    assertThat(capabilities.canSearch(), is(true));
}
Also used : DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.Test)

Example 24 with DefaultGoPluginApiResponse

use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.

the class AuthorizationExtensionTest method shouldTalkToPlugin_To_GetAuthConfigView.

@Test
public void shouldTalkToPlugin_To_GetAuthConfigView() throws Exception {
    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, is("<div>This is view snippet</div>"));
}
Also used : DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.Test)

Example 25 with DefaultGoPluginApiResponse

use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.

the class AuthorizationExtensionTest method shouldTalkToPlugin_To_ValidateRoleConfiguration.

@Test
public void shouldTalkToPlugin_To_ValidateRoleConfiguration() throws Exception {
    String responseBody = "[{\"message\":\"memberOf must not be blank.\",\"key\":\"memberOf\"}]";
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(AUTHORIZATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
    ValidationResult validationResult = authorizationExtension.validateRoleConfiguration(PLUGIN_ID, Collections.emptyMap());
    assertRequest(requestArgumentCaptor.getValue(), AUTHORIZATION_EXTENSION, "1.0", REQUEST_VALIDATE_ROLE_CONFIG, "{}");
    assertThat(validationResult.isSuccessful(), is(false));
    assertThat(validationResult.getErrors(), containsInAnyOrder(new ValidationError("memberOf", "memberOf 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)

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