Search in sources :

Example 1 with GoApiRequest

use of com.thoughtworks.go.plugin.api.request.GoApiRequest in project gocd by gocd.

the class PluginAwareDefaultGoApplicationAccessorTest method shouldHandleExceptionThrownByProcessor.

@Test
public void shouldHandleExceptionThrownByProcessor() throws Exception {
    String api = "api-uri";
    GoPluginApiRequestProcessor processor = mock(GoPluginApiRequestProcessor.class);
    GoApiRequest goApiRequest = mock(GoApiRequest.class);
    GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
    when(goApiRequest.api()).thenReturn(api);
    Throwable cause = new RuntimeException("error");
    when(processor.process(descriptor, goApiRequest)).thenThrow(cause);
    PluginRequestProcessorRegistry pluginRequestProcessorRegistry = new PluginRequestProcessorRegistry();
    pluginRequestProcessorRegistry.registerProcessorFor(api, processor);
    PluginAwareDefaultGoApplicationAccessor accessor = new PluginAwareDefaultGoApplicationAccessor(descriptor, pluginRequestProcessorRegistry);
    try {
        accessor.submit(goApiRequest);
    } catch (Exception e) {
        assertThat(e.getMessage(), is(String.format("Error while processing request api %s", api)));
        assertThat(e.getCause(), is(cause));
    }
}
Also used : GoApiRequest(com.thoughtworks.go.plugin.api.request.GoApiRequest) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Example 2 with GoApiRequest

use of com.thoughtworks.go.plugin.api.request.GoApiRequest in project gocd by gocd.

the class AuthorizationRequestProcessorTest method shouldProcessInvalidateCacheRequest.

@Test
public void shouldProcessInvalidateCacheRequest() throws Exception {
    PluginRoleService pluginRoleService = mock(PluginRoleService.class);
    when(authorizationExtension.getMessageConverter(AuthorizationMessageConverterV1.VERSION)).thenReturn(new AuthorizationMessageConverterV1());
    GoApiRequest request = new DefaultGoApiRequest(INVALIDATE_CACHE_REQUEST.requestName(), "1.0", null);
    AuthorizationRequestProcessor authorizationRequestProcessor = new AuthorizationRequestProcessor(registry, null, authorizationExtension, pluginRoleService);
    GoApiResponse response = authorizationRequestProcessor.process(pluginDescriptor, request);
    assertThat(response.responseCode(), is(200));
    verify(pluginRoleService).invalidateRolesFor("cd.go.authorization.github");
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) AuthorizationMessageConverterV1(com.thoughtworks.go.plugin.access.authorization.AuthorizationMessageConverterV1) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) GoApiRequest(com.thoughtworks.go.plugin.api.request.GoApiRequest) PluginRoleService(com.thoughtworks.go.server.service.PluginRoleService) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Aggregations

GoApiRequest (com.thoughtworks.go.plugin.api.request.GoApiRequest)2 Test (org.junit.Test)2 AuthorizationMessageConverterV1 (com.thoughtworks.go.plugin.access.authorization.AuthorizationMessageConverterV1)1 DefaultGoApiRequest (com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest)1 GoApiResponse (com.thoughtworks.go.plugin.api.response.GoApiResponse)1 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)1 PluginRoleService (com.thoughtworks.go.server.service.PluginRoleService)1