1   /*
2    * joey-gen and its relative products are published under the terms
3    * of the Apache Software License.
4    * 
5    * Created on 2005/01/25 21:51:29
6    */
7   package test.org.asyrinx.joey.gen.command.java;
8   
9   import org.asyrinx.joey.gen.command.java.CheckNameOfProperty;
10  import org.asyrinx.joey.gen.command.rdb2java.standard.BasicBuilder;
11  import org.asyrinx.joey.gen.model.java.AppDomain;
12  import org.asyrinx.joey.gen.model.java.Entity;
13  import org.asyrinx.joey.gen.model.java.Property;
14  import org.asyrinx.joey.gen.model.rdb.Column;
15  import org.asyrinx.joey.gen.model.rdb.Database;
16  import org.asyrinx.joey.gen.model.rdb.Databases;
17  import org.asyrinx.joey.gen.model.rdb.Table;
18  
19  import junit.framework.TestCase;
20  
21  /***
22   * @author takeshi
23   */
24  public class CheckNameOfPropertyTest extends TestCase {
25  
26      public static void main(String[] args) {
27          junit.swingui.TestRunner.run(CheckNameOfPropertyTest.class);
28      }
29  
30      final CheckNameOfProperty checker = new CheckNameOfProperty();
31  
32      public void testCheckNameOfProperty() {
33          final AppDomain domain = new AppDomain("domain");
34          //
35          final Entity entity1 = new Entity(domain, "entity1");
36          new Property(entity1).setName("property1");
37          new Property(entity1).setName("property2");
38          //
39          final Entity entity2 = new Entity(domain, "entity2");
40          entity2.setSuperClass(entity1);
41          new Property(entity2).setName("property3");
42          new Property(entity2).setName("property2");
43          //
44          checker.setStrict(false);
45          checker.execute(domain);
46          assertEquals(1, checker.getErrors().size());
47      }
48  
49      public void testCheckNameOfProperty1() {
50          final AppDomain domain = new AppDomain("domain");
51          //
52          final Entity entity1 = new Entity(domain, "entity1");
53          new Property(entity1).setName("property1");
54          new Property(entity1).setName("property2");
55          //
56          final Entity entity2 = new Entity(domain, "entity2");
57          entity2.setSuperClass(entity1);
58          final Property extendedKey = new Property(entity2);
59          extendedKey.setName("property1");
60          extendedKey.setExtended(true);
61          new Property(entity2).setName("property3");
62          //
63          checker.setStrict(false);
64          checker.execute(domain);
65          assertEquals(0, checker.getErrors().size());
66      }
67  
68      public void testCheckNameOfProperty2() {
69          final Databases databases = new Databases("dbs");
70          final Database database = new Database(databases, "db");
71          //
72          final Table table1 = new Table(database, "table1");
73          new Column(table1, "column1", "BIGINT", "0", true, true);
74          new Column(table1, "column2", "VARCHAR");
75          //
76          final Table table2 = new Table(database, "table2");
77          table2.setExtends("table1");
78          new Column(table2, "column3", "VARCHAR");
79          //
80          final BasicBuilder builder = new BasicBuilder();
81          try {
82              builder.execute(databases);
83          } catch (Throwable e) {
84              e.printStackTrace();
85              fail();
86          }
87      }
88  
89  }