use of com.thoughtworks.go.domain.packagerepository.Packages in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldNotAllowMultipleRepositoriesWithSameId.
@Test
public void shouldNotAllowMultipleRepositoriesWithSameId() throws Exception {
Configuration packageConfiguration = new Configuration(getConfigurationProperty("name", false, "go-agent"));
Configuration repositoryConfiguration = new Configuration(getConfigurationProperty("url", false, "http://go"));
CruiseConfig configToSave = new BasicCruiseConfig();
PackageRepository packageRepository = createPackageRepository("plugin-id-1", "version", "id", "name1", repositoryConfiguration, new Packages(new PackageDefinition("id", "name", packageConfiguration)));
PackageRepository anotherPackageRepository = createPackageRepository("plugin-id-2", "version", "id", "name2", repositoryConfiguration, new Packages(new PackageDefinition("id", "name", packageConfiguration)));
configToSave.setPackageRepositories(new PackageRepositories(packageRepository, anotherPackageRepository));
try {
xmlWriter.write(configToSave, output, false);
fail("should not have allowed two repositories with same id");
} catch (XsdValidationException e) {
assertThat(e.getMessage(), is("Duplicate unique value [id] declared for identity constraint \"uniqueRepositoryId\" of element \"repositories\"."));
}
}
use of com.thoughtworks.go.domain.packagerepository.Packages in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldNotAllowPackagesWithInvalidId.
@Test
public void shouldNotAllowPackagesWithInvalidId() throws Exception {
Configuration packageConfiguration = new Configuration(getConfigurationProperty("name", false, "go-agent"));
Configuration repositoryConfiguration = new Configuration(getConfigurationProperty("url", false, "http://go"));
CruiseConfig configToSave = new BasicCruiseConfig();
PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", repositoryConfiguration, new Packages(new PackageDefinition("id with space", "name", packageConfiguration)));
configToSave.setPackageRepositories(new PackageRepositories(packageRepository));
try {
xmlWriter.write(configToSave, output, false);
fail("should not have allowed two repositories with same id");
} catch (XsdValidationException e) {
assertThat(e.getMessage(), is("Package id is invalid. \"id with space\" should conform to the pattern - [a-zA-Z0-9_\\-]{1}[a-zA-Z0-9_\\-.]*"));
}
}
use of com.thoughtworks.go.domain.packagerepository.Packages in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldNotAllowMultiplePackagesWithSameNameWithinARepo.
@Test
public void shouldNotAllowMultiplePackagesWithSameNameWithinARepo() throws Exception {
Configuration packageConfiguration1 = new Configuration(getConfigurationProperty("name", false, "go-agent"));
Configuration packageConfiguration2 = new Configuration(getConfigurationProperty("name2", false, "go-server"));
Configuration repositoryConfiguration = new Configuration(getConfigurationProperty("url", false, "http://go"));
CruiseConfig configToSave = new BasicCruiseConfig();
PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name", repositoryConfiguration, new Packages(new PackageDefinition("id1", "name", packageConfiguration1), new PackageDefinition("id2", "name", packageConfiguration2)));
configToSave.setPackageRepositories(new PackageRepositories(packageRepository));
try {
xmlWriter.write(configToSave, output, false);
fail("should not have allowed two repositories with same id");
} catch (GoConfigInvalidException e) {
assertThat(e.getMessage(), is("You have defined multiple packages called 'name'. Package names are case-insensitive and must be unique within a repository."));
}
}
use of com.thoughtworks.go.domain.packagerepository.Packages in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldWriteToFileWithValueOfFalseForPackageDefinitionAutoUpdateWhenFalse.
@Test
public void shouldWriteToFileWithValueOfFalseForPackageDefinitionAutoUpdateWhenFalse() throws Exception {
Configuration configuration = new Configuration(getConfigurationProperty("url", false, "http://go"));
CruiseConfig cruiseConfig = new BasicCruiseConfig();
Packages packages = new Packages();
PackageDefinition aPackage = new PackageDefinition("package-id", "package-name", configuration);
aPackage.setAutoUpdate(false);
packages.add(aPackage);
PackageRepository repository = createPackageRepository("plugin-id", "version", "id", "name", configuration, packages);
cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
xmlWriter.write(cruiseConfig, output, false);
assertThat(output.toString().contains("autoUpdate=\"false\""), is(true));
}
use of com.thoughtworks.go.domain.packagerepository.Packages in project gocd by gocd.
the class UpdatePackageRepositoryCommandTest method shouldCopyPackagesFromOldRepositoryToTheUpdatedRepository.
@Test
public void shouldCopyPackagesFromOldRepositoryToTheUpdatedRepository() throws Exception {
PackageDefinition nodePackage = new PackageDefinition("foo", "bar", new Configuration());
oldPackageRepo.setPackages(new Packages(nodePackage));
UpdatePackageRepositoryCommand command = new UpdatePackageRepositoryCommand(goConfigService, packageRepositoryService, newPackageRepo, currentUser, "md5", entityHashingService, result, repoId);
assertThat(cruiseConfig.getPackageRepositories().find(repoId), is(oldPackageRepo));
assertThat(cruiseConfig.getPackageRepositories().find(repoId).getPackages().size(), is(1));
assertThat(newPackageRepo.getPackages().size(), is(0));
command.update(cruiseConfig);
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
assertThat(result, is(expectedResult));
assertThat(cruiseConfig.getPackageRepositories().find(repoId), is(newPackageRepo));
assertThat(cruiseConfig.getPackageRepositories().find(repoId).getPackages().size(), is(1));
assertThat(cruiseConfig.getPackageRepositories().find(repoId).getPackages().first(), is(nodePackage));
}
Aggregations