ObjectContentManager ocm = getObjectContentManager();
// --------------------------------------------------------------------------------
// Create and store an object graph in the repository
// --------------------------------------------------------------------------------
A a = new A();
a.setPath("/test");
C c1 = new C();
c1.setId("first");
c1.setName("First Element");
C c2 = new C();
c2.setId("second");
c2.setName("Second Element");
C c3 = new C();
c3.setId("third");
c3.setName("Third Element");
Collection collection = new ArrayList();
collection.add(c1);
collection.add(c2);
collection.add(c3);
a.setCollection(collection);
ocm.insert(a);
ocm.save();
// --------------------------------------------------------------------------------
// Get the object
// --------------------------------------------------------------------------------
a = (A) ocm.getObject( "/test");
assertNotNull("a.collection is null", a.getCollection());
assertEquals("Incorrect a.collection size", 3, a.getCollection().size());
assertTrue("Incorrect a.collection", ((C) a.getCollection().iterator().next()).getId().equals("first"));
// --------------------------------------------------------------------------------
// Update the object
// --------------------------------------------------------------------------------
c1 = new C();
c1.setId("new first");
c1.setName("First Element");
c2 = new C();
c2.setId("new second");
c2.setName("Second Element");
collection = new ArrayList();
collection.add(c1);
collection.add(c2);
a.setCollection(collection);
ocm.update(a);
ocm.save();
// --------------------------------------------------------------------------------
// Get the object
// --------------------------------------------------------------------------------
a = (A) ocm.getObject( "/test");
assertNotNull("a is null", a);
assertNotNull("a.collection is null", a.getCollection());
assertTrue("Incorrect collection size", a.getCollection().size() == 2);
assertTrue("Incorrect a.collection", ((C) a.getCollection().iterator().next()).getId().equals("new first"));
// --------------------------------------------------------------------------------
// Export to check the content
// --------------------------------------------------------------------------------
this.exportDocument("target/DefaultCollectionConverterExport.xml", "/test", true, false);