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']"));
}
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));
}
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;
}
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));
}
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));
}
Aggregations