Search in sources :

Example 16 with PackageMaterialConfig

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

the class PackageMaterialUpdateWithExistingPackageDefinitionCommandTest method shouldUpdateMaterialWithExistingPackageDefinition.

@Test
public void shouldUpdateMaterialWithExistingPackageDefinition() {
    PackageDefinition packageDefinition = cruiseConfig.getPackageRepositories().get(0).getPackages().get(1);
    String repoId = packageDefinition.getRepository().getId();
    String pkgId = packageDefinition.getId();
    HashMap<String, Serializable> params = PackageDefinitionMother.paramsForPackageMaterialAssociation(repoId, pkgId);
    PackageMaterialUpdateWithExistingPackageDefinitionCommand command = new PackageMaterialUpdateWithExistingPackageDefinitionCommand(packageDefinitionService, securityService, pipelineName, materialToBeUpdated, admin, params);
    command.update(cruiseConfig);
    assertThat(pipelineConfig.materialConfigs().first() instanceof PackageMaterialConfig, is(true));
    PackageMaterialConfig editedMaterial = (PackageMaterialConfig) pipelineConfig.materialConfigs().first();
    assertThat(editedMaterial, is(materialToBeUpdated));
    assertThat(editedMaterial.getPackageDefinition(), is(packageDefinition));
    verify(packageDefinitionService, never()).performPluginValidationsFor(packageDefinition);
}
Also used : Serializable(java.io.Serializable) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 17 with PackageMaterialConfig

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

the class PackageMaterialUpdateWithNewPackageDefinitionCommandTest method shouldHandleDeletedPackageRepo.

@Test
public void shouldHandleDeletedPackageRepo() {
    String repoId = "deleted-repo";
    String pkgName = "pkg-2";
    HashMap<String, Serializable> params = PackageDefinitionMother.paramsForPackageMaterialCreation(repoId, pkgName);
    PackageMaterialUpdateWithNewPackageDefinitionCommand command = new PackageMaterialUpdateWithNewPackageDefinitionCommand(packageDefinitionService, securityService, pipelineName, materialToBeUpdated, admin, params);
    command.update(cruiseConfig);
    assertThat(pipelineConfig.materialConfigs().first() instanceof PackageMaterialConfig, is(true));
    PackageMaterialConfig editedMaterial = (PackageMaterialConfig) pipelineConfig.materialConfigs().first();
    assertThat(editedMaterial, is(materialToBeUpdated));
    assertThat(editedMaterial.getPackageDefinition(), is(notNullValue()));
    assertThat(editedMaterial.getPackageDefinition().getId(), is(nullValue()));
    assertThat(editedMaterial.getPackageDefinition().getRepository(), is(nullValue()));
    assertThat(editedMaterial.getPackageDefinition().getName(), is(pkgName));
    assertThat(editedMaterial.getPackageDefinition().getConfiguration().size(), is(0));
    verify(packageDefinitionService, never()).performPluginValidationsFor(editedMaterial.getPackageDefinition());
}
Also used : Serializable(java.io.Serializable) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 18 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 19 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 {
    CruiseConfig configToSave = new BasicCruiseConfig();
    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);
    configToSave.getPackageRepositories().add(packageRepository);
    PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig(packageId);
    packageMaterialConfig.setPackageDefinition(expectedPackageDefinition);
    configToSave.addPipeline("default", com.thoughtworks.go.helper.PipelineConfigMother.pipelineConfig("test", new MaterialConfigs(packageMaterialConfig), new JobConfigs(new JobConfig("ls"))));
    xmlWriter.write(configToSave, 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.Test)

Example 20 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 {
    CruiseConfig configToSave = new BasicCruiseConfig();
    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));
    configToSave.addPipeline("default", com.thoughtworks.go.helper.PipelineConfigMother.pipelineConfig("test", new MaterialConfigs(packageMaterialConfig), new JobConfigs(new JobConfig("ls"))));
    try {
        xmlWriter.write(configToSave, 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) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) 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