}
@Test
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);
assertEquals(4, driftDefs.size());
for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext();) {
driftDef = i.next();
if ("testDriftDef".equals(driftDef.getName())) {
assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
assertEquals("foo/bar", driftDef.getBasedir().getValueName());
assertEquals(BaseDirValueContext.fileSystem, driftDef.getBasedir().getValueContext());
assertEquals(120L, driftDef.getInterval());
} else if ("testDriftDef-2".equals(driftDef.getName())) {
assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());
} else if (!"test-1".equals(driftDef.getName()) && !"test-2".equals(driftDef.getName())) {
fail("Unexpected drift def name: " + driftDef.getName());
}
}
driftManager.deleteDriftDefinition(overlord, EntityContext.forResource(newResource.getId()), "testDriftDef");
driftDefs = driftManager.findDriftDefinitionsByCriteria(overlord, c);
assertNotNull(driftDefs);
assertEquals(3, driftDefs.size());
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());
}