Search in sources :

Example 6 with PackageDefinition

use of com.thoughtworks.go.domain.packagerepository.PackageDefinition in project gocd by gocd.

the class MagicalGoConfigXmlWriterTest method shouldNotAllowPackagesRepositoryWithInvalidName.

@Test
public void shouldNotAllowPackagesRepositoryWithInvalidName() 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 with space", repositoryConfiguration, new Packages(new PackageDefinition("id", "name", packageConfiguration)));
    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("Invalid PackageRepository name 'name with space'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."));
    }
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.Test)

Example 7 with PackageDefinition

use of com.thoughtworks.go.domain.packagerepository.PackageDefinition in project gocd by gocd.

the class MagicalGoConfigXmlWriterTest method createPackageRepository.

private PackageRepository createPackageRepository(String pluginId, String version, String id, String name, Configuration configuration, Packages packages) {
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.setConfiguration(configuration);
    packageRepository.setPackages(packages);
    packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, version));
    packageRepository.setId(id);
    packageRepository.setName(name);
    for (PackageDefinition aPackage : packages) {
        aPackage.setRepository(packageRepository);
    }
    return packageRepository;
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository)

Example 8 with PackageDefinition

use of com.thoughtworks.go.domain.packagerepository.PackageDefinition 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\"."));
    }
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Example 9 with PackageDefinition

use of com.thoughtworks.go.domain.packagerepository.PackageDefinition 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_\\-.]*"));
    }
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Example 10 with PackageDefinition

use of com.thoughtworks.go.domain.packagerepository.PackageDefinition 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."));
    }
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.Test)

Aggregations

PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)68 Test (org.junit.Test)47 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)41 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)28 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)12 Configuration (com.thoughtworks.go.domain.config.Configuration)12 Packages (com.thoughtworks.go.domain.packagerepository.Packages)12 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)7 Serializable (java.io.Serializable)7 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)6 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)6 Before (org.junit.Before)6 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)3 Username (com.thoughtworks.go.server.domain.Username)3 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)2 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)2