Search in sources :

Example 31 with PackageRepository

use of com.thoughtworks.go.domain.packagerepository.PackageRepository 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"));
    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));
}
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.jupiter.api.Test)

Example 32 with PackageRepository

use of com.thoughtworks.go.domain.packagerepository.PackageRepository 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"));
    PackageRepository packageRepository = createPackageRepository("plugin-id", "version", "id", "name with space", repositoryConfiguration, new Packages(new PackageDefinition("id", "name", packageConfiguration)));
    cruiseConfig.setPackageRepositories(new PackageRepositories(packageRepository));
    try {
        xmlWriter.write(cruiseConfig, 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, hyphens 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.jupiter.api.Test)

Example 33 with PackageRepository

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

the class MagicalGoConfigXmlLoaderTest method shouldLoadAutoUpdateValueForPackageWhenLoadedFromConfigFile.

@Test
void shouldLoadAutoUpdateValueForPackageWhenLoadedFromConfigFile() throws Exception {
    String configTemplate = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>" + "<repositories>" + "	<repository id='2ef830d7-dd66-42d6-b393-64a84646e557' name='GoYumRepo'>" + "		<pluginConfiguration id='yum' version='1' />" + "       <configuration>" + "           <property>" + "               <key>REPO_URL</key>" + "               <value>http://fake-yum-repo/go/yum/no-arch</value>" + "               </property>" + "       </configuration>" + "	    <packages>" + "           <package id='88a3beca-cbe2-4c4d-9744-aa0cda3f371c' name='1' autoUpdate='%s'>" + "               <configuration>" + "                   <property>" + "                       <key>REPO_URL</key>" + "                       <value>http://fake-yum-repo/go/yum/no-arch</value>" + "                   </property>" + "               </configuration>" + "           </package>" + "	     </packages>" + "   </repository>" + "</repositories>" + "</cruise>";
    String configContent = String.format(configTemplate, false);
    GoConfigHolder holder = xmlLoader.loadConfigHolder(configContent);
    PackageRepository packageRepository = holder.config.getPackageRepositories().find("2ef830d7-dd66-42d6-b393-64a84646e557");
    PackageDefinition aPackage = packageRepository.findPackage("88a3beca-cbe2-4c4d-9744-aa0cda3f371c");
    assertThat(aPackage.isAutoUpdate()).isFalse();
    configContent = String.format(configTemplate, true);
    holder = xmlLoader.loadConfigHolder(configContent);
    packageRepository = holder.config.getPackageRepositories().find("2ef830d7-dd66-42d6-b393-64a84646e557");
    aPackage = packageRepository.findPackage("88a3beca-cbe2-4c4d-9744-aa0cda3f371c");
    assertThat(aPackage.isAutoUpdate()).isTrue();
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 34 with PackageRepository

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

the class RulesService method validateSecretConfigReferences.

public void validateSecretConfigReferences(PackageMaterial packageMaterial) {
    PackageRepository pkgRepository = packageMaterial.getPackageDefinition().getRepository();
    Map<CaseInsensitiveString, StringBuilder> errors = validate(packageMaterial.getSecretParams(), pkgRepository.getClass(), pkgRepository.getName(), "Package Material");
    if (!errors.isEmpty()) {
        throw new RulesViolationException(errorString(errors));
    }
}
Also used : RulesViolationException(com.thoughtworks.go.server.exceptions.RulesViolationException) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository)

Example 35 with PackageRepository

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

the class PackageRepositoryRepresenter method fromJSON.

public static PackageRepository fromJSON(JsonReader jsonReader) {
    PackageRepository packageRepository = new PackageRepository();
    jsonReader.readStringIfPresent("id", packageRepository::setId);
    jsonReader.readStringIfPresent("name", packageRepository::setName);
    return packageRepository;
}
Also used : PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository)

Aggregations

PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)89 Test (org.junit.jupiter.api.Test)46 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)40 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)39 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)23 Packages (com.thoughtworks.go.domain.packagerepository.Packages)13 Username (com.thoughtworks.go.server.domain.Username)13 Test (org.junit.Test)13 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)9 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)7 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)7 BeforeEach (org.junit.jupiter.api.BeforeEach)6 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)5 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)5 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)5 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)5 XsdValidationException (com.thoughtworks.go.util.XsdValidationException)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)4