use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class GoConfigGraphWalkerTest method shouldNotWalkPackageDefinitionWhileTraversingPackageMaterial.
@Test
public void shouldNotWalkPackageDefinitionWhileTraversingPackageMaterial() {
PackageDefinition packageDefinition = mock(PackageDefinition.class);
PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig("package-id");
setField(packageMaterialConfig, "packageDefinition", packageDefinition);
BasicCruiseConfig config = new BasicCruiseConfig();
PackageRepository packageRepository = mock(PackageRepository.class);
when(packageRepository.getPackages()).thenReturn(new Packages(packageDefinition));
when(packageDefinition.getRepository()).thenReturn(packageRepository);
when(packageRepository.doesPluginExist()).thenReturn(true);
when(packageDefinition.getId()).thenReturn("package-id");
config.getPackageRepositories().add(packageRepository);
final ConfigSaveValidationContext context = new ConfigSaveValidationContext(config);
new GoConfigGraphWalker(packageMaterialConfig).walk(new GoConfigGraphWalker.Handler() {
@Override
public void handle(Validatable validatable, ValidationContext ctx) {
validatable.validate(context);
}
});
verify(packageDefinition, never()).validate(any(ValidationContext.class));
}
use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class PipelineGroups method getPackageUsageInPipelines.
public Map<String, List<Pair<PipelineConfig, PipelineConfigs>>> getPackageUsageInPipelines() {
if (packageToPipelineMap == null) {
synchronized (this) {
if (packageToPipelineMap == null) {
packageToPipelineMap = new HashMap<>();
for (PipelineConfigs pipelineConfigs : this) {
for (PipelineConfig pipelineConfig : pipelineConfigs) {
for (PackageMaterialConfig packageMaterialConfig : pipelineConfig.packageMaterialConfigs()) {
String packageId = packageMaterialConfig.getPackageId();
if (!packageToPipelineMap.containsKey(packageId)) {
packageToPipelineMap.put(packageId, new ArrayList<>());
}
packageToPipelineMap.get(packageId).add(new Pair<>(pipelineConfig, pipelineConfigs));
}
}
}
}
}
}
return packageToPipelineMap;
}
use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class DeletePackageRepositoryCommandTest method shouldNotDeletePackageRepositoryIfItIsUsedAsAMaterialInPipeline.
@Test
public void shouldNotDeletePackageRepositoryIfItIsUsedAsAMaterialInPipeline() throws Exception {
PackageDefinition pkg = new PackageDefinition();
pkg.setId("pkg");
packageRepository.addPackage(pkg);
PackageMaterialConfig packageMaterial = new PackageMaterialConfig("pkg");
PipelineConfig pipeline = new PipelineConfig();
pipeline.setMaterialConfigs(new MaterialConfigs(packageMaterial));
cruiseConfig.addPipeline("first", pipeline);
assertThat(cruiseConfig.getPackageRepositories().size(), is(1));
assertThat(cruiseConfig.getPackageRepositories().find(repoId), is(packageRepository));
DeletePackageRepositoryCommand command = new DeletePackageRepositoryCommand(goConfigService, packageRepository, currentUser, result);
command.update(cruiseConfig);
assertFalse(command.isValid(cruiseConfig));
}
use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class ConfigConverterTest method shouldConvertPackageMaterial.
@Test
public void shouldConvertPackageMaterial() {
PackageRepositories repositories = new PackageRepositories();
PackageRepository packageRepository = new PackageRepository();
PackageDefinition definition = new PackageDefinition("package-id", "n", new Configuration());
packageRepository.addPackage(definition);
repositories.add(packageRepository);
BasicCruiseConfig cruiseConfig = new BasicCruiseConfig();
cruiseConfig.setPackageRepositories(repositories);
when(cachedGoConfig.currentConfig()).thenReturn(cruiseConfig);
CRPackageMaterial crPackageMaterial = new CRPackageMaterial("name", "package-id");
PackageMaterialConfig packageMaterialConfig = (PackageMaterialConfig) configConverter.toMaterialConfig(crPackageMaterial, context);
assertThat(packageMaterialConfig.getName().toLower(), is("name"));
assertThat(packageMaterialConfig.getPackageId(), is("package-id"));
assertThat(packageMaterialConfig.getPackageDefinition(), is(definition));
}
use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class PipelineConfigTest method shouldGetPackageMaterialConfigs.
@Test
public void shouldGetPackageMaterialConfigs() throws Exception {
SvnMaterialConfig svn = new SvnMaterialConfig("svn", false);
PackageMaterialConfig packageMaterialOne = new PackageMaterialConfig();
PackageMaterialConfig packageMaterialTwo = new PackageMaterialConfig();
PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("p1", new MaterialConfigs(svn, packageMaterialOne, packageMaterialTwo));
List<PackageMaterialConfig> packageMaterialConfigs = pipelineConfig.packageMaterialConfigs();
assertThat(packageMaterialConfigs.size(), is(2));
assertThat(packageMaterialConfigs, hasItems(packageMaterialOne, packageMaterialTwo));
}
Aggregations