1   /*
2    * joey-gen and its relative products are published under the terms
3    * of the Apache Software License.
4    * 
5    * Created on 2004/08/15 15:03:38
6    */
7   package test.org.asyrinx.joey.gen.model.rdb;
8   
9   import java.util.ArrayList;
10  import java.util.List;
11  
12  import junit.framework.TestCase;
13  
14  import org.asyrinx.joey.gen.model.rdb.Database;
15  import org.asyrinx.joey.gen.model.rdb.Databases;
16  import org.asyrinx.joey.gen.model.rdb.RdbVisitor;
17  import org.asyrinx.joey.gen.model.rdb.Table;
18  import org.asyrinx.joey.gen.model.rdb.visitor.RdbVisitorAdapter;
19  import org.asyrinx.joey.gen.model.rdb.visitor.RdbVisitorMock;
20  import org.asyrinx.joey.gen.model.rdb.visitor.RdbTopDownVisitor;
21  
22  /***
23   * @author akima
24   */
25  public class RdbVisitorTest extends TestCase {
26  
27      public static void main(String[] args) {
28          junit.swingui.TestRunner.run(RdbVisitorTest.class);
29      }
30  
31      public void testVisit() {
32          final Databases domain = new Databases("sample");
33          final Database db = new Database(domain, "db1");
34          db.getTables().add(new Table("table1"));
35          db.getTables().add(new Table("table2"));
36          //
37          final List list = new ArrayList();
38          final RdbVisitor visitor = new RdbVisitorMock() {
39              public void visit(Databases databases) {
40                  list.add(databases.getName());
41              }
42  
43              public void visit(Database database) {
44                  list.add(database.getName());
45              }
46  
47              public void visit(Table table) {
48                  list.add(table.getName());
49              }
50          };
51          new RdbVisitorAdapter(new RdbTopDownVisitor(visitor)).visit(domain);
52          //
53          assertEquals(4, list.size());
54          assertEquals("sample", list.get(0));
55          assertEquals("db1", list.get(1));
56          assertEquals("table1", list.get(2));
57          assertEquals("table2", list.get(3));
58      }
59  
60  }