Search in sources :

Example 41 with PackageRepositories

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

the class GoConfigMother method configWithPackageRepo.

public static CruiseConfig configWithPackageRepo(String... ids) throws Exception {
    final CruiseConfig config = new BasicCruiseConfig();
    PackageConfigurations configuration = new PackageConfigurations();
    configuration.addConfiguration(new PackageConfiguration("key1"));
    configuration.addConfiguration(new PackageConfiguration("key2").with(PackageConfiguration.SECURE, true));
    RepositoryMetadataStore.getInstance().addMetadataFor("plugin-1", configuration);
    for (String id : ids) {
        PackageRepository packageRepository = new PackageRepository();
        packageRepository.setId(id);
        packageRepository.setName("name" + id);
        packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-1", "1.0.0"));
        packageRepository.setPackages(new Packages(PackageDefinitionMother.create(id + "-pkg-1", packageRepository), PackageDefinitionMother.create(id + "-pkg-2", packageRepository)));
        GoCipher cipher = new GoCipher();
        ConfigurationProperty p1 = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"));
        ConfigurationProperty p2 = new ConfigurationProperty(new ConfigurationKey("key2"), null, new EncryptedConfigurationValue(cipher.encrypt("value2")), cipher);
        packageRepository.setConfiguration(new Configuration(p1, p2));
        config.setPackageRepositories(new PackageRepositories(packageRepository));
    }
    return config;
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)

Example 42 with PackageRepositories

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

the class MagicalGoConfigXmlWriterTest method shouldNotWriteToFileWithDefaultValueOfTrueForPackageDefinitionAutoUpdateWhenTrue.

@Test
public void shouldNotWriteToFileWithDefaultValueOfTrueForPackageDefinitionAutoUpdateWhenTrue() throws Exception {
    Configuration configuration = new Configuration(getConfigurationProperty("url", false, "http://go"));
    Packages packages = new Packages();
    PackageRepository repository = createPackageRepository("plugin-id", "version", "id", "name", configuration, packages);
    PackageDefinition aPackage = new PackageDefinition("package-id", "package-name", configuration);
    aPackage.setAutoUpdate(true);
    packages.add(aPackage);
    aPackage.setRepository(repository);
    cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
    xmlWriter.write(cruiseConfig, output, false);
    assertThat(output.toString().contains("autoUpdate=\"true\""), is(false));
}
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 43 with PackageRepositories

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

the class MagicalGoConfigXmlWriterTest method shouldWriteRepositoryConfigurationWithPackages.

@Test
public void shouldWriteRepositoryConfigurationWithPackages() 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"), getConfigurationProperty("secure", true, "secure")));
    PackageDefinition packageDefinition = new PackageDefinition("id", "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, is(cruiseConfig.getPackageRepositories()));
    assertThat(packageRepositories.get(0).getConfiguration().first().getConfigurationValue().getValue(), is("http://go"));
    assertThat(packageRepositories.get(0).getConfiguration().first().getEncryptedConfigurationValue(), is(nullValue()));
    assertThat(packageRepositories.get(0).getConfiguration().last().getEncryptedValue(), is(new GoCipher().encrypt("secure")));
    assertThat(packageRepositories.get(0).getConfiguration().last().getConfigurationValue(), is(nullValue()));
    assertThat(packageRepositories.get(0).getPackages().get(0), is(packageDefinition));
    assertThat(packageRepositories.get(0).getPackages().get(0).getConfiguration().first().getConfigurationValue().getValue(), is("go-agent"));
    assertThat(packageRepositories.get(0).getPackages().get(0).getConfiguration().first().getEncryptedConfigurationValue(), is(nullValue()));
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 44 with PackageRepositories

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

Example 45 with PackageRepositories

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

the class DeletePackageConfigCommand method update.

@Override
public void update(CruiseConfig modifiedConfig) {
    PackageRepositories repositories = modifiedConfig.getPackageRepositories();
    PackageRepository packageRepository = repositories.findPackageRepositoryHaving(this.packageDefinition.getId());
    packageRepository.removePackage(this.packageDefinition.getId());
    modifiedConfig.setPackageRepositories(repositories);
}
Also used : PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository)

Aggregations

PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)52 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)40 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)29 Test (org.junit.jupiter.api.Test)29 Packages (com.thoughtworks.go.domain.packagerepository.Packages)14 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)9 Test (org.junit.Test)8 Username (com.thoughtworks.go.server.domain.Username)7 BeforeEach (org.junit.jupiter.api.BeforeEach)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 XsdValidationException (com.thoughtworks.go.util.XsdValidationException)4 ArrayList (java.util.ArrayList)4 Arrays.asList (java.util.Arrays.asList)4 List (java.util.List)4 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)3 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)3 ContextConfiguration (org.springframework.test.context.ContextConfiguration)3 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 GoCipher (com.thoughtworks.go.security.GoCipher)2