ocm.save();
//---------------------------------------------------------------------------------------------------------
// Retrieve Folders found on the root level
//---------------------------------------------------------------------------------------------------------
QueryManager queryManager = ocm.getQueryManager();
Filter filter = queryManager.createFilter(FolderImpl.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(DocumentImpl.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
//---------------------------------------------------------------------------------------------------------
FolderImpl folder2 = (FolderImpl) 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));
CmsObjectImpl cmsObject = (CmsObjectImpl) 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));
//---------------------------------------------------------------------------------------------------------
// Retrieve Contents (ancestor of Documents)
//---------------------------------------------------------------------------------------------------------
queryManager = ocm.getQueryManager();
filter = queryManager.createFilter(ContentImpl.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(CmsObjectImpl.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(CmsObjectImpl.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));