Search in sources :

Example 31 with GoPluginApiRequest

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

the class DefaultPluginManagerTest method shouldSubmitPluginApiRequestToGivenPlugin.

@Test
void shouldSubmitPluginApiRequestToGivenPlugin() throws Exception {
    String extensionType = "sample-extension";
    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) {
            ActionWithReturn<GoPlugin, GoPluginApiResponse> action = (ActionWithReturn<GoPlugin, GoPluginApiResponse>) invocationOnMock.getArguments()[3];
            return action.execute(goPlugin, descriptor);
        }
    }).when(goPluginOSGiFramework).doOn(eq(GoPlugin.class), eq("plugin-id"), eq(extensionType), any(ActionWithReturn.class));
    DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, goPluginOSGiFramework, jarChangeListener, pluginRequestProcessorRegistry, systemEnvironment, pluginLoader);
    GoPluginApiResponse actualResponse = pluginManager.submitTo("plugin-id", extensionType, request);
    assertThat(actualResponse).isEqualTo(expectedResponse);
    PluginAwareDefaultGoApplicationAccessor accessor = captor.getValue();
    assertThat(accessor.pluginDescriptor()).isEqualTo(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.jupiter.api.Test)

Example 32 with GoPluginApiRequest

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

the class PluginRequestHelperTest method shouldConstructTheRequestWithRequestHeaders.

@Test
void shouldConstructTheRequestWithRequestHeaders() {
    final String requestBody = "request_body";
    when(response.responseCode()).thenReturn(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
    final GoPluginApiRequest[] generatedRequest = { null };
    doAnswer(invocationOnMock -> {
        generatedRequest[0] = (GoPluginApiRequest) invocationOnMock.getArguments()[2];
        return response;
    }).when(pluginManager).submitTo(eq(pluginId), eq(extensionName), any(GoPluginApiRequest.class));
    helper.submitRequest(pluginId, requestName, new PluginInteractionCallback<Object>() {

        @Override
        public String requestBody(String resolvedExtensionVersion) {
            return requestBody;
        }

        @Override
        public Map<String, String> requestParams(String resolvedExtensionVersion) {
            return null;
        }

        @Override
        public Map<String, String> requestHeaders(String resolvedExtensionVersion) {
            final Map<String, String> headers = new HashMap();
            headers.put("HEADER-1", "HEADER-VALUE-1");
            headers.put("HEADER-2", "HEADER-VALUE-2");
            return headers;
        }

        @Override
        public Object onSuccess(String responseBody, Map<String, String> responseHeaders, String resolvedExtensionVersion) {
            return null;
        }

        @Override
        public void onFailure(int responseCode, String responseBody, String resolvedExtensionVersion) {
        }
    });
    assertThat(generatedRequest[0].requestBody()).isEqualTo(requestBody);
    assertThat(generatedRequest[0].extension()).isEqualTo(extensionName);
    assertThat(generatedRequest[0].requestName()).isEqualTo(requestName);
    assertThat(generatedRequest[0].requestHeaders().size()).isEqualTo(2);
    assertThat(generatedRequest[0].requestHeaders().get("HEADER-1")).isEqualTo("HEADER-VALUE-1");
    assertThat(generatedRequest[0].requestHeaders().get("HEADER-2")).isEqualTo("HEADER-VALUE-2");
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 33 with GoPluginApiRequest

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

the class PluginRequestHelperTest method shouldConstructTheRequest.

@Test
void shouldConstructTheRequest() {
    final String requestBody = "request_body";
    when(response.responseCode()).thenReturn(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
    final GoPluginApiRequest[] generatedRequest = { null };
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            generatedRequest[0] = (GoPluginApiRequest) invocationOnMock.getArguments()[2];
            return response;
        }
    }).when(pluginManager).submitTo(eq(pluginId), eq(extensionName), any(GoPluginApiRequest.class));
    helper.submitRequest(pluginId, requestName, new DefaultPluginInteractionCallback<Object>() {

        @Override
        public String requestBody(String resolvedExtensionVersion) {
            return requestBody;
        }
    });
    assertThat(generatedRequest[0].requestBody()).isEqualTo(requestBody);
    assertThat(generatedRequest[0].extension()).isEqualTo(extensionName);
    assertThat(generatedRequest[0].requestName()).isEqualTo(requestName);
    assertThat(generatedRequest[0].requestParameters().isEmpty()).isTrue();
}
Also used : Answer(org.mockito.stubbing.Answer) GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.jupiter.api.Test)

Example 34 with GoPluginApiRequest

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

the class PluginRequestHelperTest method shouldConstructTheRequestWithRequestParams.

@Test
void shouldConstructTheRequestWithRequestParams() {
    final String requestBody = "request_body";
    when(response.responseCode()).thenReturn(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE);
    final GoPluginApiRequest[] generatedRequest = { null };
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            generatedRequest[0] = (GoPluginApiRequest) invocationOnMock.getArguments()[2];
            return response;
        }
    }).when(pluginManager).submitTo(eq(pluginId), eq(extensionName), any(GoPluginApiRequest.class));
    helper.submitRequest(pluginId, requestName, new PluginInteractionCallback<Object>() {

        @Override
        public String requestBody(String resolvedExtensionVersion) {
            return requestBody;
        }

        @Override
        public Map<String, String> requestParams(String resolvedExtensionVersion) {
            final HashMap params = new HashMap();
            params.put("p1", "v1");
            params.put("p2", "v2");
            return params;
        }

        @Override
        public Map<String, String> requestHeaders(String resolvedExtensionVersion) {
            return null;
        }

        @Override
        public Object onSuccess(String responseBody, Map<String, String> responseHeaders, String resolvedExtensionVersion) {
            return null;
        }

        @Override
        public void onFailure(int responseCode, String responseBody, String resolvedExtensionVersion) {
        }
    });
    assertThat(generatedRequest[0].requestBody()).isEqualTo(requestBody);
    assertThat(generatedRequest[0].extension()).isEqualTo(extensionName);
    assertThat(generatedRequest[0].requestName()).isEqualTo(requestName);
    assertThat(generatedRequest[0].requestParameters().size()).isEqualTo(2);
    assertThat(generatedRequest[0].requestParameters().get("p1")).isEqualTo("v1");
    assertThat(generatedRequest[0].requestParameters().get("p2")).isEqualTo("v2");
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) HashMap(java.util.HashMap) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 35 with GoPluginApiRequest

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

the class ArtifactExtensionTestBase method shouldGetCapabilities.

@Test
public void shouldGetCapabilities() {
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success("{}"));
    artifactExtension.getCapabilities(PLUGIN_ID);
    final GoPluginApiRequest request = requestArgumentCaptor.getValue();
    assertThat(request.extension(), is(ARTIFACT_EXTENSION));
    assertThat(request.requestName(), is(REQUEST_GET_CAPABILITIES));
    assertNull(request.requestBody());
}
Also used : 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