Search in sources :

Example 21 with GoApiResponse

use of com.thoughtworks.go.plugin.api.response.GoApiResponse in project gocd by gocd.

the class SessionRequestProcessorTest method shouldHandleSessionNotFoundDuringGetFromSession.

@Test
public void shouldHandleSessionNotFoundDuringGetFromSession() {
    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.GET_FROM_SESSION, requestBody));
    assertThat(response.responseCode(), is(500));
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) Test(org.junit.Test)

Example 22 with GoApiResponse

use of com.thoughtworks.go.plugin.api.response.GoApiResponse in project gocd by gocd.

the class SessionRequestProcessorTest method shouldPutIntoSession.

@Test
public void shouldPutIntoSession() {
    String pluginId = "plugin-id-1";
    String requestBody = "expected-request";
    Map<String, String> sessionData = new HashMap<>();
    sessionData.put("k1", "v1");
    sessionData.put("k2", "v2");
    when(jsonMessageHandler.requestMessageSessionPut(requestBody)).thenReturn(new SessionData(pluginId, sessionData));
    SessionRequestProcessor applicationAccessorSpy = spy(processor);
    doReturn(session).when(applicationAccessorSpy).getUserSession();
    GoApiResponse response = applicationAccessorSpy.process(pluginDescriptor, getGoPluginApiRequest("1.0", SessionRequestProcessor.PUT_INTO_SESSION, requestBody));
    assertThat(response.responseCode(), is(200));
    verify(session).setAttribute(pluginId, sessionData);
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 23 with GoApiResponse

use of com.thoughtworks.go.plugin.api.response.GoApiResponse in project gocd by gocd.

the class SessionRequestProcessorTest method shouldHandleSessionNotFoundDuringPutIntoSession.

@Test
public void shouldHandleSessionNotFoundDuringPutIntoSession() {
    String pluginId = "plugin-id-1";
    String requestBody = "expected-request";
    when(jsonMessageHandler.requestMessageSessionPut(requestBody)).thenReturn(new SessionData(pluginId, null));
    SessionRequestProcessor applicationAccessorSpy = spy(processor);
    doReturn(null).when(applicationAccessorSpy).getUserSession();
    GoApiResponse response = applicationAccessorSpy.process(pluginDescriptor, getGoPluginApiRequest("1.0", SessionRequestProcessor.PUT_INTO_SESSION, requestBody));
    assertThat(response.responseCode(), is(500));
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) 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