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);
}
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");
}
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();
}
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");
}
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());
}
Aggregations