use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.
the class PluginControllerTest method shouldForwardWebRequestToPlugin.
@Test
public void shouldForwardWebRequestToPlugin() throws Exception {
when(pluginManager.submitTo(eq(PLUGIN_ID), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(200));
when(pluginManager.isPluginOfType(any(String.class), any(String.class))).thenReturn(true);
Map<String, String[]> springParameterMap = new HashMap<>();
springParameterMap.put("k1", new String[] { "v1" });
springParameterMap.put("k2", new String[] { "v2", "v3" });
springParameterMap.put("k3", new String[] {});
springParameterMap.put("k4", null);
when(servletRequest.getParameterMap()).thenReturn(springParameterMap);
List<String> elements = Arrays.asList("h1", "h2", "h3");
when(servletRequest.getHeader("h1")).thenReturn("v1");
when(servletRequest.getHeader("h2")).thenReturn("");
when(servletRequest.getHeader("h3")).thenReturn(null);
when(servletRequest.getHeaderNames()).thenReturn(getMockEnumeration(elements));
pluginController.handlePluginInteractRequest(PLUGIN_ID, REQUEST_NAME, servletRequest, servletResponse);
Map<String, String> requestParameters = new HashMap<>();
requestParameters.put("k1", "v1");
requestParameters.put("k2", "v2");
requestParameters.put("k3", null);
requestParameters.put("k4", null);
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("h1", "v1");
requestHeaders.put("h2", "");
requestHeaders.put("h3", null);
assertRequest(requestArgumentCaptor.getValue(), REQUEST_NAME, requestParameters, requestHeaders);
}
use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.
the class AuthorizationExtensionTest method shouldTalkToPlugin_To_GetPluginConfigurationView.
@Test
public void shouldTalkToPlugin_To_GetPluginConfigurationView() throws Exception {
String responseBody = "{ \"template\": \"<div>This is view snippet</div>\" }";
when(pluginManager.submitTo(eq(PLUGIN_ID), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
String pluginConfigurationView = authorizationExtension.getPluginConfigurationView(PLUGIN_ID);
assertRequest(requestArgumentCaptor.getValue(), AuthorizationPluginConstants.EXTENSION_NAME, "1.0", REQUEST_GET_AUTH_CONFIG_VIEW, null);
assertThat(pluginConfigurationView, is("<div>This is view snippet</div>"));
}
use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.
the class ArtifactExtensionTest method shouldGetArtifactStoreViewFromPlugin.
@Test
public void shouldGetArtifactStoreViewFromPlugin() {
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, "{ \"template\": \"artifact-store-view\"}"));
String view = artifactExtension.getArtifactStoreView(PLUGIN_ID);
final GoPluginApiRequest request = requestArgumentCaptor.getValue();
assertThat(request.extension(), is(ARTIFACT_EXTENSION));
assertThat(request.requestName(), is(REQUEST_STORE_CONFIG_VIEW));
assertNull(request.requestBody());
assertThat(view, is("artifact-store-view"));
}
use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.
the class ArtifactExtensionTest method shouldValidateArtifactStoreConfig.
@Test
public void shouldValidateArtifactStoreConfig() {
String responseBody = "[{\"message\":\"ACCESS_KEY must not be blank.\",\"key\":\"ACCESS_KEY\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
ValidationResult validationResult = artifactExtension.validateArtifactStoreConfig(PLUGIN_ID, Collections.singletonMap("ACCESS_KEY", ""));
final GoPluginApiRequest request = requestArgumentCaptor.getValue();
assertThat(request.extension(), is(ARTIFACT_EXTENSION));
assertThat(request.requestName(), is(REQUEST_STORE_CONFIG_VALIDATE));
assertThat(request.requestBody(), is("{\"ACCESS_KEY\":\"\"}"));
assertThat(validationResult.isSuccessful(), is(false));
assertThat(validationResult.getErrors(), containsInAnyOrder(new ValidationError("ACCESS_KEY", "ACCESS_KEY must not be blank.")));
}
use of com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse in project gocd by gocd.
the class ArtifactExtensionTest method shouldValidateFetchArtifactConfig.
@Test
public void shouldValidateFetchArtifactConfig() {
String responseBody = "[{\"message\":\"Filename must not be blank.\",\"key\":\"Filename\"}]";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(new DefaultGoPluginApiResponse(SUCCESS_RESPONSE_CODE, responseBody));
ValidationResult validationResult = artifactExtension.validateFetchArtifactConfig(PLUGIN_ID, Collections.singletonMap("Filename", ""));
final GoPluginApiRequest request = requestArgumentCaptor.getValue();
assertThat(request.extension(), is(ARTIFACT_EXTENSION));
assertThat(request.requestName(), is(REQUEST_FETCH_ARTIFACT_VALIDATE));
assertThat(request.requestBody(), is("{\"Filename\":\"\"}"));
assertThat(validationResult.isSuccessful(), is(false));
assertThat(validationResult.getErrors(), containsInAnyOrder(new ValidationError("Filename", "Filename must not be blank.")));
}
Aggregations