// create a content source type and a content source
ContentSourceType type = new ContentSourceType("testGetSyncResultsListCST");
Set<ContentSourceType> types = new HashSet<ContentSourceType>();
types.add(type);
contentSourceMetadataManager.registerTypes(types); // this blows away any previous existing types
ContentSource contentSource = new ContentSource("testGetSyncResultsListCS", type);
contentSource = contentSourceManager.simpleCreateContentSource(overlord, contentSource);
// make sure we have nothing yet
PageList<ContentSourceSyncResults> list;
list = contentSourceManager.getContentSourceSyncResults(overlord, contentSource.getId(),
PageControl.getUnlimitedInstance());
assert list.size() == 0 : "-->" + list;
// create our first INPROGRESS result
ContentSourceSyncResults results = new ContentSourceSyncResults(contentSource);
results = contentSourceManager.persistContentSourceSyncResults(results);
assert results != null;
// make sure it persisted
list = contentSourceManager.getContentSourceSyncResults(overlord, contentSource.getId(),
PageControl.getUnlimitedInstance());
assert list.size() == 1 : "-->" + list;
assert list.get(0).getId() == results.getId() : "-->" + list;
// try to create another INPROGRESS, this is not allowed so null must be returned by persist
ContentSourceSyncResults another = new ContentSourceSyncResults(contentSource);
another = contentSourceManager.persistContentSourceSyncResults(another);
assert another == null : "Not allowed to have two INPROGRESS results persisted";
// verify that we really did not persist a second one
list = contentSourceManager.getContentSourceSyncResults(overlord, contentSource.getId(),
PageControl.getUnlimitedInstance());
assert list.size() == 1 : "-->" + list;
assert list.get(0).getId() == results.getId() : "-->" + list;
// try to create another but this one is a FAILURE, this is allowed
another = new ContentSourceSyncResults(contentSource);
another.setStatus(ContentSyncStatus.FAILURE);
another.setEndTime(System.currentTimeMillis());
another = contentSourceManager.persistContentSourceSyncResults(another);
assert another != null : "Allowed to have two results persisted if only one is INPROGRESS";
// verify that we really did persist a second one
list = contentSourceManager.getContentSourceSyncResults(overlord, contentSource.getId(),
PageControl.getUnlimitedInstance());
assert list.size() == 2 : "-->" + list;
assert list.get(0).getId() == another.getId() : "-->" + list;
assert list.get(1).getId() == results.getId() : "-->" + list;
// delete the content source and make sure we cascade delete the results
contentSourceManager.deleteContentSource(overlord, contentSource.getId());
list = contentSourceManager.getContentSourceSyncResults(overlord, contentSource.getId(),
PageControl.getUnlimitedInstance());
assert list.size() == 0 : "-->" + list;
contentSourceMetadataManager.registerTypes(new HashSet<ContentSourceType>());
} catch (Throwable t) {