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