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 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 PipelineGroupsTest method shouldGetPackageUsageInPipelines.
@Test
public void shouldGetPackageUsageInPipelines() throws Exception {
PackageMaterialConfig packageOne = new PackageMaterialConfig("package-id-one");
PackageMaterialConfig packageTwo = new PackageMaterialConfig("package-id-two");
final PipelineConfig p1 = PipelineConfigMother.pipelineConfig("pipeline1", new MaterialConfigs(packageOne, packageTwo), new JobConfigs(new JobConfig(new CaseInsensitiveString("jobName"))));
final PipelineConfig p2 = PipelineConfigMother.pipelineConfig("pipeline2", new MaterialConfigs(packageTwo), new JobConfigs(new JobConfig(new CaseInsensitiveString("jobName"))));
PipelineGroups groups = new PipelineGroups();
PipelineConfigs groupOne = new BasicPipelineConfigs(p1);
PipelineConfigs groupTwo = new BasicPipelineConfigs(p2);
groups.addAll(asList(groupOne, groupTwo));
Map<String, List<Pair<PipelineConfig, PipelineConfigs>>> packageToPipelineMap = groups.getPackageUsageInPipelines();
assertThat(packageToPipelineMap.get("package-id-one").size(), is(1));
assertThat(packageToPipelineMap.get("package-id-one"), hasItems(new Pair<>(p1, groupOne)));
assertThat(packageToPipelineMap.get("package-id-two").size(), is(2));
assertThat(packageToPipelineMap.get("package-id-two"), hasItems(new Pair<>(p1, groupOne), new Pair<>(p2, groupTwo)));
}
use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class PackageMaterialAddWithExistingPackageDefinitionCommandTest method shouldHandleDeletedPackageDefinition.
@Test
public void shouldHandleDeletedPackageDefinition() {
PackageDefinition packageDefinition = cruiseConfig.getPackageRepositories().get(0).getPackages().get(0);
String repoId = packageDefinition.getRepository().getId();
String pkgId = "deleted-package-definition";
HashMap<String, Serializable> params = PackageDefinitionMother.paramsForPackageMaterialAssociation(repoId, pkgId);
PackageMaterialConfig materialToBeCreated = new PackageMaterialConfig();
PackageMaterialAddWithExistingPackageDefinitionCommand command = new PackageMaterialAddWithExistingPackageDefinitionCommand(packageDefinitionService, securityService, pipelineName, materialToBeCreated, admin, params);
command.update(cruiseConfig);
PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
assertThat(pipelineConfig.materialConfigs().last() instanceof PackageMaterialConfig, is(true));
PackageMaterialConfig packageMaterial = (PackageMaterialConfig) pipelineConfig.materialConfigs().last();
assertThat(packageMaterial, is(materialToBeCreated));
assertThat(packageMaterial.getPackageDefinition(), is(nullValue()));
assertThat(packageMaterial.getPackageId(), is(nullValue()));
verify(packageDefinitionService, never()).performPluginValidationsFor(Matchers.<PackageDefinition>any());
}
use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.
the class PackageMaterialAddWithExistingPackageDefinitionCommandTest method shouldUpdateConfigWithNewMaterial.
@Test
public void shouldUpdateConfigWithNewMaterial() {
PackageDefinition packageDefinition = cruiseConfig.getPackageRepositories().get(0).getPackages().get(0);
String repoId = packageDefinition.getRepository().getId();
String pkgId = packageDefinition.getId();
HashMap<String, Serializable> params = PackageDefinitionMother.paramsForPackageMaterialAssociation(repoId, pkgId);
PackageMaterialConfig materialToBeCreated = new PackageMaterialConfig();
PackageMaterialAddWithExistingPackageDefinitionCommand command = new PackageMaterialAddWithExistingPackageDefinitionCommand(packageDefinitionService, securityService, pipelineName, materialToBeCreated, admin, params);
command.update(cruiseConfig);
PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipelineName));
assertThat(pipelineConfig.materialConfigs().last() instanceof PackageMaterialConfig, is(true));
PackageMaterialConfig packageMaterial = (PackageMaterialConfig) pipelineConfig.materialConfigs().last();
assertThat(packageMaterial, is(materialToBeCreated));
assertThat(packageMaterial.getPackageDefinition(), is(packageDefinition));
verify(packageDefinitionService, never()).performPluginValidationsFor(packageDefinition);
}
Aggregations