Search in sources :

Example 71 with PackageRepository

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

the class MagicalGoConfigXmlWriterTest method shouldAllowPackageTypeMaterialForPipeline.

@Test
public void shouldAllowPackageTypeMaterialForPipeline() 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")));
    String packageId = "id";
    PackageDefinition expectedPackageDefinition = new PackageDefinition(packageId, "name", new Configuration(getConfigurationProperty("name", false, "go-agent")));
    expectedPackageDefinition.setRepository(packageRepository);
    packageRepository.getPackages().add(expectedPackageDefinition);
    cruiseConfig.getPackageRepositories().add(packageRepository);
    PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig(packageId);
    packageMaterialConfig.setPackageDefinition(expectedPackageDefinition);
    JobConfig jobConfig = new JobConfig("ls");
    jobConfig.addTask(new AntTask());
    cruiseConfig.addPipeline("default", com.thoughtworks.go.helper.PipelineConfigMother.pipelineConfig("test", new MaterialConfigs(packageMaterialConfig), new JobConfigs(jobConfig)));
    xmlWriter.write(cruiseConfig, output, false);
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(output.toString());
    PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("test"));
    assertThat(pipelineConfig.materialConfigs().get(0) instanceof PackageMaterialConfig, is(true));
    assertThat(((PackageMaterialConfig) pipelineConfig.materialConfigs().get(0)).getPackageId(), is(packageId));
    PackageDefinition packageDefinition = goConfigHolder.config.getPackageRepositories().first().getPackages().first();
    assertThat(((PackageMaterialConfig) pipelineConfig.materialConfigs().get(0)).getPackageDefinition(), is(packageDefinition));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 72 with PackageRepository

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

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

the class PackageDefinitionCreator method getPackageDefinition.

public PackageDefinition getPackageDefinition(CruiseConfig cruiseConfig) {
    Map packageDefinitionMap = (Map) params.get(PACKAGE_DEFINITION);
    String repositoryId = (String) packageDefinitionMap.get(REPOSITORY_ID);
    PackageRepository packageRepository = cruiseConfig.getPackageRepositories().find(repositoryId);
    PackageDefinition packageDefinition = null;
    if (packageRepository != null) {
        packageDefinition = packageRepository.findPackage((String) params.get(PACKAGE_ID));
    }
    return packageDefinition;
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Map(java.util.Map)

Example 74 with PackageRepository

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

the class CreatePackageConfigCommandTest method shouldValidateIfPackageNameIsNull.

@Test
public void shouldValidateIfPackageNameIsNull() {
    PackageDefinition pkg = new PackageDefinition("Id", null, new Configuration());
    PackageRepository repository = new PackageRepository(repoId, null, null, null);
    repository.addPackage(pkg);
    cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
    CreatePackageConfigCommand command = new CreatePackageConfigCommand(goConfigService, pkg, repoId, currentUser, result, packageDefinitionService);
    assertFalse(command.isValid(cruiseConfig));
    assertThat(pkg.errors().getAllOn("name"), is(Arrays.asList("Package name is mandatory")));
}
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 75 with PackageRepository

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

the class CreatePackageConfigCommandTest method shouldValidateDuplicatePackageName.

@Test
public void shouldValidateDuplicatePackageName() throws Exception {
    PackageRepository repository = cruiseConfig.getPackageRepositories().find(repoId);
    PackageDefinition pkg = new PackageDefinition("Id", "prettyjson", new Configuration());
    pkg.setRepository(repository);
    repository.addPackage(pkg);
    cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
    CreatePackageConfigCommand command = new CreatePackageConfigCommand(goConfigService, packageDefinition, repoId, currentUser, result, packageDefinitionService);
    command.update(cruiseConfig);
    assertFalse(command.isValid(cruiseConfig));
    assertThat(packageDefinition.errors().size(), is(1));
    assertThat(packageDefinition.errors().firstError(), is("You have defined multiple packages called 'prettyjson'. Package names are case-insensitive and must be unique within a repository."));
}
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)

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