use of com.thoughtworks.go.plugin.api.request.GoPluginApiRequest in project gocd by gocd.
the class JsonBasedTaskExecutorTest method shouldExecuteAndReturnSuccessfulExecutionResultTaskThroughPlugin.
@Test
public void shouldExecuteAndReturnSuccessfulExecutionResultTaskThroughPlugin() {
when(pluginManager.submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), any(GoPluginApiRequest.class))).thenReturn(response);
when(handler.toExecutionResult(response.responseBody())).thenReturn(ExecutionResult.success("message1"));
ExecutionResult result = new JsonBasedTaskExecutor(pluginId, pluginRequestHelper, handlerHashMap).execute(config(), context);
assertThat(result.isSuccessful(), is(true));
assertThat(result.getMessagesForDisplay(), is("message1"));
ArgumentCaptor<GoPluginApiRequest> argument = ArgumentCaptor.forClass(GoPluginApiRequest.class);
verify(pluginManager).submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), argument.capture());
assertThat(argument.getValue().extension(), is(PLUGGABLE_TASK_EXTENSION));
assertThat(argument.getValue().extensionVersion(), is(extensionVersion));
assertThat(argument.getValue().requestName(), is(TaskExtension.EXECUTION_REQUEST));
}
use of com.thoughtworks.go.plugin.api.request.GoPluginApiRequest in project gocd by gocd.
the class NotificationExtensionTestForV4 method shouldNotifyPluginSettingsChange.
@Test
public void shouldNotifyPluginSettingsChange() throws Exception {
String supportedVersion = "4.0";
Map<String, String> settings = Collections.singletonMap("foo", "bar");
ArgumentCaptor<GoPluginApiRequest> requestArgumentCaptor = ArgumentCaptor.forClass(GoPluginApiRequest.class);
when(pluginManager.resolveExtensionVersion(eq("pluginId"), eq(NOTIFICATION_EXTENSION), anyList())).thenReturn(supportedVersion);
when(pluginManager.isPluginOfType(NOTIFICATION_EXTENSION, "pluginId")).thenReturn(true);
when(pluginManager.submitTo(eq("pluginId"), eq(NOTIFICATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, ""));
NotificationExtension extension = new NotificationExtension(pluginManager, extensionsRegistry);
extension.notifyPluginSettingsChange("pluginId", settings);
assertRequest(requestArgumentCaptor.getValue(), NOTIFICATION_EXTENSION, supportedVersion, REQUEST_NOTIFY_PLUGIN_SETTINGS_CHANGE, "{\"foo\":\"bar\"}");
}
use of com.thoughtworks.go.plugin.api.request.GoPluginApiRequest in project gocd by gocd.
the class NotificationExtensionTestForV3 method shouldNotifyPluginSettingsChange.
@Test
public void shouldNotifyPluginSettingsChange() throws Exception {
String supportedVersion = "3.0";
Map<String, String> settings = Collections.singletonMap("foo", "bar");
ArgumentCaptor<GoPluginApiRequest> requestArgumentCaptor = ArgumentCaptor.forClass(GoPluginApiRequest.class);
when(pluginManager.resolveExtensionVersion(eq("pluginId"), eq(NOTIFICATION_EXTENSION), anyList())).thenReturn(supportedVersion);
when(pluginManager.isPluginOfType(NOTIFICATION_EXTENSION, "pluginId")).thenReturn(true);
when(pluginManager.submitTo(eq("pluginId"), eq(NOTIFICATION_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, ""));
NotificationExtension extension = new NotificationExtension(pluginManager, extensionsRegistry);
extension.notifyPluginSettingsChange("pluginId", settings);
assertRequest(requestArgumentCaptor.getValue(), NOTIFICATION_EXTENSION, supportedVersion, REQUEST_NOTIFY_PLUGIN_SETTINGS_CHANGE, "{\"foo\":\"bar\"}");
}
use of com.thoughtworks.go.plugin.api.request.GoPluginApiRequest in project gocd by gocd.
the class ElasticAgentExtensionV4Test method assertExtensionRequest.
private void assertExtensionRequest(String extensionVersion, String requestName, String requestBody) {
final GoPluginApiRequest request = requestArgumentCaptor.getValue();
assertThat(request.requestName(), Matchers.is(requestName));
assertThat(request.extensionVersion(), Matchers.is(extensionVersion));
assertThat(request.extension(), Matchers.is(PluginConstants.ELASTIC_AGENT_EXTENSION));
assertThatJson(requestBody).isEqualTo(request.requestBody());
}
use of com.thoughtworks.go.plugin.api.request.GoPluginApiRequest in project gocd by gocd.
the class JsonBasedPluggableTaskTest method shouldGetTaskView.
@Test
public void shouldGetTaskView() {
String jsonResponse = "{\"displayValue\":\"MyTaskPlugin\", \"template\":\"<html>junk</html>\"}";
when(goPluginApiResponse.responseBody()).thenReturn(jsonResponse);
TaskView view = task.view();
assertThat(view.displayValue(), is("MyTaskPlugin"));
assertThat(view.template(), is("<html>junk</html>"));
ArgumentCaptor<GoPluginApiRequest> argument = ArgumentCaptor.forClass(GoPluginApiRequest.class);
verify(pluginManager).submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), argument.capture());
MatcherAssert.assertThat(argument.getValue().extension(), Matchers.is(PLUGGABLE_TASK_EXTENSION));
MatcherAssert.assertThat(argument.getValue().extensionVersion(), Matchers.is(JsonBasedTaskExtensionHandler_V1.VERSION));
MatcherAssert.assertThat(argument.getValue().requestName(), Matchers.is(TaskExtension.TASK_VIEW_REQUEST));
}
Aggregations