use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldPopulateErrorsForCheckConnectionOnPlugin.
@Test
void shouldPopulateErrorsForCheckConnectionOnPlugin() {
String pluginId = "yum";
PackageRepository packageRepository = packageRepository(pluginId);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
PackageRepositoryService service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, secretParamResolver);
ArgumentCaptor<RepositoryConfiguration> argumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
when(packageRepositoryExtension.checkConnectionToRepository(eq(pluginId), argumentCaptor.capture())).thenReturn(new Result().withErrorMessages("Repo invalid!!", "Could not connect"));
service.checkConnection(packageRepository, result);
RepositoryConfiguration packageConfigurations = argumentCaptor.getValue();
PackageMaterialTestHelper.assertPackageConfiguration(packageConfigurations.list(), packageRepository.getConfiguration());
assertThat(result.isSuccessful()).isFalse();
assertThat(result.message()).isEqualTo("Could not connect to package repository. Reason(s): Repo invalid!!\nCould not connect");
verify(packageRepositoryExtension).checkConnectionToRepository(eq(pluginId), any(RepositoryConfiguration.class));
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageDefinitionServiceTest method shouldPerformCheckConnectionOnPackage.
@Test
void shouldPerformCheckConnectionOnPackage() 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);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
PackageDefinitionService service = new PackageDefinitionService(packageRepositoryExtension, entityHashingService, goConfigService, secretParamResolver);
ArgumentCaptor<com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration> packageConfigurationsCaptor = ArgumentCaptor.forClass(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration.class);
ArgumentCaptor<RepositoryConfiguration> packageRepositoryConfigurationsCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
when(packageRepositoryExtension.checkConnectionToPackage(eq(packageRepository.getPluginConfiguration().getId()), packageConfigurationsCaptor.capture(), packageRepositoryConfigurationsCaptor.capture())).thenReturn(new Result().withSuccessMessages("Got Package!!!"));
service.checkConnection(packageDefinition, result);
assertPackageConfiguration(packageConfigurationsCaptor.getValue().list(), packageDefinition.getConfiguration());
assertPackageConfiguration(packageRepositoryConfigurationsCaptor.getValue().list(), packageRepository.getConfiguration());
assertThat(result.isSuccessful()).isTrue();
assertThat(result.message()).isEqualTo("OK. Got Package!!!");
verify(packageRepositoryExtension).checkConnectionToPackage(anyString(), any(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration.class), any(RepositoryConfiguration.class));
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class PackageRepositoryService method populateConfiguration.
private RepositoryConfiguration populateConfiguration(Configuration configuration) {
RepositoryConfiguration repositoryConfiguration = new RepositoryConfiguration();
for (ConfigurationProperty configurationProperty : configuration) {
String value = configurationProperty.getValue();
repositoryConfiguration.add(new PackageMaterialProperty(configurationProperty.getConfigurationKey().getName(), value));
}
return repositoryConfiguration;
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class MagicalGoConfigXmlLoaderTest method shouldFailValidationIfPackageDefinitionWithDuplicateFingerprintExists.
@Test
void shouldFailValidationIfPackageDefinitionWithDuplicateFingerprintExists() {
com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageConfiguration = new com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration();
packageConfiguration.add(new PackageMaterialProperty("PKG-KEY1"));
RepositoryConfiguration repositoryConfiguration = new RepositoryConfiguration();
repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY1"));
repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY2").with(REQUIRED, false).with(PART_OF_IDENTITY, false));
repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY3").with(REQUIRED, false).with(PART_OF_IDENTITY, false).with(SECURE, true));
PackageMetadataStore.getInstance().addMetadataFor("plugin-1", new PackageConfigurations(packageConfiguration));
RepositoryMetadataStore.getInstance().addMetadataFor("plugin-1", new PackageConfigurations(repositoryConfiguration));
String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<repositories>\n" + " <repository id='repo-id-1' name='name-1'>\n" + " <pluginConfiguration id='plugin-1' version='1.0'/>\n" + " <configuration>\n" + " <property>\n" + " <key>REPO-KEY1</key>\n" + " <value>repo-key1</value>\n" + " </property>\n" + " <property>\n" + " <key>REPO-KEY2</key>\n" + " <value>repo-key2</value>\n" + " </property>\n" + " <property>\n" + " <key>REPO-KEY3</key>\n" + " <value>repo-key3</value>\n" + " </property>\n" + " </configuration>\n" + " <packages>\n" + " <package id='package-id-1' name='name-1'>\n" + " <configuration>\n" + " <property>\n" + " <key>PKG-KEY1</key>\n" + " <value>pkg-key1</value>\n" + " </property>\n" + " </configuration>\n" + " </package>\n" + " </packages>\n" + " </repository>\n" + " <repository id='repo-id-2' name='name-2'>\n" + " <pluginConfiguration id='plugin-1' version='1.0'/>\n" + " <configuration>\n" + " <property>\n" + " <key>REPO-KEY1</key>\n" + " <value>repo-key1</value>\n" + " </property>\n" + " <property>\n" + " <key>REPO-KEY2</key>\n" + " <value>another-repo-key2</value>\n" + " </property>\n" + " <property>\n" + " <key>REPO-KEY3</key>\n" + " <value>another-repo-key3</value>\n" + " </property>\n" + " </configuration>\n" + " <packages>\n" + " <package id='package-id-2' name='name-2'>\n" + " <configuration>\n" + " <property>\n" + " <key>PKG-KEY1</key>\n" + " <value>pkg-key1</value>\n" + " </property>\n" + " </configuration>\n" + " </package>\n" + " </packages>\n" + " </repository>\n" + " </repositories>" + "</cruise>";
assertFailureDuringLoad(xml, GoConfigInvalidException.class, "Cannot save package or repo, found duplicate packages. [Repo Name: 'name-1', Package Name: 'name-1'], [Repo Name: 'name-2', Package Name: 'name-2']");
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration in project gocd by gocd.
the class JsonMessageHandler1_0 method responseMessageForRepositoryConfiguration.
@Override
public RepositoryConfiguration responseMessageForRepositoryConfiguration(String responseBody) {
try {
RepositoryConfiguration repositoryConfiguration = new RepositoryConfiguration();
Map<String, Map> configurations;
try {
configurations = parseResponseToMap(responseBody);
} catch (Exception e) {
throw new RuntimeException("Repository configuration should be returned as a map");
}
if (configurations == null || configurations.isEmpty()) {
throw new RuntimeException("Empty response body");
}
for (String key : configurations.keySet()) {
if (isEmpty(key)) {
throw new RuntimeException("Repository configuration key cannot be empty");
}
if (!(configurations.get(key) instanceof Map)) {
throw new RuntimeException(format("Repository configuration properties for key '%s' should be represented as a Map", key));
}
repositoryConfiguration.add(toPackageMaterialProperty(key, configurations.get(key)));
}
return repositoryConfiguration;
} catch (Exception e) {
throw new RuntimeException(format("Unable to de-serialize json response. %s", e.getMessage()));
}
}
Aggregations