Search in sources :

Example 1 with DefaultGoApiRequest

use of com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest in project gocd by gocd.

the class AuthorizationRequestProcessorTest method shouldProcessInvalidateCacheRequest.

@Test
public void shouldProcessInvalidateCacheRequest() throws Exception {
    PluginRoleService pluginRoleService = mock(PluginRoleService.class);
    when(authorizationExtension.getMessageConverter(AuthorizationMessageConverterV1.VERSION)).thenReturn(new AuthorizationMessageConverterV1());
    GoApiRequest request = new DefaultGoApiRequest(INVALIDATE_CACHE_REQUEST.requestName(), "1.0", null);
    AuthorizationRequestProcessor authorizationRequestProcessor = new AuthorizationRequestProcessor(registry, null, authorizationExtension, pluginRoleService);
    GoApiResponse response = authorizationRequestProcessor.process(pluginDescriptor, request);
    assertThat(response.responseCode(), is(200));
    verify(pluginRoleService).invalidateRolesFor("cd.go.authorization.github");
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) AuthorizationMessageConverterV1(com.thoughtworks.go.plugin.access.authorization.AuthorizationMessageConverterV1) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) GoApiRequest(com.thoughtworks.go.plugin.api.request.GoApiRequest) PluginRoleService(com.thoughtworks.go.server.service.PluginRoleService) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 2 with DefaultGoApiRequest

use of com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest in project gocd by gocd.

the class ElasticAgentRequestProcessorTest method shouldProcessListAgentRequest.

@Test
public void shouldProcessListAgentRequest() throws Exception {
    LinkedMultiValueMap<String, ElasticAgentMetadata> allAgents = new LinkedMultiValueMap<>();
    ElasticAgentMetadata agent = new ElasticAgentMetadata("foo", "bar", "docker", AgentRuntimeStatus.Building, AgentConfigStatus.Disabled);
    allAgents.put("docker", Arrays.asList(agent));
    when(agentService.allElasticAgents()).thenReturn(allAgents);
    GoApiResponse response = processor.process(pluginDescriptor, new DefaultGoApiRequest(REQUEST_SERVER_LIST_AGENTS, "1.0", pluginIdentifier));
    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) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 3 with DefaultGoApiRequest

use of com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest in project gocd by gocd.

the class ElasticAgentRequestProcessorTest method shouldProcessDisableAgentRequest.

@Test
public void shouldProcessDisableAgentRequest() throws Exception {
    AgentMetadata agent = new AgentMetadata("foo", null, null, null);
    DefaultGoApiRequest goPluginApiRequest = new DefaultGoApiRequest(PROCESS_DISABLE_AGENTS, "1.0", pluginIdentifier);
    goPluginApiRequest.setRequestBody(extension.getElasticAgentMessageConverter(goPluginApiRequest.apiVersion()).listAgentsResponseBody(Arrays.asList(agent)));
    AgentInstance agentInstance = AgentInstance.createFromConfig(new AgentConfig("uuid"), null);
    when(agentService.findElasticAgent("foo", "docker")).thenReturn(agentInstance);
    processor.process(pluginDescriptor, goPluginApiRequest);
    verify(agentConfigService).disableAgents(processor.usernameFor(pluginDescriptor), agentInstance);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 4 with DefaultGoApiRequest

use of com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest in project gocd by gocd.

the class PluginSettingsRequestProcessorTest method shouldHandleIncorrectAPIVersion.

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

Example 5 with DefaultGoApiRequest

use of com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest in project gocd by gocd.

the class ElasticAgentRequestProcessorTest method shouldProcessDeleteAgentRequest.

@Test
public void shouldProcessDeleteAgentRequest() throws Exception {
    AgentMetadata agent = new AgentMetadata("foo", null, null, null);
    DefaultGoApiRequest goPluginApiRequest = new DefaultGoApiRequest(PROCESS_DELETE_AGENTS, "1.0", pluginIdentifier);
    goPluginApiRequest.setRequestBody(extension.getElasticAgentMessageConverter(goPluginApiRequest.apiVersion()).listAgentsResponseBody(Arrays.asList(agent)));
    AgentInstance agentInstance = AgentInstance.createFromConfig(new AgentConfig("uuid"), null);
    when(agentService.findElasticAgent("foo", "docker")).thenReturn(agentInstance);
    processor.process(pluginDescriptor, goPluginApiRequest);
    verify(agentConfigService).deleteAgents(processor.usernameFor(pluginDescriptor), agentInstance);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Aggregations

DefaultGoApiRequest (com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest)8 Test (org.junit.Test)8 GoApiResponse (com.thoughtworks.go.plugin.api.response.GoApiResponse)6 NullPlugin (com.thoughtworks.go.domain.NullPlugin)3 ElasticAgentMetadata (com.thoughtworks.go.server.domain.ElasticAgentMetadata)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 AgentInstance (com.thoughtworks.go.domain.AgentInstance)2 Plugin (com.thoughtworks.go.domain.Plugin)2 AgentMetadata (com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata)2 AuthorizationMessageConverterV1 (com.thoughtworks.go.plugin.access.authorization.AuthorizationMessageConverterV1)1 GoApiRequest (com.thoughtworks.go.plugin.api.request.GoApiRequest)1 PluginSettings (com.thoughtworks.go.server.domain.PluginSettings)1 PluginRoleService (com.thoughtworks.go.server.service.PluginRoleService)1 HashMap (java.util.HashMap)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1