Search in sources :

Example 31 with PackageDefinition

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

the class PackageMaterialUpdateWithNewPackageDefinitionCommand method updateConfig.

@Override
protected void updateConfig(CruiseConfig cruiseConfig) {
    PackageDefinition packageDefinition = createNewPackageDefinition(cruiseConfig);
    packageMaterialConfig = (PackageMaterialConfig) cruiseConfig.pipelineConfigByName(new CaseInsensitiveString(pipeline)).materialConfigs().get(packageMaterialConfig);
    packageMaterialConfig.setPackageDefinition(packageDefinition);
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Example 32 with PackageDefinition

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

the class UpdatePackageConfigCommandTest method shouldValidateDuplicateIdentity.

@Test
public void shouldValidateDuplicateIdentity() throws Exception {
    PackageRepository repository = cruiseConfig.getPackageRepositories().find("repoId");
    PackageDefinition pkg = new PackageDefinition("Id", "name", configuration);
    pkg.setRepository(repository);
    repository.addPackage(pkg);
    cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
    UpdatePackageConfigCommand command = new UpdatePackageConfigCommand(goConfigService, packageUuid, newPackageDefinition, currentUser, "md5", this.entityHashingService, result, packageDefinitionService);
    command.update(cruiseConfig);
    assertFalse(command.isValid(cruiseConfig));
    assertThat(newPackageDefinition.errors().size(), is(1));
    assertThat(newPackageDefinition.errors().firstError(), is("Cannot save package or repo, found duplicate packages. [Repo Name: 'repoName', Package Name: 'name'], [Repo Name: 'repoName', Package Name: 'prettyjson']"));
}
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.Test)

Example 33 with PackageDefinition

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

the class UpdatePackageRepositoryCommandTest method shouldCopyPackagesFromOldRepositoryToTheUpdatedRepository.

@Test
public void shouldCopyPackagesFromOldRepositoryToTheUpdatedRepository() throws Exception {
    PackageDefinition nodePackage = new PackageDefinition("foo", "bar", new Configuration());
    oldPackageRepo.setPackages(new Packages(nodePackage));
    UpdatePackageRepositoryCommand command = new UpdatePackageRepositoryCommand(goConfigService, packageRepositoryService, newPackageRepo, currentUser, "md5", entityHashingService, result, repoId);
    assertThat(cruiseConfig.getPackageRepositories().find(repoId), is(oldPackageRepo));
    assertThat(cruiseConfig.getPackageRepositories().find(repoId).getPackages().size(), is(1));
    assertThat(newPackageRepo.getPackages().size(), is(0));
    command.update(cruiseConfig);
    HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
    assertThat(result, is(expectedResult));
    assertThat(cruiseConfig.getPackageRepositories().find(repoId), is(newPackageRepo));
    assertThat(cruiseConfig.getPackageRepositories().find(repoId).getPackages().size(), is(1));
    assertThat(cruiseConfig.getPackageRepositories().find(repoId).getPackages().first(), is(nodePackage));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) Test(org.junit.Test)

Example 34 with PackageDefinition

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

the class CreatePackageConfigCommandTest method setup.

@Before
public void setup() throws Exception {
    initMocks(this);
    currentUser = new Username(new CaseInsensitiveString("user"));
    result = new HttpLocalizedOperationResult();
    cruiseConfig = new GoConfigMother().defaultCruiseConfig();
    packageId = "prettyjson";
    packageUuid = "random-uuid";
    configuration = new Configuration(new ConfigurationProperty(new ConfigurationKey("PACKAGE_ID"), new ConfigurationValue(packageId)));
    packageDefinition = new PackageDefinition(packageUuid, "prettyjson", configuration);
    PackageRepositories repositories = cruiseConfig.getPackageRepositories();
    repoId = "repoId";
    Configuration configuration = new Configuration(new ConfigurationProperty(new ConfigurationKey("foo"), new ConfigurationValue("bar")));
    PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin-id", "1");
    repository = new PackageRepository(repoId, "repoName", pluginConfiguration, configuration);
    repositories.add(repository);
    cruiseConfig.setPackageRepositories(repositories);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Before(org.junit.Before)

Example 35 with PackageDefinition

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

the class CreatePackageConfigCommandTest method shouldValidateIfPackageNameIsInvalid.

@Test
public void shouldValidateIfPackageNameIsInvalid() {
    PackageRepository repository = cruiseConfig.getPackageRepositories().find(repoId);
    PackageDefinition pkg = new PackageDefinition("Id", "!$#", new Configuration());
    pkg.setRepository(repository);
    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("Invalid Package name '!$#'. 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) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Aggregations

PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)69 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)9 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)7 Serializable (java.io.Serializable)7 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 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)3 SCM (com.thoughtworks.go.domain.scm.SCM)3 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)3 Username (com.thoughtworks.go.server.domain.Username)3 Timestamp (java.sql.Timestamp)3