public void testCreateMultipleWithAssoc()
{
Metaclass animalClass = m_metadata.getMetaclass("Animal");
Metaclass penClass = m_metadata.getMetaclass("AnimalPen");
Instance animal, pen;
InstanceList list;
// Create new animal & pen
pen = (Instance)penClass.invoke("new", new Object[]
{
new Pair(Symbol.define("name"), "Chimpanzee pen")
});
animal = (Instance)animalClass.invoke("new", new Object[]
{
new Pair(Symbol.define("commonName"), "Chimpanzee"),
new Pair(Symbol.define("scientificName"), "Pan troglodytes"),
new Pair(Symbol.define("limbCount"), Primitive.createInteger(4))
});
animal.setValue("pen", pen);
m_context.getUnitOfWork().commit();
// Read the animal, check the assoc to its pen
list = Query.createRead(animalClass,
parse("(commonName pen)"), parse("(= (@ commonName) \"Chimpanzee\")"),
null, -1, 0, false, Query.SEC_NODE, m_context).read();
assertEquals(1, list.size());
animal = list.getInstance(0);
assertEquals("Chimpanzee", animal.getValue("commonName"));
pen = (Instance)animal.getValue("pen");
assertEquals("Chimpanzee pen", pen.getValue("name"));
// Read the pen, check the collection of its animals
list = Query.createRead(penClass,
parse("(name animals)"), parse("(= (@ name) \"Chimpanzee pen\")"),
null, -1, 0, false, Query.SEC_NODE, m_context).read();
assertEquals(1, list.size());
pen = list.getInstance(0);
assertEquals("Chimpanzee pen", pen.getValue("name"));
list = (InstanceList)pen.getValue("animals");
assertEquals(1, list.size());
animal = list.getInstance(0);
assertEquals("Pan troglodytes", animal.getValue("scientificName"));
}