Search in sources :

Example 16 with GoPluginApiRequest

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));
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) ExecutionResult(com.thoughtworks.go.plugin.api.response.execution.ExecutionResult) Test(org.junit.jupiter.api.Test)

Example 17 with GoPluginApiRequest

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\"}");
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.jupiter.api.Test)

Example 18 with GoPluginApiRequest

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\"}");
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) DefaultGoPluginApiResponse(com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse) Test(org.junit.jupiter.api.Test)

Example 19 with GoPluginApiRequest

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());
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)

Example 20 with GoPluginApiRequest

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));
}
Also used : TaskView(com.thoughtworks.go.plugin.api.task.TaskView) GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) Test(org.junit.jupiter.api.Test)

Aggregations

GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)42 Test (org.junit.jupiter.api.Test)23 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)15 Test (org.junit.Test)12 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)7 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)6 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)6 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Answer (org.mockito.stubbing.Answer)4 ArtifactStore (com.thoughtworks.go.config.ArtifactStore)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ArtifactPlan (com.thoughtworks.go.domain.ArtifactPlan)2 PublishArtifactResponse (com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse)2 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)2 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)2 GsonBuilder (com.google.gson.GsonBuilder)1 FetchPluggableArtifactTask (com.thoughtworks.go.config.FetchPluggableArtifactTask)1 PluginSettingsJsonMessageHandler2_0 (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsJsonMessageHandler2_0)1