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