Search in sources :

Example 6 with GoApiResponse

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

the class ElasticAgentRequestProcessorV1Test method shouldProcessListAgentRequest.

@Test
public void shouldProcessListAgentRequest() throws Exception {
    LinkedMultiValueMap<String, ElasticAgentMetadata> allAgents = new LinkedMultiValueMap<>();
    ElasticAgentMetadata agent = new ElasticAgentMetadata("foo", "bar", "cd.go.example.plugin", AgentRuntimeStatus.Building, AgentConfigStatus.Disabled);
    allAgents.put("cd.go.example.plugin", Arrays.asList(agent));
    when(agentService.allElasticAgents()).thenReturn(allAgents);
    when(request.api()).thenReturn(REQUEST_SERVER_LIST_AGENTS);
    GoApiResponse response = processor.process(pluginDescriptor, request);
    JSONAssert.assertEquals("[{\"agent_id\":\"bar\",\"agent_state\":\"Building\",\"build_state\":\"Building\",\"config_state\":\"Disabled\"}]", response.responseBody(), true);
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) Test(org.junit.Test)

Example 7 with GoApiResponse

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

the class PluginSettingsRequestProcessorTest method shouldRespondWith400IfNoneOfExtensionsCanHandleThePlugin.

@Test
public void shouldRespondWith400IfNoneOfExtensionsCanHandleThePlugin() {
    String PLUGIN_ID = "plugin-foo-id";
    when(pluginDescriptor.id()).thenReturn(PLUGIN_ID);
    when(pluginExtension.canHandlePlugin(PLUGIN_ID)).thenReturn(false);
    GoApiResponse response = processor.process(pluginDescriptor, new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "1.0", new GoPluginIdentifier("extension1", Collections.singletonList("1.0"))));
    assertThat(response.responseCode(), is(400));
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) GoPluginIdentifier(com.thoughtworks.go.plugin.api.GoPluginIdentifier) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 8 with GoApiResponse

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

the class ServerInfoRequestProcessorTest method shouldReturnAErrorResponseIfExtensionDoesNotSupportServerInfo.

@Test
public void shouldReturnAErrorResponseIfExtensionDoesNotSupportServerInfo() throws Exception {
    DefaultGoApiRequest request = new DefaultGoApiRequest(GET_SERVER_ID, "bad-version", new GoPluginIdentifier("foo", Arrays.asList("1.0")));
    when(pluginExtension.canHandlePlugin(pluginId)).thenReturn(true);
    when(pluginExtension.serverInfoJSON(any(String.class), any(String.class), any(String.class), any(String.class))).thenThrow(new UnsupportedOperationException("Operation not supported."));
    GoApiResponse response = processor.process(pluginDescriptor, request);
    assertThat(response.responseCode(), is(400));
}
Also used : GoPluginIdentifier(com.thoughtworks.go.plugin.api.GoPluginIdentifier) GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 9 with GoApiResponse

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

the class SessionRequestProcessorTest method shouldHandleIncorrectAPIVersion.

@Test
public void shouldHandleIncorrectAPIVersion() {
    GoApiResponse response = processor.process(pluginDescriptor, getGoPluginApiRequest("1.1", null, null));
    assertThat(response.responseCode(), is(500));
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) Test(org.junit.Test)

Example 10 with GoApiResponse

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

the class SessionRequestProcessorTest method shouldRemoveSession.

@Test
public void shouldRemoveSession() {
    String pluginId = "plugin-id-1";
    String requestBody = "expected-request";
    when(jsonMessageHandler.requestMessageSessionGetAndRemove(requestBody)).thenReturn(pluginId);
    SessionRequestProcessor applicationAccessorSpy = spy(processor);
    doReturn(session).when(applicationAccessorSpy).getUserSession();
    GoApiResponse response = applicationAccessorSpy.process(pluginDescriptor, getGoPluginApiRequest("1.0", SessionRequestProcessor.REMOVE_FROM_SESSION, requestBody));
    assertThat(response.responseCode(), is(200));
    verify(session).removeAttribute(pluginId);
}
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