use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.
the class PluggableScmServiceTest method shouldCheckConnectionToSCM.
@Test
public void shouldCheckConnectionToSCM() {
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
SCM modifiedSCM = new SCM("scm-id", new PluginConfiguration(pluginId, "1"), configuration);
Result expectedResult = new Result();
expectedResult.withSuccessMessages(Arrays.asList("message"));
when(scmExtension.checkConnectionToSCM(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class))).thenReturn(expectedResult);
Result gotResult = pluggableScmService.checkConnection(modifiedSCM);
verify(scmExtension).checkConnectionToSCM(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class));
assertSame(expectedResult, gotResult);
}
use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.
the class PluggableScmServiceTest method shouldValidateMandatoryFieldsForSCM.
@Test
public void shouldValidateMandatoryFieldsForSCM() {
Configuration configuration = new Configuration(ConfigurationPropertyMother.create("KEY1"));
SCM modifiedSCM = new SCM("scm-id", new PluginConfiguration(pluginId, "1"), configuration);
ValidationResult validationResult = new ValidationResult();
when(scmExtension.isSCMConfigurationValid(eq(modifiedSCM.getPluginConfiguration().getId()), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
when(localizer.localize("MANDATORY_CONFIGURATION_FIELD")).thenReturn("MANDATORY_CONFIGURATION_FIELD");
pluggableScmService.validate(modifiedSCM);
final List<ValidationError> validationErrors = validationResult.getErrors();
assertFalse(validationErrors.isEmpty());
final ValidationError validationError = getValidationErrorFor(validationErrors, "KEY1");
assertNotNull(validationError);
assertThat(validationError.getMessage(), is("MANDATORY_CONFIGURATION_FIELD"));
}
use of com.thoughtworks.go.domain.config.PluginConfiguration in project gocd by gocd.
the class PluggableScmServiceTest method isValidShouldMapPluginValidationErrorsToPluggableSCMConfigurations.
@Test
public void isValidShouldMapPluginValidationErrorsToPluggableSCMConfigurations() {
PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
Configuration configuration = new Configuration();
configuration.add(ConfigurationPropertyMother.create("url", false, "url"));
configuration.add(ConfigurationPropertyMother.create("username", false, "admin"));
ValidationResult validationResult = new ValidationResult();
validationResult.addError(new ValidationError("url", "invalid"));
validationResult.addError(new ValidationError("username", "invalid"));
SCM scmConfig = mock(SCM.class);
when(scmConfig.doesPluginExist()).thenReturn(true);
when(scmConfig.getPluginConfiguration()).thenReturn(pluginConfiguration);
when(scmConfig.getConfiguration()).thenReturn(configuration);
when(scmExtension.isSCMConfigurationValid(any(String.class), any(SCMPropertyConfiguration.class))).thenReturn(validationResult);
assertFalse(pluggableScmService.isValid(scmConfig));
assertThat(configuration.getProperty("url").errors().get("url").get(0), is("invalid"));
assertThat(configuration.getProperty("username").errors().get("username").get(0), is("invalid"));
}
use of com.thoughtworks.go.domain.config.PluginConfiguration 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");
}
use of com.thoughtworks.go.domain.config.PluginConfiguration 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")));
}
Aggregations