{
ObjectContentManager ocm = getObjectContentManager();
try
{
Page page = new Page();
page.setPath("/page");
page.setTitle("Page Title");
page.addParagraph(new Paragraph("para1"));
page.addParagraph(new Paragraph("para2"));
ocm.insert(page);
ocm.save();
page.addParagraph(new Paragraph("para3"));
page.setTitle("Page Title 2");
ocm.checkout("/page");
ocm.update(page);
ocm.save();
ocm.checkin("/page");
page.addParagraph(new Paragraph("para4"));
page.setTitle("Page Title 3");
ocm.checkout("/page");
ocm.update(page);
ocm.save();
ocm.checkin("/page");
VersionIterator versionIterator = ocm.getAllVersions("/page");
assertNotNull("VersionIterator is null", versionIterator);
assertTrue("Invalid number of versions found", versionIterator.getSize() == 3);
while (versionIterator.hasNext())
{
Version version = (Version) versionIterator.next();
log.info("version found : "+ version.getName() + " - " + version.getPath() + " - " + version.getCreated().getTime());
if (version.getName().equals("jcr:rootVersion"))
{
continue;
}
page = (Page) ocm.getObject("/page", version.getName());
assertNotNull("Page is null for version " + version.getName(), page);
if (version.getName().equals("1.0"))
{
assertEquals("Invalid title for version " + version.getName(),page.getTitle(), "Page Title 2");
}
if (version.getName().equals("1.1"))
{
assertEquals("Invalid title for version " + version.getName(),page.getTitle(), "Page Title 3");
}
}
Version baseVersion = ocm.getBaseVersion("/page");
log.info("Base version : " + baseVersion.getName());
Version rootVersion = ocm.getRootVersion("/page");
log.info("Root version : " + rootVersion.getName());
//this.exportDocument("/home/christophe/export.xml", "/jcr:system/jcr:versionStorage", true, false);
//Get the latest version
page = (Page) ocm.getObject( "/page");
assertNotNull("Last version is nulll", page);
assertTrue("Invalid number of paragraph found in the last version", page.getParagraphs().size() == 4);
}
catch(Exception e)
{