public void testDriftDef() throws Exception {
Configuration config = new Configuration();
DriftDefinition driftDefPojo = new DriftDefinition(config);
driftDefPojo.setName("testDriftDef");
driftDefPojo.setInterval(60L);
driftDefPojo.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem, "foo/bar"));
driftManager.updateDriftDefinition(overlord, EntityContext.forResource(newResource.getId()), driftDefPojo);
DriftDefinitionCriteria c = new DriftDefinitionCriteria();
c.addFilterResourceIds(newResource.getId());
c.fetchConfiguration(true);
List<DriftDefinition> driftDefs = driftManager.findDriftDefinitionsByCriteria(overlord, c);
assertNotNull(driftDefs);
assertEquals(3, driftDefs.size());
DriftDefinition driftDef = null;
for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext();) {
driftDef = i.next();
if (driftDefPojo.getName().equals(driftDef.getName()))
break;
}
assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
assertEquals(driftDefPojo.getName(), driftDef.getName());
assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());
driftDefPojo.setInterval(120L);
driftManager.updateDriftDefinition(overlord, EntityContext.forResource(newResource.getId()), driftDefPojo);
driftDefs = driftManager.findDriftDefinitionsByCriteria(overlord, c);
assertNotNull(driftDefs);
assertEquals(3, driftDefs.size());
driftDef = null;
for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext();) {
driftDef = i.next();
if (driftDefPojo.getName().equals(driftDef.getName()))
break;
}
assertEquals(driftDefPojo.getName(), driftDef.getName());
assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
assertEquals(120L, driftDef.getInterval());
driftDefPojo = new DriftDefinition(driftDef.getConfiguration().deepCopyWithoutProxies());
driftDefPojo.setName("testDriftDef-2");
driftDefPojo.setInterval(30L);
driftDefPojo.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem, "foo/baz"));
driftManager.updateDriftDefinition(overlord, EntityContext.forResource(newResource.getId()), driftDefPojo);
driftDefs = driftManager.findDriftDefinitionsByCriteria(overlord, c);
assertNotNull(driftDefs);