}
public void testReadAssocVirtualFKToRelationalAttr() throws Exception
{
Metaclass virtualClass = getMetadata().getMetaclass("Animal");
InstanceArrayList list;
Instance inst, inst2;
list = (InstanceArrayList)Query.createRead(virtualClass,
parse("(commonName (virtFKToRelAttr firstName))"),
null,
null,
-1, 0, false, Query.SEC_NODE, m_context).read();
assertEquals(4, list.getCount());
inst = list.getInstance(0);
assertEquals("Dog", inst.getValue("commonName"));
assertNull(inst.getValue("virtFKToRelAttr"));
inst = list.getInstance(2);
assertEquals("Spider", inst.getValue("commonName"));
inst2 = (Instance)inst.getValue("virtFKToRelAttr");
assertEquals("Joe", inst2.getValue("firstName"));
assertEquals("Test", inst2.getValue("lastName"));
inst = list.getInstance(3);
assertEquals("Beaver", inst.getValue("commonName"));
inst2 = (Instance)inst.getValue("virtFKToRelAttr");
assertEquals("Zoe", inst2.getValue("firstName"));
// Read the reverse attribute
Metaclass relationalClass = getMetadata().getMetaclass("PetOwner");
list = (InstanceArrayList)Query.createRead(relationalClass,
parse("(firstName (relAttrFromVirtFK commonName))"),
null,
null,
-1, 0, false, Query.SEC_NODE, m_context).read();
assertEquals(2, list.getCount());
inst = list.getInstance(0);
assertEquals("Joe", inst.getValue("firstName"));
inst2 = (Instance)inst.getValue("relAttrFromVirtFK");
assertEquals("Spider", inst2.getValue("commonName"));
inst = list.getInstance(1);
assertEquals("Zoe", inst.getValue("firstName"));
inst2 = (Instance)inst.getValue("relAttrFromVirtFK");
assertEquals("Beaver", inst2.getValue("commonName"));
assertEquals("Castor canadensis", inst2.getValue("scientificName"));
}