ocm.save();
//---------------------------------------------------------------------------------------------------------
// Retrieve Folders found on the root level
//---------------------------------------------------------------------------------------------------------
QueryManager queryManager = ocm.getQueryManager();
Filter filter = queryManager.createFilter(Folder.class);
Query query = queryManager.createQuery(filter);
filter.setScope("/");
Collection result = ocm.getObjects(query);
assertEquals("Invalid number of folders found", result.size(), 2);
assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class));
assertTrue("Invalid item in the collection", this.contains(result, "/folder2", FolderImpl.class));
//---------------------------------------------------------------------------------------------------------
// Retrieve Documents
//---------------------------------------------------------------------------------------------------------
queryManager = ocm.getQueryManager();
filter = queryManager.createFilter(Document.class);
filter.addLike("name", "document name%");
query = queryManager.createQuery(filter);
result = ocm.getObjects(query);
assertEquals("Invalid number of documents found", result.size(),2);
assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));
//---------------------------------------------------------------------------------------------------------
// Retrieve folder2
//---------------------------------------------------------------------------------------------------------
Folder folder2 = (Folder) ocm.getObject( "/folder2");
assertNotNull("folder 2 is null", folder2);
assertEquals("Invalid number of cms object found in folder2 children", folder2.getChildren().size() ,2);
assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", DocumentImpl.class));
assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", FolderImpl.class));
CmsObject cmsObject = (CmsObject) ocm.getObject( "/folder2");
assertNotNull("folder 2 is null", cmsObject);
assertTrue("Invalid instance for folder 2", cmsObject instanceof FolderImpl);
assertEquals("Invalid number of documents found in folder2 children", folder2.getChildren().size(),2);
assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", DocumentImpl.class));
assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", FolderImpl.class));
Folder childFolder = (Folder) ocm.getObject( "/folder2/subfolder");
Folder parenFolder = childFolder.getParentFolder();
assertNotNull("parent folder is null", parenFolder);
assertTrue("Invalid instance for parent folder", parenFolder instanceof FolderImpl);
assertEquals("Invalid number of documents found in folder2 children", parenFolder.getChildren().size(),2);
assertTrue("Invalid item in the collection", this.contains(parenFolder.getChildren(), "/folder2/document4", DocumentImpl.class));
assertTrue("Invalid item in the collection", this.contains(parenFolder.getChildren(), "/folder2/subfolder", FolderImpl.class));
//---------------------------------------------------------------------------------------------------------
// Retrieve Contents (ancestor of Documents)
//---------------------------------------------------------------------------------------------------------
queryManager = ocm.getQueryManager();
filter = queryManager.createFilter(Content.class);
filter.addLike("name", "document name%");
query = queryManager.createQuery(filter);
result = ocm.getObjects(query);
assertEquals("Invalid number of documents found", result.size(),2);
assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));
//---------------------------------------------------------------------------------------------------------
// Retrieve all cmsobjects found on the root level
//---------------------------------------------------------------------------------------------------------
queryManager = ocm.getQueryManager();
filter = queryManager.createFilter(CmsObject.class);
filter.setScope("/");
query = queryManager.createQuery(filter);
result = ocm.getObjects(query);
assertEquals("Invalid ancestor object found", result.size(),5);
assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));
assertTrue("Invalid item in the collection", this.contains(result, "/document3", DocumentImpl.class));
assertTrue("Invalid item in the collection", this.contains(result, "/folder1",FolderImpl.class));
assertTrue("Invalid item in the collection", this.contains(result, "/folder2",FolderImpl.class));
//---------------------------------------------------------------------------------------------------------
// Retrieve all cmsobjects found anywhere
//---------------------------------------------------------------------------------------------------------
queryManager = ocm.getQueryManager();
filter = queryManager.createFilter(CmsObject.class);
query = queryManager.createQuery(filter);
result = ocm.getObjects(query);
assertEquals("Invalid ancestor object found", result.size(),7);
assertTrue("Invalid item in the collection", this.contains(result, "/document1", DocumentImpl.class));
assertTrue("Invalid item in the collection", this.contains(result, "/document2", DocumentImpl.class));