Resource resource = new Resource("testPVCSResource", "testPVCSResource", rt);
resource.setUuid("" + new Random().nextInt());
Architecture arch = new Architecture("testPVCSInsertArch");
PackageType pt = new PackageType("testPVCSInsertPT", resource.getResourceType());
Package pkg = new Package("testPVCSInsertPackage", pt);
PackageVersion pv = new PackageVersion(pkg, "version", arch);
ContentSourceType cst = new ContentSourceType("testPVCSContentSourceType");
ContentSource cs = new ContentSource("testPVCSContentSource", cst);
PackageVersionContentSource pvcs = new PackageVersionContentSource(pv, cs, "fooLocation");
Configuration csConfig = new Configuration();
csConfig.put(new PropertySimple("csConfig1", "csConfig1Value"));
cs.setConfiguration(csConfig);
Configuration pvConfig = new Configuration();
pvConfig.put(new PropertySimple("pvConfig1", "pvConfig1Value"));
pv.setExtraProperties(pvConfig);
String pvMetadata = "testInsertMetadata";
pv.setMetadata(pvMetadata.getBytes());
em.persist(rt);
em.persist(resource);
em.persist(arch);
em.persist(pt);
em.persist(pkg);
em.persist(pv);
em.persist(cst);
em.persist(cs);
em.persist(pvcs);
em.flush();
em.clear();
PackageVersionContentSourcePK pk = new PackageVersionContentSourcePK(pv, cs);
PackageVersionContentSource pvcsDup = em.find(PackageVersionContentSource.class, pk);
em.clear();
assert pvcsDup != null;
assert pvcsDup.equals(pvcs);
assert pvcsDup.getLocation().equals("fooLocation");
PackageVersionContentSourcePK pkDup = pvcsDup.getPackageVersionContentSourcePK();
assert pkDup.getContentSource().getName().equals("testPVCSContentSource");
assert pkDup.getPackageVersion().getGeneralPackage().getName().equals("testPVCSInsertPackage");
Query q = em.createNamedQuery(PackageVersionContentSource.QUERY_FIND_BY_CONTENT_SOURCE_ID);
q.setParameter("id", cs.getId());
List<PackageVersionContentSource> allPvcs = q.getResultList();
// make sure the fetch joining works by looking deep inside the objects
assert allPvcs != null;
assert allPvcs.size() == 1;
pvcs = allPvcs.get(0);
assert pvcs.getPackageVersionContentSourcePK() != null;
assert pvcs.getLocation().equals("fooLocation");
assert pvcs.getPackageVersionContentSourcePK().getPackageVersion().equals(pv);
assert pvcs.getPackageVersionContentSourcePK().getPackageVersion().getArchitecture().equals(arch);
assert pvcs.getPackageVersionContentSourcePK().getPackageVersion().getGeneralPackage().equals(pkg);
assert pvcs.getPackageVersionContentSourcePK().getPackageVersion().getExtraProperties().equals(pvConfig);
assert new String(pvcs.getPackageVersionContentSourcePK().getPackageVersion().getMetadata())
.equals(pvMetadata);
assert pvcs.getPackageVersionContentSourcePK().getContentSource().equals(cs);
assert pvcs.getPackageVersionContentSourcePK().getContentSource().getConfiguration().equals(csConfig);
assert pvcs.getPackageVersionContentSourcePK().getPackageVersion().getGeneralPackage().getPackageType()
.getResourceType().equals(rt);
// add repo and subscribe resource to it; test metadata query
Repo repo = new Repo("testPVCSRepo");
em.persist(repo);
RepoContentSource ccsmapping = repo.addContentSource(cs);
em.persist(ccsmapping);
ResourceRepo subscription = repo.addResource(resource);
em.persist(subscription);
RepoPackageVersion mapping = repo.addPackageVersion(pv);
em.persist(mapping);
em.flush();
repo = em.find(Repo.class, repo.getId());
assert repo.getResources().contains(resource);
assert repo.getContentSources().contains(cs);
q = em.createNamedQuery(PackageVersion.QUERY_FIND_METADATA_BY_RESOURCE_ID);
q.setParameter("resourceId", resource.getId());
List<PackageVersionMetadataComposite> metadataList = q.getResultList();
assert metadataList.size() == 1 : "-->" + metadataList;
PackageVersionMetadataComposite composite = metadataList.get(0);
assert composite.getPackageVersionId() == pv.getId();
assert new String(composite.getMetadata()).equals(new String(pv.getMetadata()));
assert new String(composite.getPackageDetailsKey().getName()).equals(pkg.getName());
assert new String(composite.getPackageDetailsKey().getVersion()).equals(pv.getVersion());
assert new String(composite.getPackageDetailsKey().getPackageTypeName()).equals(pt.getName());
assert new String(composite.getPackageDetailsKey().getArchitectureName()).equals(arch.getName());
em.clear();
// remove cs from pv