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);
}
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'."));
}
}
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));
}
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));
}
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")));
}
Aggregations