assert contentSource != null;
int contentSourceId = contentSource.getId();
assert contentSourceId > 0;
// create a repo and associate the new content source with it
Repo repo = new Repo("testMergeWithRepo");
repo = repoManager.createRepo(overlord, repo);
repoManager.addContentSourcesToRepo(overlord, repo.getId(), new int[] { contentSourceId });
// this report will add a mapping to PV->CS
// we didn't set up any mappings like that yet - this will be the first one
// since a repo has this CS - the repo->PV will also get mapped
PackageSyncReport report = new PackageSyncReport();
ContentProviderPackageDetailsKey key = new ContentProviderPackageDetailsKey("testMergeWithRepofoo",
"testMergeWithRepo-Version", packageType1.getName(), architecture1.getName(), resourceType1.getName(),
resourceType1.getPlugin());
ContentProviderPackageDetails details = new ContentProviderPackageDetails(key);
details.setExtraProperties(new Configuration());
details.getExtraProperties().put(new PropertySimple("hello", "world"));
details.setLocation("dummy-location");
details.setFileSize(0L); // under the covers this ends up allowing us to create a package bits of size 0
report.addNewPackage(details);
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous;
previous = new HashMap<ContentProviderPackageDetailsKey, PackageVersionContentSource>();
RepoSyncResults results = new RepoSyncResults(repo);
results = repoManager.persistRepoSyncResults(results);
assert results != null;
contentSourceManager.mergePackageSyncReport(contentSource, repo, report, previous, results);
List<PackageVersion> inRepo;
inRepo = repoManager.findPackageVersionsInRepo(overlord, repo.getId(), PageControl.getUnlimitedInstance());
assert inRepo != null;
assert inRepo.size() == 1;
assert "testMergeWithRepo-Version".equals(inRepo.get(0).getVersion());
// sanity check - make sure our own entity manager can find the PV entity
getTransactionManager().begin();
try {
PackageVersion foundPv = getEntityManager().find(PackageVersion.class, inRepo.get(0).getId());
assert foundPv != null;
assert foundPv.getExtraProperties() != null;
assert foundPv.getExtraProperties().getSimple("hello").getStringValue().equals("world");
} finally {
getTransactionManager().rollback();
}
// delete the content source first
contentSourceManager.deleteContentSource(overlord, contentSourceId);
// make sure our PV isn't orphaned yet! It is directly related to the repo still
getTransactionManager().begin();
try {
assert null != getEntityManager().find(PackageVersion.class, inRepo.get(0).getId());
} finally {
getTransactionManager().rollback();
}
// delete the repo - this finally orphans the PV, so the PV should get deleted automatically
repoManager.deleteRepo(overlord, repo.getId());
// test to make sure we purged the orphaned package version (since both content source and repo are gone now)
getTransactionManager().begin();
try {
assert null == getEntityManager().find(PackageVersion.class, inRepo.get(0).getId());