Search in sources :

Example 11 with PackageMaterialConfig

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));
}
Also used : PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Example 12 with PackageMaterialConfig

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;
}
Also used : PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig)

Example 13 with PackageMaterialConfig

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));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Test(org.junit.Test)

Example 14 with PackageMaterialConfig

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));
}
Also used : PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Example 15 with PackageMaterialConfig

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));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) Test(org.junit.Test)

Aggregations

PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)27 Test (org.junit.Test)23 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)13 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)11 Serializable (java.io.Serializable)10 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)7 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)7 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)5 Configuration (com.thoughtworks.go.domain.config.Configuration)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 MergePipelineConfigs (com.thoughtworks.go.config.merge.MergePipelineConfigs)2 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)2 PipelineConfigMother.createPipelineConfig (com.thoughtworks.go.helper.PipelineConfigMother.createPipelineConfig)2 Pair (com.thoughtworks.go.util.Pair)2 Arrays.asList (java.util.Arrays.asList)2 HashMap (java.util.HashMap)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)1 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1