Architecture arch = new Architecture("testCSSRInsertArch");
PackageType pt = new PackageType("testCSSRInsertPT", resource.getResourceType());
Package pkg = new Package("testCSSRInsertPackage", pt);
PackageVersion pv = new PackageVersion(pkg, "version", arch);
ContentSourceType cst = new ContentSourceType("testCSSRContentSourceType");
ContentSource cs = new ContentSource("testCSSRContentSource", cst);
ContentSourceSyncResults results = new ContentSourceSyncResults(cs);
Repo repo = new Repo("testCSSRRepo");
repo.addContentSource(cs);
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(repo);
em.persist(results);
cs.addSyncResult(results);
em.flush();
cs = em.find(ContentSource.class, cs.getId());
assert cs != null;
List<ContentSourceSyncResults> syncResults = cs.getSyncResults();
assert syncResults != null;
assert syncResults.size() == 1;
results = syncResults.get(0);
assert results.getContentSource().equals(cs);
assert results.getStatus() == ContentSyncStatus.INPROGRESS;
assert results.getResults() == null;
assert results.getEndTime() == null;
assert results.getStartTime() <= System.currentTimeMillis();
results.setEndTime(System.currentTimeMillis());
results.setStatus(ContentSyncStatus.FAILURE);
results.setResults("dummy failure");
results = em.merge(results);
// add another (make sure the start time is long enough to pass the time check below
Thread.sleep(100);
results = new ContentSourceSyncResults(cs);
em.persist(results);
cs.addSyncResult(results);
em.flush();
cs = em.find(ContentSource.class, cs.getId());
assert cs != null;
syncResults = cs.getSyncResults();
assert syncResults != null;
assert syncResults.size() == 2;
} catch (Exception e) {
e.printStackTrace();
throw e;