use of com.thoughtworks.go.domain.packagerepository.PackageDefinition in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldAllowPackageTypeMaterialForPipeline.
@Test
public void shouldAllowPackageTypeMaterialForPipeline() throws Exception {
CruiseConfig configToSave = new BasicCruiseConfig();
PackageRepository packageRepository = new PackageRepository();
packageRepository.setId("id");
packageRepository.setName("name");
packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-id", "version"));
packageRepository.setConfiguration(new Configuration(getConfigurationProperty("url", false, "http://go")));
String packageId = "id";
PackageDefinition expectedPackageDefinition = new PackageDefinition(packageId, "name", new Configuration(getConfigurationProperty("name", false, "go-agent")));
expectedPackageDefinition.setRepository(packageRepository);
packageRepository.getPackages().add(expectedPackageDefinition);
configToSave.getPackageRepositories().add(packageRepository);
PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig(packageId);
packageMaterialConfig.setPackageDefinition(expectedPackageDefinition);
configToSave.addPipeline("default", com.thoughtworks.go.helper.PipelineConfigMother.pipelineConfig("test", new MaterialConfigs(packageMaterialConfig), new JobConfigs(new JobConfig("ls"))));
xmlWriter.write(configToSave, output, false);
GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(output.toString());
PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("test"));
assertThat(pipelineConfig.materialConfigs().get(0) instanceof PackageMaterialConfig, is(true));
assertThat(((PackageMaterialConfig) pipelineConfig.materialConfigs().get(0)).getPackageId(), is(packageId));
PackageDefinition packageDefinition = goConfigHolder.config.getPackageRepositories().first().getPackages().first();
assertThat(((PackageMaterialConfig) pipelineConfig.materialConfigs().get(0)).getPackageDefinition(), is(packageDefinition));
}
use of com.thoughtworks.go.domain.packagerepository.PackageDefinition in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldWriteRepositoryConfigurationWithPackagesWhenNoRepoAndPkgIdIsProvided.
@Test
public void shouldWriteRepositoryConfigurationWithPackagesWhenNoRepoAndPkgIdIsProvided() throws Exception {
CruiseConfig configToSave = new BasicCruiseConfig();
PackageRepository packageRepository = new PackageRepository();
packageRepository.setName("name");
packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-id", "version"));
packageRepository.setConfiguration(new Configuration(getConfigurationProperty("url", false, "http://go"), getConfigurationProperty("secure", true, "secure")));
PackageDefinition packageDefinition = new PackageDefinition(null, "name", new Configuration(getConfigurationProperty("name", false, "go-agent")));
packageDefinition.setRepository(packageRepository);
packageRepository.getPackages().add(packageDefinition);
configToSave.getPackageRepositories().add(packageRepository);
xmlWriter.write(configToSave, output, false);
GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(output.toString());
PackageRepositories packageRepositories = goConfigHolder.config.getPackageRepositories();
assertThat(packageRepositories.size(), is(configToSave.getPackageRepositories().size()));
assertThat(packageRepositories.get(0).getId(), is(notNullValue()));
assertThat(packageRepositories.get(0).getPackages().size(), is(1));
assertThat(packageRepositories.get(0).getPackages().get(0).getId(), is(notNullValue()));
}
use of com.thoughtworks.go.domain.packagerepository.PackageDefinition in project gocd by gocd.
the class MagicalGoConfigXmlLoaderTest method shouldBeAbleToResolveSecureConfigPropertiesForPackages.
@Test
public void shouldBeAbleToResolveSecureConfigPropertiesForPackages() throws Exception {
String encryptedValue = new GoCipher().encrypt("secure-two");
String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<repositories>\n" + " <repository id='repo-id' name='name'>\n" + " <pluginConfiguration id='plugin-id' version='1.0'/>\n" + " <configuration>\n" + " <property>\n" + " <key>plain</key>\n" + " <value>value</value>\n" + " </property>\n" + " <property>\n" + " <key>secure-one</key>\n" + " <value>secure-value</value>\n" + " </property>\n" + " <property>\n" + " <key>secure-two</key>\n" + " <encryptedValue>" + encryptedValue + "</encryptedValue>\n" + " </property>\n" + " </configuration>\n" + " <packages>\n" + " <package id='package-id' name='name'>\n" + " <configuration>\n" + " <property>\n" + " <key>plain</key>\n" + " <value>value</value>\n" + " </property>\n" + " <property>\n" + " <key>secure-one</key>\n" + " <value>secure-value</value>\n" + " </property>\n" + " <property>\n" + " <key>secure-two</key>\n" + " <encryptedValue>" + encryptedValue + "</encryptedValue>\n" + " </property>\n" + " </configuration>\n" + " </package>\n" + " </packages>\n" + " </repository>\n" + " </repositories>" + "<pipelines group=\"group_name\">\n" + " <pipeline name=\"new_name\">\n" + " <materials>\n" + " <package ref='package-id' />\n" + " </materials>\n" + " <stage name=\"stage_name\">\n" + " <jobs>\n" + " <job name=\"job_name\" />\n" + " </jobs>\n" + " </stage>\n" + " </pipeline>\n" + "</pipelines></cruise>";
// meta data of package
PackageConfigurations packageConfigurations = new PackageConfigurations();
packageConfigurations.addConfiguration(new PackageConfiguration("plain"));
packageConfigurations.addConfiguration(new PackageConfiguration("secure-one").with(PackageConfiguration.SECURE, true));
packageConfigurations.addConfiguration(new PackageConfiguration("secure-two").with(PackageConfiguration.SECURE, true));
PackageMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
RepositoryMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml);
PackageDefinition packageDefinition = goConfigHolder.config.getPackageRepositories().first().getPackages().first();
PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("new_name"));
PackageMaterialConfig packageMaterialConfig = (PackageMaterialConfig) pipelineConfig.materialConfigs().get(0);
assertThat(packageMaterialConfig.getPackageDefinition(), is(packageDefinition));
Configuration repoConfig = packageMaterialConfig.getPackageDefinition().getRepository().getConfiguration();
assertThat(repoConfig.get(0).getConfigurationValue().getValue(), is("value"));
assertThat(repoConfig.get(1).getEncryptedValue(), is(new GoCipher().encrypt("secure-value")));
assertThat(repoConfig.get(2).getEncryptedValue(), is(encryptedValue));
Configuration packageConfig = packageMaterialConfig.getPackageDefinition().getConfiguration();
assertThat(packageConfig.get(0).getConfigurationValue().getValue(), is("value"));
assertThat(packageConfig.get(1).getEncryptedValue(), is(new GoCipher().encrypt("secure-value")));
assertThat(packageConfig.get(2).getEncryptedValue(), is(encryptedValue));
}
use of com.thoughtworks.go.domain.packagerepository.PackageDefinition in project gocd by gocd.
the class MagicalGoConfigXmlLoaderTest method shouldResolvePackageRepoReferenceElementForAPackageInConfig.
@Test
public void shouldResolvePackageRepoReferenceElementForAPackageInConfig() throws Exception {
String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<repositories>\n" + " <repository id='repo-id' name='name'>\n" + " <pluginConfiguration id='plugin-id' version='1.0'/>\n" + " <configuration>\n" + " <property>\n" + " <key>url</key>\n" + " <value>http://go</value>\n" + " </property>\n" + " </configuration>\n" + " <packages>\n" + " <package id='package-id' name='name'>\n" + " <configuration>\n" + " <property>\n" + " <key>name</key>\n" + " <value>go-agent</value>\n" + " </property>\n" + " </configuration>\n" + " </package>\n" + " </packages>\n" + " </repository>\n" + " </repositories></cruise>";
GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(xml);
PackageRepository packageRepository = goConfigHolder.config.getPackageRepositories().first();
PackageDefinition packageDefinition = packageRepository.getPackages().first();
assertThat(packageDefinition.getRepository(), is(packageRepository));
}
use of com.thoughtworks.go.domain.packagerepository.PackageDefinition in project gocd by gocd.
the class MaterialsMother method packageMaterial.
public static PackageMaterial packageMaterial(String repoId, String repoName, String pkgId, String pkgName, final String pluginid, final String version, List<ConfigurationProperty> repoProperties, List<ConfigurationProperty> packageProperties) {
PackageRepository repository = PackageRepositoryMother.create(repoId, repoName, pluginid, version, new Configuration((ConfigurationProperty[]) repoProperties.toArray()));
PackageDefinition packageDefinition = PackageDefinitionMother.create(pkgId, pkgName, new Configuration((ConfigurationProperty[]) packageProperties.toArray()), repository);
repository.getPackages().add(packageDefinition);
PackageMaterial material = new PackageMaterial(pkgId);
material.setId(1);
material.setPackageDefinition(packageDefinition);
return material;
}
Aggregations