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;