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