assert contentSource != null;
contentSourceId = contentSource.getId();
assert contentSourceId > 0;
// create a repo
Repo repo = new Repo("testRepo");
repo = repoManager.createRepo(overlord, repo);
repoId = repo.getId();
// 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
PackageSyncReport report = new PackageSyncReport();
ContentProviderPackageDetailsKey key = new ContentProviderPackageDetailsKey("testCreateContentSourceFoo",
"testCreateContentSourceVer", packageType1.getName(), architecture1.getName(), resourceType1.getName(),
resourceType1.getPlugin());
ContentProviderPackageDetails details = new ContentProviderPackageDetails(key);
details.setLocation("dummy-location");
details.setMetadata("dummy-metadata".getBytes());
details.addResourceVersion("1.0.0");
details.addResourceVersion("2.0.0");
report.addNewPackage(details);
Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous;
previous = new HashMap<ContentProviderPackageDetailsKey, PackageVersionContentSource>();
// merge the report!
RepoSyncResults results = new RepoSyncResults(repo);
results = repoManager.persistRepoSyncResults(results);
assert results != null;
results = contentSourceManager.mergePackageSyncReport(contentSource, repo, report, previous, results);
assert results != null;
// Verify the product version was created
getTransactionManager().begin();
try {
resourceType1 = em.find(ResourceType.class, resourceType1.getId());
Query productVersionQuery = em.createNamedQuery(ProductVersion.QUERY_FIND_BY_RESOURCE_TYPE_AND_VERSION);
productVersionQuery.setParameter("resourceType", resourceType1);
productVersionQuery.setParameter("version", "1.0.0");
List productVersionList = productVersionQuery.getResultList();
assert productVersionList.size() > 0 : "Could not find product version for 1.0.0";
productVersionQuery = em.createNamedQuery(ProductVersion.QUERY_FIND_BY_RESOURCE_TYPE_AND_VERSION);
productVersionQuery.setParameter("resourceType", resourceType1);
productVersionQuery.setParameter("version", "2.0.0");
productVersionList = productVersionQuery.getResultList();
assert productVersionList.size() > 0 : "Could not find product version for 2.0.0";
} finally {
getTransactionManager().rollback();
}
// see that the resource sees no metadata yet - not subscribed yet
pc = PageControl.getUnlimitedInstance();
PageList<PackageVersionMetadataComposite> metadataList;
metadataList = contentSourceManager.getPackageVersionMetadata(resource1.getId(), pc);
assert metadataList != null;
assert metadataList.size() == 0 : "-->" + metadataList;
String metadataMd5 = contentSourceManager.getResourceSubscriptionMD5(resource1.getId());
assert metadataMd5 != null;
assert metadataMd5.length() == 32 : "-->" + metadataMd5;
assert metadataMd5.equals("d41d8cd98f00b204e9800998ecf8427e") : "-->" + metadataMd5;
// just to make sure the MD5 for empty data is what we think it is...
metadataMd5 = contentSourceManager.getResourceSubscriptionMD5(Integer.MIN_VALUE); // should find no metadata at all
assert metadataMd5 != null;
assert metadataMd5.length() == 32 : "-->" + metadataMd5;
assert metadataMd5.equals("d41d8cd98f00b204e9800998ecf8427e") : "-->" + metadataMd5;
// add the content source's packages to the repo
repoManager.addContentSourcesToRepo(overlord, repoId, new int[] { contentSourceId });
// see the package versions have been assigned to the repo and content source
List<PackageVersion> inRepo;
List<PackageVersionContentSource> inContentSources;
List<PackageVersionContentSource> inContentSource;
pc = PageControl.getUnlimitedInstance();
inRepo = repoManager.findPackageVersionsInRepo(overlord, repoId, pc);
pc = PageControl.getUnlimitedInstance();
inContentSources = contentSourceManager.getPackageVersionsFromContentSources(overlord,
new int[] { contentSourceId }, pc);
inContentSource = contentSourceManager.getPackageVersionsFromContentSource(overlord, contentSourceId, pc);
assert inRepo != null;
assert inContentSources != null;
assert inContentSource != null;
assert inRepo.size() == 1 : inRepo;
assert inContentSources.size() == 1 : inContentSources;
assert inContentSource.size() == 1 : inContentSource;
// confirm that we didn't load the bits yet
pc = PageControl.getUnlimitedInstance();
List<PackageVersionContentSource> unloaded;
unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord,
contentSourceId, repoId, pc);
assert unloaded != null;
assert unloaded.size() == 1;
// check the counts
long pvccount = repoManager.getPackageVersionCountFromRepo(overlord, repo.getId());
assert (pvccount == 1) : "-->" + pvccount;
long pvcscount = contentSourceManager.getPackageVersionCountFromContentSource(overlord, contentSourceId);
assert (pvcscount == 1) : "-->" + pvcscount;
// subscribe the resource
repoManager.subscribeResourceToRepos(overlord, resource1.getId(), new int[] { repoId });
// confirm the resource is subscribed
pc = PageControl.getUnlimitedInstance();
metadataList = contentSourceManager.getPackageVersionMetadata(resource1.getId(), pc);
assert metadataList != null;
assert metadataList.size() == 1 : "-->" + metadataList;
metadataMd5 = contentSourceManager.getResourceSubscriptionMD5(resource1.getId());
assert metadataMd5 != null;
assert metadataMd5.length() == 32 : "-->" + metadataMd5;
// MD5 is based on the hash code of last modified time
repo = repoManager.getRepo(overlord, repoId);
long modifiedTimestamp = repo.getLastModifiedDate();
Date modifiedDate = new Date(modifiedTimestamp);
String datehash = Integer.toString(modifiedDate.hashCode());
assert metadataMd5.equals(MessageDigestGenerator.getDigestString(datehash)) : "-->" + metadataMd5;
repoManager.unsubscribeResourceFromRepos(overlord, resource1.getId(), new int[] { repoId });