@Test
public void testAbstractMemberSearch() throws Exception
{
PersistenceManager persist = new PersistenceManager(driver, database, login, password);
Foo foo = new Foo();
ConcreteBar1 bar = new ConcreteBar1();
bar.setAbstractName("abstract");
bar.setConcreteName("concrete");
foo.setBar(bar);
persist.saveObject(foo);
ConcreteBar2 bar2 = new ConcreteBar2();
bar2.setAbstractName("f");
bar2.setConcreteName("C");
foo.setBar(bar2);
persist.saveObject(foo);
persist.close();
persist = new PersistenceManager(driver, database, login, password);
// assert that there are no ConcreteBar1 objects
List<ConcreteBar1> cbar1s = persist.getObjects(ConcreteBar1.class, new All());
assertEquals(0, cbar1s.size());
// assert that there is one ConcreteBar2 object
List<ConcreteBar2> cbar2s = persist.getObjects(ConcreteBar2.class, new All());
assertEquals(1, cbar2s.size());
// assert that there is one AbstractBar object
List<AbstractBar> bars = persist.getObjects(AbstractBar.class, new All());
assertEquals(1, bars.size());
// create a Foo search object
Foo searchFoo = new Foo();
// assert that the Foo object can be retrieved with a ConcreteBar2
// object.
ConcreteBar2 cbar2 = new ConcreteBar2();
cbar2.setAbstractName("f");
cbar2.setConcreteName("C");
searchFoo.setBar(cbar2);
List<Foo> foos = persist.getObjects(Foo.class, new Equal(searchFoo));
assertEquals(1, foos.size());
// assert that the Foo object can be retrieved with a ConcreteBar1
// object.
ConcreteBar1 cbar1 = new ConcreteBar1();
cbar1.setAbstractName("f");
cbar1.setConcreteName("C");
cbar1.setFooProperty("foo");
searchFoo.setBar(cbar1);
foos = persist.getObjects(Foo.class, new Equal(searchFoo, false));
assertEquals(1, foos.size());
// assert that the Foo object can not be retrieved with incorrect values
cbar1.setAbstractName("fail");
searchFoo.setBar(cbar1);
foos = persist.getObjects(Foo.class, new Equal(searchFoo, false));
assertEquals(0, foos.size());
persist.close();