documentStream.setEncoding("utf-8");
documentStream.setContent("Test Content 3".getBytes());
document.setDocumentStream(documentStream);
ocm.insert(document);
FolderImpl folder = new FolderImpl();
folder.setPath("/folder1");
folder.setName("folder1");
ocm.insert(folder);
document = new DocumentImpl();
document.setName("document4");
document.setContentType("plain/text");
documentStream = new DocumentStream();
documentStream.setEncoding("utf-8");
documentStream.setContent("Test Content 4".getBytes());
document.setDocumentStream(documentStream);
FolderImpl subFolder = new FolderImpl();
subFolder.setName("subfolder");
folder = new FolderImpl();
folder.setPath("/folder2");
folder.setName("folder2");
folder.addChild(document);
folder.addChild(subFolder);
ocm.insert(folder);
Atomic a = new Atomic();
a.setPath("/atomic");
a.setBooleanPrimitive(true);
ocm.insert(a);
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();