Settings buildSettings = cfg.buildSettings(serviceRegistry);
TableSelectorStrategy tss = new TableSelectorStrategy(new DefaultReverseEngineeringStrategy());
MockedMetaDataDialect mockedMetaDataDialect = new MockedMetaDataDialect();
JDBCReader reader = JDBCReaderFactory.newJDBCReader( buildSettings, tss, mockedMetaDataDialect, serviceRegistry);
tss.addSchemaSelection( new SchemaSelection(null,null, "CHILD") );
DatabaseCollector dc = new DefaultDatabaseCollector(reader.getMetaDataDialect());
reader.readDatabaseSchema( dc, null, null );
assertEquals(mockedMetaDataDialect.gottenTables.size(),1);
assertEquals(mockedMetaDataDialect.gottenTables.get(0),"CHILD");
Iterator iterator = dc.iterateTables();
Table firstChild = (Table) iterator.next();
assertEquals(firstChild.getName(), "CHILD");
assertFalse(iterator.hasNext());
assertFalse("should not record foreignkey to table it doesn't know about yet",firstChild.getForeignKeyIterator().hasNext());
tss.clearSchemaSelections();
tss.addSchemaSelection( new SchemaSelection(null, null, "MASTER") );
mockedMetaDataDialect.gottenTables.clear();
reader.readDatabaseSchema( dc, null, null );
assertEquals(mockedMetaDataDialect.gottenTables.size(),1);
assertEquals(mockedMetaDataDialect.gottenTables.get(0),"MASTER");
iterator = dc.iterateTables();
assertNotNull(iterator.next());
assertNotNull(iterator.next());
assertFalse(iterator.hasNext());
Table table = dc.getTable( null, null, "CHILD" );
assertSame( firstChild, table );
assertHasNext("should have recorded one foreignkey to child table", 1, firstChild.getForeignKeyIterator() );
tss.clearSchemaSelections();
reader.readDatabaseSchema( dc, null, null );
Table finalMaster = dc.getTable( null, null, "MASTER" );
assertSame(firstChild, dc.getTable( null, null, "CHILD" ));
assertHasNext( 1, firstChild.getForeignKeyIterator() );