Search in sources :

Example 21 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 22 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 23 with PackageDefinition

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

the class UpdatePackageConfigCommand method isRequestFresh.

private boolean isRequestFresh() {
    PackageDefinition oldPackage = goConfigService.getConfigForEditing().getPackageRepositories().findPackageDefinitionWith(oldPackageId);
    boolean freshRequest = entityHashingService.md5ForEntity(oldPackage).equals(md5);
    if (!freshRequest) {
        result.stale(LocalizedMessage.string("STALE_RESOURCE_CONFIG", "package", oldPackage.getId()));
    }
    return freshRequest;
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition)

Example 24 with PackageDefinition

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

the class PackageDefinitionCreatorTest method setup.

@Before
public void setup() {
    packageDefinitionService = mock(PackageDefinitionService.class);
    doNothing().when(packageDefinitionService).performPluginValidationsFor(any(PackageDefinition.class));
    cruiseConfig = mock(BasicCruiseConfig.class);
    packageRepository = PackageRepositoryMother.create(repoId);
    packageDefinition = PackageDefinitionMother.create(pkgId);
    packageRepository.addPackage(packageDefinition);
    when(cruiseConfig.getPackageRepositories()).thenReturn(new PackageRepositories(packageRepository));
    doNothing().when(cruiseConfig).savePackageDefinition(any(PackageDefinition.class));
}
Also used : PackageDefinitionService(com.thoughtworks.go.server.service.materials.PackageDefinitionService) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) Before(org.junit.Before)

Example 25 with PackageDefinition

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

the class PackageDefinitionCreatorTest method testGetPackageDefinition.

@Test
public void testGetPackageDefinition() throws Exception {
    HashMap<String, Serializable> params = PackageDefinitionMother.paramsForPackageMaterialAssociation(repoId, pkgId);
    PackageDefinitionCreator packageDefinitionCreator = new PackageDefinitionCreator(packageDefinitionService, params);
    PackageDefinition fetchedPackageDefinition = packageDefinitionCreator.getPackageDefinition(cruiseConfig);
    assertThat(fetchedPackageDefinition.getId(), is(pkgId));
}
Also used : Serializable(java.io.Serializable) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Test(org.junit.Test)

Aggregations

PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)68 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)7 Serializable (java.io.Serializable)7 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)6 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 Matchers.containsString (org.hamcrest.Matchers.containsString)4 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)3 Username (com.thoughtworks.go.server.domain.Username)3 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)2 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)2