use of com.thoughtworks.go.plugin.api.response.GoApiResponse in project gocd by gocd.
the class SessionRequestProcessorTest method shouldHandleSessionNotFoundDuringRemoveFromSession.
@Test
public void shouldHandleSessionNotFoundDuringRemoveFromSession() {
String pluginId = "plugin-id-1";
String requestBody = "expected-request";
when(jsonMessageHandler.requestMessageSessionGetAndRemove(requestBody)).thenReturn(pluginId);
SessionRequestProcessor applicationAccessorSpy = spy(processor);
doReturn(null).when(applicationAccessorSpy).getUserSession();
GoApiResponse response = applicationAccessorSpy.process(pluginDescriptor, getGoPluginApiRequest("1.0", SessionRequestProcessor.REMOVE_FROM_SESSION, requestBody));
assertThat(response.responseCode(), is(500));
}
use of com.thoughtworks.go.plugin.api.response.GoApiResponse in project gocd by gocd.
the class ServerHealthRequestProcessorTest method shouldAddDeserializedServerHealthMessages.
@Test
public void shouldAddDeserializedServerHealthMessages() {
String requestBody = new Gson().toJson(asList(new PluginHealthMessage("warning", "message 1"), new PluginHealthMessage("error", "message 2")));
GoApiResponse response = processor.process(descriptor, createRequest("1.0", requestBody));
assertThat(response.responseCode()).isEqualTo(SUCCESS_RESPONSE_CODE);
ArgumentCaptor<ServerHealthState> argumentCaptor = ArgumentCaptor.forClass(ServerHealthState.class);
InOrder inOrder = inOrder(serverHealthService);
inOrder.verify(serverHealthService, times(1)).removeByScope(HealthStateScope.fromPlugin(PLUGIN_ID));
inOrder.verify(serverHealthService, times(2)).update(argumentCaptor.capture());
assertThat(argumentCaptor.getAllValues().get(0).getDescription()).isEqualTo("message 1");
assertThat(argumentCaptor.getAllValues().get(1).getDescription()).isEqualTo("message 2");
}
use of com.thoughtworks.go.plugin.api.response.GoApiResponse in project gocd by gocd.
the class AuthenticationRequestProcessorTest method shouldHandleIncorrectAPIVersion.
@Test
public void shouldHandleIncorrectAPIVersion() {
GoApiResponse response = processor.process(pluginDescriptor, getGoPluginApiRequest("1.1", null));
assertThat(response.responseCode(), is(500));
}
use of com.thoughtworks.go.plugin.api.response.GoApiResponse in project gocd by gocd.
the class PluginSettingsRequestProcessorTest method shouldAccept2_0AsAnAPIVersion.
@Test
public void shouldAccept2_0AsAnAPIVersion() {
when(pluginDescriptor.id()).thenReturn("plugin-foo-id");
when(pluginSqlMapDao.findPlugin("plugin-foo-id")).thenReturn(new Plugin("plugin-foo-id", "{\"k1\": \"v1\",\"k2\": \"v2\"}"));
GoApiResponse response = processor.process(pluginDescriptor, new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "2.0", null));
assertThat(response.responseCode(), is(200));
}
use of com.thoughtworks.go.plugin.api.response.GoApiResponse in project gocd by gocd.
the class ServerHealthRequestProcessorTest method shouldRespondWithAFailedResponseCodeAndMessageIfSomethingGoesWrong.
@Test
public void shouldRespondWithAFailedResponseCodeAndMessageIfSomethingGoesWrong() {
GoApiResponse response = processor.process(descriptor, createRequest("1.0", "INVALID_JSON"));
assertThat(response.responseCode()).isEqualTo(INTERNAL_ERROR);
assertThat(new Gson().fromJson(response.responseBody(), Map.class)).isEqualTo(m("message", "Failed to deserialize message from plugin: INVALID_JSON"));
}
Aggregations