Search in sources :

Example 6 with GoPluginApiRequest

use of com.thoughtworks.go.plugin.api.request.GoPluginApiRequest 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));
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) GoPluginApiResponse(com.thoughtworks.go.plugin.api.response.GoPluginApiResponse) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Example 7 with GoPluginApiRequest

use of com.thoughtworks.go.plugin.api.request.GoPluginApiRequest in project gocd by gocd.

the class JsonBasedPluggableTaskTest method shouldValidateTaskConfig.

@Test
public void shouldValidateTaskConfig() {
    String jsonResponse = "{\"errors\":{\"key1\":\"err1\",\"key2\":\"err3\"}}";
    String config = "{\"URL\":{\"secure\":false,\"value\":\"http://foo\",\"required\":true}}";
    when(goPluginApiResponse.responseBody()).thenReturn(jsonResponse);
    TaskConfig configuration = new TaskConfig();
    final TaskConfigProperty property = new TaskConfigProperty("URL", "http://foo");
    property.with(Property.SECURE, false);
    property.with(Property.REQUIRED, true);
    configuration.add(property);
    ValidationResult result = task.validate(configuration);
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.getErrors().get(0).getKey(), is("key1"));
    assertThat(result.getErrors().get(0).getMessage(), is("err1"));
    assertThat(result.getErrors().get(1).getKey(), is("key2"));
    assertThat(result.getErrors().get(1).getMessage(), is("err3"));
    ArgumentCaptor<GoPluginApiRequest> argument = ArgumentCaptor.forClass(GoPluginApiRequest.class);
    verify(pluginManager).submitTo(eq(pluginId), argument.capture());
    assertThat(argument.getValue().requestBody(), is(config));
    MatcherAssert.assertThat(argument.getValue().extension(), Matchers.is(TaskExtension.TASK_EXTENSION));
    MatcherAssert.assertThat(argument.getValue().extensionVersion(), Matchers.is(JsonBasedTaskExtensionHandler_V1.VERSION));
    MatcherAssert.assertThat(argument.getValue().requestName(), Matchers.is(TaskExtension.VALIDATION_REQUEST));
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) Test(org.junit.Test)

Example 8 with GoPluginApiRequest

use of com.thoughtworks.go.plugin.api.request.GoPluginApiRequest in project gocd by gocd.

the class JsonBasedPluggableTaskTest method shouldGetTheTaskConfig.

@Test
public void shouldGetTheTaskConfig() {
    String jsonResponse = "{" + "\"URL\":{\"default-value\":\"\",\"secure\":false,\"required\":true}," + "\"USER\":{\"default-value\":\"foo\",\"secure\":true,\"required\":true}," + "\"PASSWORD\":{}" + "}";
    when(goPluginApiResponse.responseBody()).thenReturn(jsonResponse);
    TaskConfig config = task.config();
    Property url = config.get("URL");
    assertThat(url.getOption(Property.REQUIRED), is(true));
    assertThat(url.getOption(Property.SECURE), is(false));
    Property user = config.get("USER");
    assertThat(user.getOption(Property.REQUIRED), is(true));
    assertThat(user.getOption(Property.SECURE), is(true));
    Property password = config.get("PASSWORD");
    assertThat(password.getOption(Property.REQUIRED), is(true));
    assertThat(password.getOption(Property.SECURE), is(false));
    ArgumentCaptor<GoPluginApiRequest> argument = ArgumentCaptor.forClass(GoPluginApiRequest.class);
    verify(pluginManager).submitTo(eq(pluginId), argument.capture());
    MatcherAssert.assertThat(argument.getValue().extension(), Matchers.is(TaskExtension.TASK_EXTENSION));
    MatcherAssert.assertThat(argument.getValue().extensionVersion(), Matchers.is(JsonBasedTaskExtensionHandler_V1.VERSION));
    MatcherAssert.assertThat(argument.getValue().requestName(), Matchers.is(TaskExtension.CONFIGURATION_REQUEST));
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) Test(org.junit.Test)

Aggregations

GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)8 Test (org.junit.Test)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Answer (org.mockito.stubbing.Answer)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)2 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)2 GsonBuilder (com.google.gson.GsonBuilder)1 GoPlugin (com.thoughtworks.go.plugin.api.GoPlugin)1 Property (com.thoughtworks.go.plugin.api.config.Property)1 GoPluginApiResponse (com.thoughtworks.go.plugin.api.response.GoPluginApiResponse)1 ExecutionResult (com.thoughtworks.go.plugin.api.response.execution.ExecutionResult)1 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)1 com.thoughtworks.go.plugin.api.task (com.thoughtworks.go.plugin.api.task)1 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)1 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)1