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");
}
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);
}
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);
}
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));
}
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);
}
Aggregations