@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)); }
com.thoughtworks.go.plugin.api.task.Console console = mock(com.thoughtworks.go.plugin.api.task.Console.class); when(context.workingDir()).thenReturn(workingDir); EnvironmentVariables environment = getEnvironmentVariables(); when(context.environment()).thenReturn(environment); when(context.console()).thenReturn(console); handler = new JsonBasedTaskExtensionHandler_V1(); handlerHashMap.put("1.0", handler); new JsonBasedTaskExecutor(pluginId, pluginRequestHelper, handlerHashMap).execute(config(), context);
@Test public void shouldExecuteAndReturnFailureExecutionResultTaskThroughPlugin() { when(pluginManager.submitTo(eq(pluginId), eq(PLUGGABLE_TASK_EXTENSION), any(GoPluginApiRequest.class))).thenReturn(response); when(handler.toExecutionResult(response.responseBody())).thenReturn(ExecutionResult.failure("error1")); ExecutionResult result = new JsonBasedTaskExecutor(pluginId, pluginRequestHelper, handlerHashMap).execute(config(), context); assertThat(result.isSuccessful(), is(false)); assertThat(result.getMessagesForDisplay(), is("error1")); }