Search in sources :

Example 6 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 7 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 8 with PackageMaterialConfig

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)));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PipelineConfigMother.createPipelineConfig(com.thoughtworks.go.helper.PipelineConfigMother.createPipelineConfig) StringContains.containsString(org.hamcrest.core.StringContains.containsString) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) MergePipelineConfigs(com.thoughtworks.go.config.merge.MergePipelineConfigs) Pair(com.thoughtworks.go.util.Pair) Test(org.junit.Test)

Example 9 with PackageMaterialConfig

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

Example 10 with PackageMaterialConfig

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

Aggregations

PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)27 Test (org.junit.Test)22 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