KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > standalone > sql > schema > SchemaTest


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): ______________________________________.
23  */

24
25 package org.objectweb.cjdbc.scenario.standalone.sql.schema;
26
27 import java.sql.Types JavaDoc;
28
29 import org.objectweb.cjdbc.common.sql.schema.AliasedDatabaseTable;
30 import org.objectweb.cjdbc.common.sql.schema.DatabaseColumn;
31 import org.objectweb.cjdbc.common.sql.schema.DatabaseTable;
32 import org.objectweb.cjdbc.common.sql.schema.TableColumn;
33 import org.objectweb.cjdbc.scenario.templates.NoTemplate;
34
35 /**
36  * Test schema validation of the database.
37  */

38 public class SchemaTest extends NoTemplate
39 {
40   /**
41    * Test <code>AliasedDatabaseTable</code> objects
42    *
43    */

44   public void testAliasedDatabaseTable()
45   {
46     AliasedDatabaseTable at1, at2, at3, at4;
47     DatabaseTable t1 = new DatabaseTable("buy_now", 5);
48     DatabaseColumn c1 = new DatabaseColumn("id", true);
49     DatabaseColumn c2 = new DatabaseColumn("buyer_id", false);
50     DatabaseColumn c3 = new DatabaseColumn("item_id", false);
51     DatabaseColumn c4 = new DatabaseColumn("qty", false);
52     DatabaseColumn c5 = new DatabaseColumn("date", false);
53
54     t1.addColumn(c1);
55     t1.addColumn(c2);
56     t1.addColumn(c3);
57     t1.addColumn(c4);
58     t1.addColumn(c5);
59
60     DatabaseTable t2 = new DatabaseTable("buy_now2", 5);
61     t2.addColumn(c1);
62     t2.addColumn(c2);
63     t2.addColumn(c3);
64     t2.addColumn(c4);
65     t2.addColumn(c5);
66
67     at1 = new AliasedDatabaseTable(t1, "alias1");
68     at2 = new AliasedDatabaseTable(t1, "alias2");
69     at3 = new AliasedDatabaseTable(t2, "alias1");
70     at4 = new AliasedDatabaseTable(t1, "alias1");
71
72     assertTrue(at1.equals(at1));
73     assertFalse(at1.equals(at2));
74     assertFalse(at1.equals(at3));
75     assertTrue(at1.equals(at4));
76   }
77
78   /**
79    * Test validity of columns in schema
80    *
81    */

82   public void testDatabaseColumn()
83   {
84     DatabaseColumn c1, c2, c3, c4, c5, c6;
85     c1 = new DatabaseColumn("foo", true);
86     c2 = new DatabaseColumn("foo", true);
87     c3 = new DatabaseColumn("foo", false);
88
89     c4 = new DatabaseColumn("foo", true, Types.INTEGER);
90     c5 = new DatabaseColumn("foo", true, Types.VARCHAR);
91     c6 = new DatabaseColumn("foo", true, Types.NULL);
92
93     // Test equals
94
assertTrue(c1.equals(c2));
95     assertFalse(c1.equals(c3));
96     assertFalse(c1.equals(c4));
97     assertFalse(c1.equals(c5));
98     assertTrue(c1.equals(c6));
99
100     // Test equals Ignore Types
101
assertTrue(c1.equalsIgnoreType(c2));
102     assertFalse(c1.equalsIgnoreType(c3));
103     assertTrue(c1.equalsIgnoreType(c4));
104     assertTrue(c1.equalsIgnoreType(c5));
105     assertTrue(c1.equalsIgnoreType(c6));
106     assertTrue(c4.equalsIgnoreType(c5));
107     assertTrue(c4.equalsIgnoreType(c6));
108
109   }
110
111   /**
112    * Test validity of column in schema
113    *
114    */

115   public void testTableColumn()
116   {
117     TableColumn t1, t2, t3, t4;
118     t1 = new TableColumn("table1", "name1");
119     t2 = new TableColumn("table1", "name1");
120     t3 = new TableColumn("table1", "name2");
121     t4 = new TableColumn("table2", "name1");
122
123     assertTrue(t1.equals(t1));
124     assertTrue(t1.equals(t2));
125     assertFalse(t1.equals(t3));
126     assertFalse(t1.equals(t4));
127   }
128 }
Popular Tags