int id;
String name = "BundleTest-testBundleVersionRepo";
String recipe = "action/script/recipe is here";
Repo repo1 = new Repo(name + "-Repo1");
Repo repo2 = new Repo(name + "-Repo2");
em.persist(repo1);
em.persist(repo2);
assert repo1.getId() > 0;
assert repo2.getId() > 0;
Query q = em.createNamedQuery(BundleVersionRepo.QUERY_FIND_BY_REPO_ID_NO_FETCH);
q.setParameter("id", repo1.getId());
assert q.getResultList().size() == 0 : "should not have repo1 mapping in the db yet";
q.setParameter("id", repo2.getId());
assert q.getResultList().size() == 0 : "should not have repo2 mapping in the db yet";
BundleType bundleType = createBundleType(em, name + "-Type", createResourceType(em));
Bundle bundle = createBundle(em, name + "-Bundle", bundleType);
BundleVersion bundleVersion = new BundleVersion(name, "1.0.0.BETA", bundle, recipe);
bundleVersion.setVersionOrder(0);
em.persist(bundleVersion);
id = bundleVersion.getId();
assert id > 0;
assert bundleVersion.getBundle().getId() != 0 : "bundle should have been cascade persisted too";
assert bundleVersion.getBundle().getBundleType().getId() != 0 : "bundleType should have been cascade persisted too";
BundleVersionRepo bvr1 = new BundleVersionRepo(bundleVersion, repo1);
BundleVersionRepo bvr2 = new BundleVersionRepo(bundleVersion, repo2);
em.persist(bvr1);
em.persist(bvr2);
q = em.createNamedQuery(BundleVersionRepo.QUERY_FIND_BY_REPO_ID_NO_FETCH);
q.setParameter("id", repo1.getId());
assert q.getResultList().size() == 1;
assert ((BundleVersionRepo) q.getSingleResult()).getBundleVersionRepoPK().getBundleVersion()
.equals(bundleVersion);
assert ((BundleVersionRepo) q.getSingleResult()).getBundleVersionRepoPK().getRepo().equals(repo1);
q.setParameter("id", repo2.getId());
assert q.getResultList().size() == 1;
assert ((BundleVersionRepo) q.getSingleResult()).getBundleVersionRepoPK().getBundleVersion()
.equals(bundleVersion);
assert ((BundleVersionRepo) q.getSingleResult()).getBundleVersionRepoPK().getRepo().equals(repo2);