Search in sources :

Example 11 with DefaultGoApiRequest

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

the class PluginSettingsRequestProcessorTest method shouldNotGetPluginSettingsForPluginThatDoesNotExistInDB.

@Test
public void shouldNotGetPluginSettingsForPluginThatDoesNotExistInDB() {
    String PLUGIN_ID = "plugin-foo-id";
    String requestBody = "expected-request";
    when(pluginDescriptor.id()).thenReturn(PLUGIN_ID);
    when(pluginSqlMapDao.findPlugin(PLUGIN_ID)).thenReturn(new NullPlugin());
    when(pluginExtension.canHandlePlugin(PLUGIN_ID)).thenReturn(true);
    DefaultGoApiRequest apiRequest = new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "1.0", new GoPluginIdentifier("extension1", Collections.singletonList("1.0")));
    apiRequest.setRequestBody(requestBody);
    GoApiResponse response = processor.process(pluginDescriptor, apiRequest);
    assertThat(response.responseCode(), is(200));
    assertThat(response.responseBody(), is(nullValue()));
    verify(pluginExtension).pluginSettingsJSON(PLUGIN_ID, Collections.EMPTY_MAP);
}
Also used : GoPluginIdentifier(com.thoughtworks.go.plugin.api.GoPluginIdentifier) GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) NullPlugin(com.thoughtworks.go.domain.NullPlugin) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 12 with DefaultGoApiRequest

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

the class PluginSettingsRequestProcessorTest method shouldRouteToTheRightExtensionBasedOnTheRequest_WhenAPluginHasMultipleExtensions.

@Test
public void shouldRouteToTheRightExtensionBasedOnTheRequest_WhenAPluginHasMultipleExtensions() throws Exception {
    GoPluginExtension anotherPluginExtension = mock(GoPluginExtension.class);
    String pluginId = "plugin-foo-id";
    Map<String, String> pluginSettings = m("k1", "v1", "k2", "v2");
    when(pluginDescriptor.id()).thenReturn(pluginId);
    when(pluginSqlMapDao.findPlugin(pluginId)).thenReturn(new Plugin(pluginId, "{\"k1\": \"v1\",\"k2\": \"v2\"}"));
    processor = new PluginSettingsRequestProcessor(applicationAccessor, pluginSqlMapDao, Arrays.asList(pluginExtension, anotherPluginExtension));
    DefaultGoApiRequest requestForExtension1 = new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "1.0", new GoPluginIdentifier("extension1", singletonList("1.0")));
    setupExpectationsFor(pluginExtension, pluginId, "extension1");
    setupExpectationsFor(anotherPluginExtension, pluginId, "extension2");
    processor.process(pluginDescriptor, requestForExtension1);
    verify(pluginExtension).pluginSettingsJSON(eq(pluginId), anyMapOf(String.class, String.class));
    verify(anotherPluginExtension, never()).pluginSettingsJSON(eq(pluginId), anyMapOf(String.class, String.class));
    Mockito.reset(pluginExtension, anotherPluginExtension);
    DefaultGoApiRequest requestForExtension2 = new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "1.0", new GoPluginIdentifier("extension2", singletonList("1.0")));
    setupExpectationsFor(pluginExtension, pluginId, "extension1");
    setupExpectationsFor(anotherPluginExtension, pluginId, "extension2");
    processor.process(pluginDescriptor, requestForExtension2);
    verify(pluginExtension, never()).pluginSettingsJSON(eq(pluginId), anyMapOf(String.class, String.class));
    verify(anotherPluginExtension).pluginSettingsJSON(eq(pluginId), anyMapOf(String.class, String.class));
    Mockito.reset(pluginExtension, anotherPluginExtension);
}
Also used : GoPluginExtension(com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension) GoPluginIdentifier(com.thoughtworks.go.plugin.api.GoPluginIdentifier) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) Test(org.junit.Test)

Example 13 with DefaultGoApiRequest

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

the class PluginSettingsRequestProcessorTest method shouldRespondWith400IfPluginExtensionErrorsOut.

@Test
public void shouldRespondWith400IfPluginExtensionErrorsOut() {
    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\"}"));
    when(pluginExtension.canHandlePlugin(PLUGIN_ID)).thenReturn(true);
    when(pluginExtension.pluginSettingsJSON(eq(PLUGIN_ID), any(Map.class))).thenThrow(RuntimeException.class);
    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(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) HashMap(java.util.HashMap) Map(java.util.Map) NullPlugin(com.thoughtworks.go.domain.NullPlugin) Plugin(com.thoughtworks.go.domain.Plugin) Test(org.junit.Test)

Example 14 with DefaultGoApiRequest

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

the class ServerInfoRequestProcessorTest method shouldReturnAServerIdInJSONForm.

@Test
public void shouldReturnAServerIdInJSONForm() throws Exception {
    DefaultGoApiRequest request = new DefaultGoApiRequest(GET_SERVER_ID, "1.0", new GoPluginIdentifier("extension1", Arrays.asList("1.0")));
    when(pluginExtension.canHandlePlugin(pluginId)).thenReturn(true);
    when(pluginExtension.serverInfoJSON(pluginId, serverConfig.getServerId(), serverConfig.getSiteUrl().getUrl(), serverConfig.getSecureSiteUrl().getUrl())).thenReturn("server_info");
    GoApiResponse response = processor.process(pluginDescriptor, request);
    assertThat(response.responseCode(), is(200));
    assertThat(response.responseBody(), is("server_info"));
}
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 15 with DefaultGoApiRequest

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

the class ServerInfoRequestProcessorTest method shouldRouteToTheRightExtensionBasedOnTheRequest_WhenAPluginHasMultipleExtensions.

@Test
public void shouldRouteToTheRightExtensionBasedOnTheRequest_WhenAPluginHasMultipleExtensions() throws Exception {
    GoPluginExtension anotherPluginExtension = mock(GoPluginExtension.class);
    processor = new ServerInfoRequestProcessor(processorRegistry, goConfigService, Arrays.asList(this.pluginExtension, anotherPluginExtension));
    DefaultGoApiRequest requestFromExtension1 = new DefaultGoApiRequest(GET_SERVER_ID, "1.0", new GoPluginIdentifier("extension1", Arrays.asList("1.0")));
    setupExpectationsFor(pluginExtension, pluginId, "extension1");
    setupExpectationsFor(anotherPluginExtension, pluginId, "extension2");
    processor.process(pluginDescriptor, requestFromExtension1);
    verify(pluginExtension).serverInfoJSON(pluginId, serverConfig.getServerId(), serverConfig.getSiteUrl().getUrl(), serverConfig.getSecureSiteUrl().getUrl());
    verify(anotherPluginExtension, never()).serverInfoJSON(anyString(), anyString(), anyString(), anyString());
    Mockito.reset(pluginExtension, anotherPluginExtension);
    DefaultGoApiRequest requestFromExtension2 = new DefaultGoApiRequest(GET_SERVER_ID, "1.0", new GoPluginIdentifier("extension2", Arrays.asList("1.0")));
    setupExpectationsFor(pluginExtension, pluginId, "extension1");
    setupExpectationsFor(anotherPluginExtension, pluginId, "extension2");
    processor.process(pluginDescriptor, requestFromExtension2);
    verify(pluginExtension, never()).serverInfoJSON(anyString(), anyString(), anyString(), anyString());
    verify(anotherPluginExtension).serverInfoJSON(pluginId, serverConfig.getServerId(), serverConfig.getSiteUrl().getUrl(), serverConfig.getSecureSiteUrl().getUrl());
    Mockito.reset(pluginExtension, anotherPluginExtension);
}
Also used : GoPluginExtension(com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension) GoPluginIdentifier(com.thoughtworks.go.plugin.api.GoPluginIdentifier) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) 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