changeSet.setDriftDefinitionId(driftDef.getId());
changeSet.setResourceId(resource.getId());
changeSet.setDriftHandlingMode(normal);
changeSet.setCtime(System.currentTimeMillis());
DriftDTO drift1 = new DriftDTO();
drift1.setCategory(FILE_ADDED);
drift1.setPath("drift.1");
drift1.setChangeSet(changeSet);
drift1.setCtime(System.currentTimeMillis());
drift1.setNewDriftFile(toDTo(driftFile1));
DriftDTO drift2 = new DriftDTO();
drift2.setCategory(FILE_ADDED);
drift2.setPath("drift.2");
drift2.setChangeSet(changeSet);
drift2.setCtime(System.currentTimeMillis());
drift2.setNewDriftFile(toDTo(driftFile2));
Set<DriftDTO> drifts = new HashSet<DriftDTO>();
drifts.add(drift1);
drifts.add(drift2);
changeSet.setDrifts(drifts);
String newChangeSetId = jpaDriftServer.persistChangeSet(getOverlord(), changeSet);
// verify that the change set was persisted
JPADriftChangeSetCriteria criteria = new JPADriftChangeSetCriteria();
criteria.addFilterId(newChangeSetId);
criteria.fetchDrifts(true);
PageList<JPADriftChangeSet> changeSets = jpaDriftServer.findDriftChangeSetsByCriteria(getOverlord(), criteria);
assertEquals("Expected to find one change set", 1, changeSets.size());
JPADriftChangeSet jpaChangeSet = changeSets.get(0);
assertEquals("Expected change set to contain two drifts. This could be a result of the change set not being "
+ "persisted correctly or the criteria fetch being done incorrectly.", 2, jpaChangeSet.getDrifts().size());
AssertUtils.assertPropertiesMatch("The change set was not persisted correctly", changeSet, jpaChangeSet, "id",
"drifts", "class", "ctime");
List<? extends Drift> expectedDrifts = asList(drift1, drift2);
List<? extends Drift> actualDrifts = new ArrayList(jpaChangeSet.getDrifts());
// We ignore the id and ctime properties because those are set by JPADriftServerBean
// and are somewhat implmentation specific. We ignore the directory property because
// it is really a calculated property. newDriftFile has to be compared separately
// since it does not implement equals.
AssertUtils.assertCollectionMatchesNoOrder("The change set drifts were not persisted correctly",
(List<Drift>) expectedDrifts, (List<Drift>) actualDrifts, "id", "ctime", "changeSet", "directory",
"newDriftFile", "class");
assertPropertiesMatch("The newDriftFile property was not set correctly for " + drift1,
drift1.getNewDriftFile(), findDriftByPath(actualDrifts, "drift.1").getNewDriftFile(), "class", "ctime");
assertPropertiesMatch("The newDriftFile property was not set correctly for " + drift2,
drift2.getNewDriftFile(), findDriftByPath(actualDrifts, "drift.2").getNewDriftFile(), "class", "ctime");
}