use of com.thoughtworks.go.domain.packagerepository.PackageRepository 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.domain.packagerepository.PackageRepository in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldWriteRepositoryConfigurationWithPackagesWhenNoRepoAndPkgIdIsProvided.
@Test
public void shouldWriteRepositoryConfigurationWithPackagesWhenNoRepoAndPkgIdIsProvided() throws Exception {
PackageRepository packageRepository = new PackageRepository();
packageRepository.setName("name");
packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-id", "version"));
packageRepository.setConfiguration(new Configuration(getConfigurationProperty("url", false, "http://go"), getConfigurationProperty("secure", true, "secure")));
PackageDefinition packageDefinition = new PackageDefinition(null, "name", new Configuration(getConfigurationProperty("name", false, "go-agent")));
packageDefinition.setRepository(packageRepository);
packageRepository.getPackages().add(packageDefinition);
cruiseConfig.getPackageRepositories().add(packageRepository);
xmlWriter.write(cruiseConfig, output, false);
GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(output.toString());
PackageRepositories packageRepositories = goConfigHolder.config.getPackageRepositories();
assertThat(packageRepositories.size(), is(cruiseConfig.getPackageRepositories().size()));
assertThat(packageRepositories.get(0).getId(), is(notNullValue()));
assertThat(packageRepositories.get(0).getPackages().size(), is(1));
assertThat(packageRepositories.get(0).getPackages().get(0).getId(), is(notNullValue()));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class PackageDefinitionCreator method getPackageDefinition.
public PackageDefinition getPackageDefinition(CruiseConfig cruiseConfig) {
Map packageDefinitionMap = (Map) params.get(PACKAGE_DEFINITION);
String repositoryId = (String) packageDefinitionMap.get(REPOSITORY_ID);
PackageRepository packageRepository = cruiseConfig.getPackageRepositories().find(repositoryId);
PackageDefinition packageDefinition = null;
if (packageRepository != null) {
packageDefinition = packageRepository.findPackage((String) params.get(PACKAGE_ID));
}
return packageDefinition;
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class CreatePackageConfigCommandTest method shouldValidateIfPackageNameIsNull.
@Test
public void shouldValidateIfPackageNameIsNull() {
PackageDefinition pkg = new PackageDefinition("Id", null, new Configuration());
PackageRepository repository = new PackageRepository(repoId, null, null, null);
repository.addPackage(pkg);
cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
CreatePackageConfigCommand command = new CreatePackageConfigCommand(goConfigService, pkg, repoId, currentUser, result, packageDefinitionService);
assertFalse(command.isValid(cruiseConfig));
assertThat(pkg.errors().getAllOn("name"), is(Arrays.asList("Package name is mandatory")));
}
use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.
the class CreatePackageConfigCommandTest method shouldValidateDuplicatePackageName.
@Test
public void shouldValidateDuplicatePackageName() throws Exception {
PackageRepository repository = cruiseConfig.getPackageRepositories().find(repoId);
PackageDefinition pkg = new PackageDefinition("Id", "prettyjson", new Configuration());
pkg.setRepository(repository);
repository.addPackage(pkg);
cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
CreatePackageConfigCommand command = new CreatePackageConfigCommand(goConfigService, packageDefinition, repoId, currentUser, result, packageDefinitionService);
command.update(cruiseConfig);
assertFalse(command.isValid(cruiseConfig));
assertThat(packageDefinition.errors().size(), is(1));
assertThat(packageDefinition.errors().firstError(), is("You have defined multiple packages called 'prettyjson'. Package names are case-insensitive and must be unique within a repository."));
}
Aggregations