use of com.thoughtworks.go.plugin.api.response.GoPluginApiResponse in project gocd by gocd.
the class DefaultPluginManagerTest method shouldSubmitPluginApiRequestToGivenPlugin.
@Test
public void shouldSubmitPluginApiRequestToGivenPlugin() throws Exception {
GoPluginApiRequest request = mock(GoPluginApiRequest.class);
GoPluginApiResponse expectedResponse = mock(GoPluginApiResponse.class);
final GoPlugin goPlugin = mock(GoPlugin.class);
final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
when(goPlugin.handle(request)).thenReturn(expectedResponse);
ArgumentCaptor<PluginAwareDefaultGoApplicationAccessor> captor = ArgumentCaptor.forClass(PluginAwareDefaultGoApplicationAccessor.class);
doNothing().when(goPlugin).initializeGoApplicationAccessor(captor.capture());
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
ActionWithReturn<GoPlugin, GoPluginApiResponse> action = (ActionWithReturn<GoPlugin, GoPluginApiResponse>) invocationOnMock.getArguments()[2];
return action.execute(goPlugin, descriptor);
}
}).when(goPluginOSGiFramework).doOn(eq(GoPlugin.class), eq("plugin-id"), any(ActionWithReturn.class));
DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, goPluginOSGiFramework, jarChangeListener, pluginRequestProcessorRegistry, pluginWriter, pluginValidator, systemEnvironment, pluginsZipUpdater, pluginsListListener);
GoPluginApiResponse actualResponse = pluginManager.submitTo("plugin-id", request);
assertThat(actualResponse, is(expectedResponse));
PluginAwareDefaultGoApplicationAccessor accessor = captor.getValue();
assertThat(accessor.pluginDescriptor(), is(descriptor));
}
use of com.thoughtworks.go.plugin.api.response.GoPluginApiResponse in project gocd by gocd.
the class PluginController method handlePluginInteractRequest.
@RequestMapping(value = "/plugin/interact/{pluginId}/{requestName}", method = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE })
public void handlePluginInteractRequest(@PathVariable String pluginId, @PathVariable String requestName, HttpServletRequest request, HttpServletResponse response) throws IOException {
if (!isAuthPlugin(pluginId)) {
response.setStatus(SC_FORBIDDEN);
response.getWriter().println("Plugin interact endpoint is enabled only for Authentication Plugins");
return;
}
if (isRestrictedRequestName(requestName)) {
response.setStatus(SC_FORBIDDEN);
response.getWriter().println(String.format("Plugin interact for '%s' requestName is disallowed.", requestName));
return;
}
DefaultGoPluginApiRequest apiRequest = new DefaultGoPluginApiRequest(null, null, requestName);
apiRequest.setRequestParams(getParameterMap(request));
addRequestHeaders(request, apiRequest);
try {
GoPluginApiResponse pluginApiResponse = pluginManager.submitTo(pluginId, apiRequest);
if (DefaultGoApiResponse.SUCCESS_RESPONSE_CODE == pluginApiResponse.responseCode()) {
renderPluginResponse(pluginApiResponse, response);
return;
}
if (DefaultGoApiResponse.REDIRECT_RESPONSE_CODE == pluginApiResponse.responseCode()) {
String location = "";
if (hasValueFor(pluginApiResponse, "Location")) {
location = pluginApiResponse.responseHeaders().get("Location");
}
response.sendRedirect(location);
return;
}
} catch (Exception e) {
// handle
}
throw new RuntimeException("render error page");
}
use of com.thoughtworks.go.plugin.api.response.GoPluginApiResponse in project gocd by gocd.
the class JsonBasedTaskExtensionHandler_V1Test method shouldConstructExecutionResultFromSuccessfulExecutionResponse.
@Test
public void shouldConstructExecutionResultFromSuccessfulExecutionResponse() {
GoPluginApiResponse response = mock(GoPluginApiResponse.class);
when(response.responseBody()).thenReturn("{\"success\":true,\"message\":\"message1\"}");
ExecutionResult result = new JsonBasedTaskExtensionHandler_V1().toExecutionResult(response.responseBody());
assertThat(result.isSuccessful(), is(true));
assertThat(result.getMessagesForDisplay(), is("message1"));
}
Aggregations