Search in sources :

Example 31 with PackageMaterialConfig

use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.

the class PipelineGroupsTest method shouldComputePackageUsageInPipelinesOnlyOnce.

@Test
public void shouldComputePackageUsageInPipelinesOnlyOnce() 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();
    groups.addAll(asList(new BasicPipelineConfigs(p1), new BasicPipelineConfigs(p2)));
    Map<String, List<Pair<PipelineConfig, PipelineConfigs>>> result1 = groups.getPackageUsageInPipelines();
    Map<String, List<Pair<PipelineConfig, PipelineConfigs>>> result2 = groups.getPackageUsageInPipelines();
    assertSame(result1, result2);
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PipelineConfigMother.createPipelineConfig(com.thoughtworks.go.helper.PipelineConfigMother.createPipelineConfig) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) MergePipelineConfigs(com.thoughtworks.go.config.merge.MergePipelineConfigs) Test(org.junit.jupiter.api.Test)

Example 32 with PackageMaterialConfig

use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.

the class MagicalGoConfigXmlWriterTest method shouldFailValidationIfPackageTypeMaterialForPipelineHasARefToNonExistantPackage.

@Test
public void shouldFailValidationIfPackageTypeMaterialForPipelineHasARefToNonExistantPackage() throws Exception {
    String packageId = "does-not-exist";
    PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig(packageId);
    PackageRepository repository = com.thoughtworks.go.domain.packagerepository.PackageRepositoryMother.create("repo-id", "repo-name", "pluginid", "version", new Configuration(com.thoughtworks.go.domain.packagerepository.ConfigurationPropertyMother.create("k1", false, "v1")));
    packageMaterialConfig.setPackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinitionMother.create("does-not-exist", "package-name", new Configuration(com.thoughtworks.go.domain.packagerepository.ConfigurationPropertyMother.create("k2", false, "v2")), repository));
    JobConfig jobConfig = new JobConfig("ls");
    jobConfig.addTask(new AntTask());
    cruiseConfig.addPipeline("default", com.thoughtworks.go.helper.PipelineConfigMother.pipelineConfig("test", new MaterialConfigs(packageMaterialConfig), new JobConfigs(jobConfig)));
    try {
        xmlWriter.write(cruiseConfig, output, false);
        fail("should not allow this");
    } catch (XsdValidationException exception) {
        assertThat(exception.getMessage(), is("Key 'packageIdReferredByMaterial' with value 'does-not-exist' not found for identity constraint of element 'cruise'."));
    }
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) XsdValidationException(com.thoughtworks.go.util.XsdValidationException) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 33 with PackageMaterialConfig

use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.

the class MagicalGoConfigXmlWriterTest method shouldAllowPackageTypeMaterialForPipeline.

@Test
public void shouldAllowPackageTypeMaterialForPipeline() throws Exception {
    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);
    cruiseConfig.getPackageRepositories().add(packageRepository);
    PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig(packageId);
    packageMaterialConfig.setPackageDefinition(expectedPackageDefinition);
    JobConfig jobConfig = new JobConfig("ls");
    jobConfig.addTask(new AntTask());
    cruiseConfig.addPipeline("default", com.thoughtworks.go.helper.PipelineConfigMother.pipelineConfig("test", new MaterialConfigs(packageMaterialConfig), new JobConfigs(jobConfig)));
    xmlWriter.write(cruiseConfig, 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));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 34 with PackageMaterialConfig

use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.

the class DeletePackageConfigCommandTest method shouldNotDeletePackageIfItIsUsedAsAMaterialInPipeline.

@Test
public void shouldNotDeletePackageIfItIsUsedAsAMaterialInPipeline() throws Exception {
    MaterialConfigs materialConfigs = new MaterialConfigs(new PackageMaterialConfig(new CaseInsensitiveString("fooPackage"), packageUuid, packageDefinition));
    Map<String, List<Pair<PipelineConfig, PipelineConfigs>>> pipelinesUsingPackages = new HashMap<>();
    Pair<PipelineConfig, PipelineConfigs> pair = new Pair<>(PipelineConfigMother.pipelineConfig("some-pipeline", "stage", materialConfigs), null);
    ArrayList<Pair<PipelineConfig, PipelineConfigs>> pairs = new ArrayList<>();
    pairs.add(pair);
    pipelinesUsingPackages.put(packageUuid, pairs);
    List<String> pipelines = new ArrayList<>();
    pipelines.add("some-pipeline");
    when(goConfigService.getPackageUsageInPipelines()).thenReturn(pipelinesUsingPackages);
    DeletePackageConfigCommand command = new DeletePackageConfigCommand(goConfigService, packageDefinition, currentUser, result);
    command.update(cruiseConfig);
    assertFalse(command.isValid(cruiseConfig));
    HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
    expectedResult.unprocessableEntity(cannotDeleteResourceBecauseOfDependentPipelines("package definition", packageUuid, pipelines));
    assertThat(result, is(expectedResult));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) List(java.util.List) PipelineConfigs(com.thoughtworks.go.config.PipelineConfigs) Pair(com.thoughtworks.go.util.Pair) Test(org.junit.jupiter.api.Test)

Example 35 with PackageMaterialConfig

use of com.thoughtworks.go.config.materials.PackageMaterialConfig in project gocd by gocd.

the class BasicCruiseConfigTest method shouldListAllPipelinesAssociatedWithThePackage.

@Test
public void shouldListAllPipelinesAssociatedWithThePackage() {
    GitMaterialConfig git = git("http://example.com");
    PackageMaterialConfig packageMaterialConfig = packageMaterialConfig();
    PipelineConfig p1 = pipelineConfig("p1", new MaterialConfigs(git, packageMaterialConfig));
    PipelineConfig p2 = pipelineConfig("p2", new MaterialConfigs(git));
    PipelineConfig p3 = pipelineConfig("p3", new MaterialConfigs(packageMaterialConfig));
    PipelineConfigs group1 = createGroup("group1", p1, p2);
    PipelineConfigs group2 = createGroup("group2", p3);
    CruiseConfig config = createCruiseConfig();
    config.setGroup(new PipelineGroups(group1, group2));
    List<PipelineConfig> pipelineConfigs = config.pipelinesAssociatedWithPackage(packageMaterialConfig.getPackageDefinition());
    assertThat(pipelineConfigs.size(), is(2));
    assertThat(pipelineConfigs.get(0).getName(), is(new CaseInsensitiveString("p1")));
    assertThat(pipelineConfigs.get(1).getName(), is(new CaseInsensitiveString("p3")));
}
Also used : PipelineGroups(com.thoughtworks.go.domain.PipelineGroups) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) Test(org.junit.jupiter.api.Test)

Aggregations

PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)40 Test (org.junit.jupiter.api.Test)17 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)14 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)14 Test (org.junit.Test)13 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)12 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)10 Serializable (java.io.Serializable)10 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)6 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)6 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)5 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)4 PipelineGroups (com.thoughtworks.go.domain.PipelineGroups)4 HashMap (java.util.HashMap)4 PipelineConfigs (com.thoughtworks.go.config.PipelineConfigs)3 Configuration (com.thoughtworks.go.domain.config.Configuration)3 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ErrorGetter (com.thoughtworks.go.api.representers.ErrorGetter)2