Search in sources :

Example 6 with DefaultGoApiRequest

use of com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest 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 7 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)

Example 8 with DefaultGoApiRequest

use of com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest 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 9 with DefaultGoApiRequest

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

the class ServerHealthRequestProcessorTest method createRequest.

private DefaultGoApiRequest createRequest(String apiVersion, String requestBody) {
    DefaultGoApiRequest request = new DefaultGoApiRequest(ADD_SERVER_HEALTH_MESSAGES, apiVersion, null);
    request.setRequestBody(requestBody);
    return request;
}
Also used : DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest)

Example 10 with DefaultGoApiRequest

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

the class PluginSettingsRequestProcessorTest method shouldGetPluginSettingsForPluginThatExistsInDB.

@Test
public void shouldGetPluginSettingsForPluginThatExistsInDB() {
    String PLUGIN_ID = "plugin-foo-id";
    when(pluginDescriptor.id()).thenReturn(PLUGIN_ID);
    when(pluginSqlMapDao.findPlugin(PLUGIN_ID)).thenReturn(new Plugin(PLUGIN_ID, "{\"k1\": \"v1\",\"k2\": \"v2\"}"));
    String responseBody = "expected-response";
    Map<String, String> settingsMap = new HashMap<>();
    settingsMap.put("k1", "v1");
    settingsMap.put("k2", "v2");
    when(pluginExtension.canHandlePlugin(PLUGIN_ID)).thenReturn(true);
    when(pluginExtension.pluginSettingsJSON(PLUGIN_ID, settingsMap)).thenReturn(responseBody);
    DefaultGoApiRequest apiRequest = new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "1.0", new GoPluginIdentifier("extension1", Collections.singletonList("1.0")));
    apiRequest.setRequestBody("expected-request");
    GoApiResponse response = processor.process(pluginDescriptor, apiRequest);
    assertThat(response.responseCode(), is(200));
    assertThat(response.responseBody(), is(responseBody));
}
Also used : GoPluginIdentifier(com.thoughtworks.go.plugin.api.GoPluginIdentifier) GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) HashMap(java.util.HashMap) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) Test(org.junit.Test)

Aggregations

DefaultGoApiRequest (com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest)16 Test (org.junit.Test)15 GoApiResponse (com.thoughtworks.go.plugin.api.response.GoApiResponse)10 GoPluginIdentifier (com.thoughtworks.go.plugin.api.GoPluginIdentifier)9 NullPlugin (com.thoughtworks.go.domain.NullPlugin)5 Plugin (com.thoughtworks.go.domain.Plugin)4 ElasticAgentMetadata (com.thoughtworks.go.server.domain.ElasticAgentMetadata)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 AgentInstance (com.thoughtworks.go.domain.AgentInstance)2 GoPluginExtension (com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension)2 AgentMetadata (com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata)2 HashMap (java.util.HashMap)2 AuthorizationMessageConverterV1 (com.thoughtworks.go.plugin.access.authorization.AuthorizationMessageConverterV1)1 GoApiRequest (com.thoughtworks.go.plugin.api.request.GoApiRequest)1 PluginRoleService (com.thoughtworks.go.server.service.PluginRoleService)1 Map (java.util.Map)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1