Search in sources :

Example 1 with PluginSettingsConfiguration

use of com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration in project gocd by gocd.

the class AuthenticationExtensionTest method shouldTalkToPluginToGetPluginSettingsConfiguration.

@Test
public void shouldTalkToPluginToGetPluginSettingsConfiguration() throws Exception {
    PluginSettingsConfiguration deserializedResponse = new PluginSettingsConfiguration();
    when(pluginSettingsJSONMessageHandler.responseMessageForPluginSettingsConfiguration(RESPONSE_BODY)).thenReturn(deserializedResponse);
    PluginSettingsConfiguration response = authenticationExtension.getPluginSettingsConfiguration(PLUGIN_ID);
    assertRequest(requestArgumentCaptor.getValue(), AuthenticationExtension.EXTENSION_NAME, "1.0", PluginSettingsConstants.REQUEST_PLUGIN_SETTINGS_CONFIGURATION, null);
    verify(pluginSettingsJSONMessageHandler).responseMessageForPluginSettingsConfiguration(RESPONSE_BODY);
    assertSame(response, deserializedResponse);
}
Also used : PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) Test(org.junit.Test)

Example 2 with PluginSettingsConfiguration

use of com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration in project gocd by gocd.

the class PluginService method validatePluginSettingsFor.

public void validatePluginSettingsFor(PluginSettings pluginSettings) {
    String pluginId = pluginSettings.getPluginId();
    PluginSettingsConfiguration configuration = pluginSettings.toPluginSettingsConfiguration();
    ValidationResult result = null;
    boolean anyExtensionSupportsPluginId = false;
    for (GoPluginExtension extension : extensions) {
        if (extension.canHandlePlugin(pluginId)) {
            result = extension.validatePluginSettings(pluginId, configuration);
            anyExtensionSupportsPluginId = true;
        }
    }
    if (!anyExtensionSupportsPluginId)
        throw new IllegalArgumentException(String.format("Plugin '%s' is not supported by any extension point", pluginId));
    if (!result.isSuccessful()) {
        for (ValidationError error : result.getErrors()) {
            pluginSettings.populateErrorMessageFor(error.getKey(), error.getMessage());
        }
    }
}
Also used : GoPluginExtension(com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult)

Example 3 with PluginSettingsConfiguration

use of com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration in project gocd by gocd.

the class TaskExtensionTest method shouldTalkToPluginToGetPluginSettingsConfiguration.

@Test
public void shouldTalkToPluginToGetPluginSettingsConfiguration() throws Exception {
    extension.registerHandler("1.0", pluginSettingsJSONMessageHandler);
    extension.messageHandlerMap.put("1.0", jsonMessageHandler);
    String responseBody = "expected-response";
    PluginSettingsConfiguration deserializedResponse = new PluginSettingsConfiguration();
    when(pluginSettingsJSONMessageHandler.responseMessageForPluginSettingsConfiguration(responseBody)).thenReturn(deserializedResponse);
    when(pluginManager.isPluginOfType(TaskExtension.TASK_EXTENSION, pluginId)).thenReturn(true);
    when(pluginManager.submitTo(eq(pluginId), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
    PluginSettingsConfiguration response = extension.getPluginSettingsConfiguration(pluginId);
    assertRequest(requestArgumentCaptor.getValue(), TaskExtension.TASK_EXTENSION, "1.0", PluginSettingsConstants.REQUEST_PLUGIN_SETTINGS_CONFIGURATION, null);
    verify(pluginSettingsJSONMessageHandler).responseMessageForPluginSettingsConfiguration(responseBody);
    assertSame(response, deserializedResponse);
}
Also used : PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) Test(org.junit.Test)

Example 4 with PluginSettingsConfiguration

use of com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration in project gocd by gocd.

the class PackageRepositoryExtensionTest method shouldTalkToPluginToGetPluginSettingsConfiguration.

@Test
public void shouldTalkToPluginToGetPluginSettingsConfiguration() throws Exception {
    extension.registerHandler("1.0", pluginSettingsJSONMessageHandler);
    extension.messageHandlerMap.put("1.0", jsonMessageHandler);
    String responseBody = "expected-response";
    PluginSettingsConfiguration deserializedResponse = new PluginSettingsConfiguration();
    when(pluginSettingsJSONMessageHandler.responseMessageForPluginSettingsConfiguration(responseBody)).thenReturn(deserializedResponse);
    when(pluginManager.isPluginOfType(EXTENSION_NAME, PLUGIN_ID)).thenReturn(true);
    when(pluginManager.submitTo(eq(PLUGIN_ID), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
    PluginSettingsConfiguration response = extension.getPluginSettingsConfiguration(PLUGIN_ID);
    assertRequest(requestArgumentCaptor.getValue(), EXTENSION_NAME, "1.0", PluginSettingsConstants.REQUEST_PLUGIN_SETTINGS_CONFIGURATION, null);
    verify(pluginSettingsJSONMessageHandler).responseMessageForPluginSettingsConfiguration(responseBody);
    assertSame(response, deserializedResponse);
}
Also used : PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) Test(org.junit.Test)

Example 5 with PluginSettingsConfiguration

use of com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration in project gocd by gocd.

the class SCMExtensionTest method shouldTalkToPluginToGetPluginSettingsConfiguration.

@Test
public void shouldTalkToPluginToGetPluginSettingsConfiguration() throws Exception {
    PluginSettingsConfiguration deserializedResponse = new PluginSettingsConfiguration();
    when(pluginSettingsJSONMessageHandler.responseMessageForPluginSettingsConfiguration(responseBody)).thenReturn(deserializedResponse);
    PluginSettingsConfiguration response = scmExtension.getPluginSettingsConfiguration(PLUGIN_ID);
    assertRequest(requestArgumentCaptor.getValue(), SCMExtension.EXTENSION_NAME, "1.0", PluginSettingsConstants.REQUEST_PLUGIN_SETTINGS_CONFIGURATION, null);
    verify(pluginSettingsJSONMessageHandler).responseMessageForPluginSettingsConfiguration(responseBody);
    assertSame(response, deserializedResponse);
}
Also used : PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) Test(org.junit.Test)

Aggregations

PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)14 Test (org.junit.Test)7 Before (org.junit.Before)6 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)5 PluginSettingsProperty (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsProperty)2 NullPlugin (com.thoughtworks.go.domain.NullPlugin)1 Plugin (com.thoughtworks.go.domain.Plugin)1 GoPluginExtension (com.thoughtworks.go.plugin.access.common.settings.GoPluginExtension)1 PackageMaterialProperty (com.thoughtworks.go.plugin.api.material.packagerepository.PackageMaterialProperty)1 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)1 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)1 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1