Search in sources :

Example 11 with Packages

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

the class GoConfigGraphWalkerTest method shouldNotWalkPackageDefinitionWhileTraversingPackageMaterial.

@Test
public void shouldNotWalkPackageDefinitionWhileTraversingPackageMaterial() {
    PackageDefinition packageDefinition = mock(PackageDefinition.class);
    PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig("package-id");
    setField(packageMaterialConfig, "packageDefinition", packageDefinition);
    BasicCruiseConfig config = new BasicCruiseConfig();
    PackageRepository packageRepository = mock(PackageRepository.class);
    when(packageRepository.getPackages()).thenReturn(new Packages(packageDefinition));
    when(packageDefinition.getRepository()).thenReturn(packageRepository);
    when(packageRepository.doesPluginExist()).thenReturn(true);
    when(packageDefinition.getId()).thenReturn("package-id");
    config.getPackageRepositories().add(packageRepository);
    final ConfigSaveValidationContext context = new ConfigSaveValidationContext(config);
    new GoConfigGraphWalker(packageMaterialConfig).walk(new GoConfigGraphWalker.Handler() {

        @Override
        public void handle(Validatable validatable, ValidationContext ctx) {
            validatable.validate(context);
        }
    });
    verify(packageDefinition, never()).validate(any(ValidationContext.class));
}
Also used : PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Example 12 with Packages

use of com.thoughtworks.go.domain.packagerepository.Packages 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"));
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    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.Test)

Example 13 with Packages

use of com.thoughtworks.go.domain.packagerepository.Packages 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 14 with Packages

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

the class PackageConfigCommand method isValid.

public boolean isValid(CruiseConfig preprocessedConfig, String repositoryId) {
    PackageRepositories packageRepositories = preprocessedConfig.getPackageRepositories();
    PackageRepository repository = packageRepositories.find(repositoryId);
    Packages packages = repository.getPackages();
    preprocessedPackageDefinition = packages.find(this.packageDefinition.getId());
    preprocessedPackageDefinition.validate(null);
    if (preprocessedPackageDefinition.getAllErrors().isEmpty()) {
        packageRepositories.validate(null);
        packages.validate(null);
        packageDefinitionService.validatePackageConfiguration(preprocessedPackageDefinition);
        BasicCruiseConfig.copyErrors(preprocessedPackageDefinition, packageDefinition);
        return preprocessedPackageDefinition.getAllErrors().isEmpty() && result.isSuccessful();
    }
    BasicCruiseConfig.copyErrors(preprocessedPackageDefinition, packageDefinition);
    return false;
}
Also used : Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository)

Aggregations

Packages (com.thoughtworks.go.domain.packagerepository.Packages)14 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)13 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)12 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)12 Test (org.junit.Test)12 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)1 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)1 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)1 GoCipher (com.thoughtworks.go.security.GoCipher)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1