Search in sources :

Example 11 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class PackageDefinitionServiceTest method shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository.

@Test
public void shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository() throws Exception {
    Configuration configuration = new Configuration();
    configuration.add(ConfigurationPropertyMother.create("required", false, ""));
    configuration.add(ConfigurationPropertyMother.create("required_secure", true, ""));
    configuration.add(ConfigurationPropertyMother.create("secure", true, ""));
    configuration.add(ConfigurationPropertyMother.create("not_required_not_secure", false, ""));
    configuration.add(ConfigurationPropertyMother.create("spec", false, "xyz?"));
    PackageDefinition packageDefinition = PackageDefinitionMother.create("1", "name", configuration, packageRepository);
    ValidationResult expectedValidationResult = new ValidationResult();
    expectedValidationResult.addError(new ValidationError("spec", "invalid spec"));
    when(packageRepositoryExtension.isPackageConfigurationValid(eq(packageRepository.getPluginConfiguration().getId()), any(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration.class), any(RepositoryConfiguration.class))).thenReturn(expectedValidationResult);
    service.performPluginValidationsFor(packageDefinition);
    assertThat(packageDefinition.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("mandatory field")));
    assertThat(packageDefinition.getConfiguration().get(1).getEncryptedConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("mandatory field")));
    assertThat(packageDefinition.getConfiguration().get(2).getEncryptedConfigurationValue().errors().isEmpty(), is(true));
    assertThat(packageDefinition.getConfiguration().get(3).getConfigurationValue().errors().isEmpty(), is(true));
    assertThat(packageDefinition.getConfiguration().get(4).getConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("invalid spec")));
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PackageMaterialTestHelper.assertPackageConfiguration(com.thoughtworks.go.server.service.materials.PackageMaterialTestHelper.assertPackageConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PackageMaterialTestHelper.assertPackageConfiguration(com.thoughtworks.go.server.service.materials.PackageMaterialTestHelper.assertPackageConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) Test(org.junit.Test)

Example 12 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class PackageRepositoryServiceTest method shouldInvokePluginValidationsBeforeSavingPackageRepository.

@Test
public void shouldInvokePluginValidationsBeforeSavingPackageRepository() throws Exception {
    String pluginId = "yum";
    PackageRepository packageRepository = new PackageRepository();
    RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, new PackageConfigurations());
    packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, "1.0"));
    packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("url", false, "junk-url"));
    ArgumentCaptor<RepositoryConfiguration> packageConfigurationsArgumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
    ValidationResult expectedValidationResult = new ValidationResult();
    expectedValidationResult.addError(new ValidationError("url", "url format incorrect"));
    when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(new GoPluginDescriptor("yum", "1.0", null, null, null, true));
    when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), packageConfigurationsArgumentCaptor.capture())).thenReturn(expectedValidationResult);
    service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, mock(Localizer.class));
    service.performPluginValidationsFor(packageRepository);
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("url format incorrect")));
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 13 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class PackageRepositoryServiceTest method shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository.

@Test
public void shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository() throws Exception {
    // metadata setup
    String pluginId = "yum";
    PackageConfigurations repositoryConfiguration = new PackageConfigurations();
    repositoryConfiguration.add(new PackageConfiguration("required").with(PackageConfiguration.REQUIRED, true));
    repositoryConfiguration.add(new PackageConfiguration("required_secure").with(PackageConfiguration.REQUIRED, true).with(PackageConfiguration.SECURE, true));
    repositoryConfiguration.add(new PackageConfiguration("secure").with(PackageConfiguration.SECURE, true).with(PackageConfiguration.REQUIRED, false));
    repositoryConfiguration.add(new PackageConfiguration("not_required_not_secure"));
    RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, repositoryConfiguration);
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, "1.0"));
    packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("required", false, ""));
    packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("required_secure", true, ""));
    packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("secure", true, ""));
    packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("not_required_not_secure", false, ""));
    when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), any(RepositoryConfiguration.class))).thenReturn(new ValidationResult());
    when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(new GoPluginDescriptor(pluginId, "1.0", null, null, null, true));
    when(localizer.localize("MANDATORY_CONFIGURATION_FIELD")).thenReturn("mandatory field");
    service.performPluginValidationsFor(packageRepository);
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("mandatory field")));
    assertThat(packageRepository.getConfiguration().get(1).getEncryptedConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("mandatory field")));
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 14 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class PackageRepositoryServiceTest method shouldUpdatePluginVersionWhenValid.

@Test
public void shouldUpdatePluginVersionWhenValid() {
    String pluginId = "valid";
    RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, new PackageConfigurations());
    when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(new GoPluginDescriptor(pluginId, "1.0", null, null, null, true));
    when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), any(RepositoryConfiguration.class))).thenReturn(new ValidationResult());
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, ""));
    service.performPluginValidationsFor(packageRepository);
    assertThat(packageRepository.getPluginConfiguration().getVersion(), is("1.0"));
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 15 with ValidationResult

use of com.thoughtworks.go.plugin.api.response.validation.ValidationResult in project gocd by gocd.

the class PluggableScmServiceTest method isValidShouldMapPluginValidationErrorsToPluggableSCMForMissingConfigurations.

@Test
public void isValidShouldMapPluginValidationErrorsToPluggableSCMForMissingConfigurations() {
    PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(new ValidationError("url", "URL is a required field"));
    SCM scmConfig = mock(SCM.class);
    when(scmConfig.doesPluginExist()).thenReturn(true);
    when(scmConfig.getPluginConfiguration()).thenReturn(pluginConfiguration);
    when(scmConfig.getConfiguration()).thenReturn(new Configuration());
    when(scmExtension.isSCMConfigurationValid(any(String.class), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
    assertFalse(pluggableScmService.isValid(scmConfig));
    verify(scmConfig).addError("url", "URL is a required field");
}
Also used : Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) SCM(com.thoughtworks.go.domain.scm.SCM) Test(org.junit.Test)

Aggregations

ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)85 Test (org.junit.Test)69 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)43 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)17 Configuration (com.thoughtworks.go.domain.config.Configuration)14 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)11 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)11 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)10 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)10 PluginSettings (com.thoughtworks.go.server.domain.PluginSettings)9 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)7 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)7 SCM (com.thoughtworks.go.domain.scm.SCM)7 DefaultGoPluginApiResponse (com.thoughtworks.go.plugin.api.response.DefaultGoPluginApiResponse)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)5 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)5 Username (com.thoughtworks.go.server.domain.Username)5 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)4 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)3