Search in sources :

Example 11 with GoApiResponse

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));
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) Test(org.junit.Test)

Example 12 with GoApiResponse

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");
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) InOrder(org.mockito.InOrder) Gson(com.google.gson.Gson) ServerHealthState(com.thoughtworks.go.serverhealth.ServerHealthState) Test(org.junit.Test)

Example 13 with GoApiResponse

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));
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) Test(org.junit.Test)

Example 14 with GoApiResponse

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));
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Plugin(com.thoughtworks.go.domain.Plugin) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Test(org.junit.Test)

Example 15 with GoApiResponse

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"));
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) Gson(com.google.gson.Gson) Test(org.junit.Test)

Aggregations

GoApiResponse (com.thoughtworks.go.plugin.api.response.GoApiResponse)23 Test (org.junit.Test)23 DefaultGoApiRequest (com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest)10 GoPluginIdentifier (com.thoughtworks.go.plugin.api.GoPluginIdentifier)6 NullPlugin (com.thoughtworks.go.domain.NullPlugin)4 HashMap (java.util.HashMap)4 Plugin (com.thoughtworks.go.domain.Plugin)3 Gson (com.google.gson.Gson)2 ElasticAgentMetadata (com.thoughtworks.go.server.domain.ElasticAgentMetadata)2 Map (java.util.Map)2 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)2 User (com.thoughtworks.go.plugin.access.authentication.models.User)1 AuthorizationMessageConverterV1 (com.thoughtworks.go.plugin.access.authorization.AuthorizationMessageConverterV1)1 GoApiRequest (com.thoughtworks.go.plugin.api.request.GoApiRequest)1 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)1 PluginRoleService (com.thoughtworks.go.server.service.PluginRoleService)1 ServerHealthState (com.thoughtworks.go.serverhealth.ServerHealthState)1 InOrder (org.mockito.InOrder)1 PreAuthenticatedAuthenticationToken (org.springframework.security.providers.preauth.PreAuthenticatedAuthenticationToken)1