public void testStartupWithOldDataStructure() throws Exception {
RegistryService registry = (RegistryService) container.getComponentInstanceOfType(RegistryService.class);
String pathDefault = RegistryService.EXO_SERVICES + "/Audit/defaultIdentity";
String pathAdmin = RegistryService.EXO_SERVICES + "/Audit/adminIdentity";
SessionProvider sessionProvider = SessionProvider.createSystemProvider();
try {
// A value is expected for the default identity
RegistryEntry registryEntry = registry.getEntry(sessionProvider, pathDefault);
Document doc = registryEntry.getDocument();
Element element = doc.getDocumentElement();
String defaultIdentity;
assertNotNull(defaultIdentity = element.getAttribute( "value"));
// A value is expected for the admin identity
registryEntry = registry.getEntry(sessionProvider, pathAdmin);
doc = registryEntry.getDocument();
element = doc.getDocumentElement();
String adminIdentity;
assertNotNull(adminIdentity = element.getAttribute( "value"));
// We remove the new entry to simulate old data structure
registry.removeEntry(sessionProvider, pathDefault);
AuditServiceImpl as = (AuditServiceImpl) service;
// We restart the service to make sure that it doesn't fail at startup
as.stop();
as.start();
// The same value is expected for the default identity
registryEntry = registry.getEntry(sessionProvider, pathDefault);
doc = registryEntry.getDocument();
element = doc.getDocumentElement();
assertEquals(defaultIdentity, element.getAttribute( "value"));
// The same value is expected for the admin identity
registryEntry = registry.getEntry(sessionProvider, pathAdmin);
doc = registryEntry.getDocument();
element = doc.getDocumentElement();
assertEquals(adminIdentity, element.getAttribute( "value"));
}
finally {
sessionProvider.close();
}
}