KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > hajdbc > dialect > TestHSQLDBDialect


1 /*
2  * HA-JDBC: High-Availability JDBC
3  * Copyright (c) 2004-2006 Paul Ferraro
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation; either version 2.1 of the License, or (at your
8  * option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: ferraro@users.sourceforge.net
20  */

21 package net.sf.hajdbc.dialect;
22
23 import java.sql.DatabaseMetaData JavaDoc;
24 import java.sql.SQLException JavaDoc;
25
26 import net.sf.hajdbc.Dialect;
27 import net.sf.hajdbc.ForeignKeyConstraint;
28
29 import org.easymock.EasyMock;
30 import org.testng.annotations.Test;
31
32 /**
33  * @author Paul Ferraro
34  *
35  */

36 @Test
37 public class TestHSQLDBDialect extends TestDefaultDialect
38 {
39     @Override JavaDoc
40     protected Dialect createDialect()
41     {
42         return new HSQLDBDialect();
43     }
44
45     @Override JavaDoc
46     public void testGetSimpleSQL()
47     {
48         String JavaDoc sql = this.dialect.getSimpleSQL();
49         
50         assert sql.equals("CALL NOW()") : sql;
51     }
52
53     /**
54      * Test case for {@link net.sf.hajdbc.Dialect#getCreateForeignKeyConstraintSQL(java.sql.DatabaseMetaData, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)}
55      */

56     @Override JavaDoc
57     public void testGetCreateForeignKeyConstraintSQL()
58     {
59         ForeignKeyConstraint constraint = new ForeignKeyConstraint("fk_name", "schema", "table");
60         constraint.getColumnList().add("column1");
61         constraint.getColumnList().add("column2");
62         constraint.setForeignSchema("other_schema");
63         constraint.setForeignTable("other_table");
64         constraint.getForeignColumnList().add("other_column1");
65         constraint.getForeignColumnList().add("other_column2");
66         constraint.setUpdateRule(DatabaseMetaData.importedKeyNoAction);
67         constraint.setDeleteRule(DatabaseMetaData.importedKeyNoAction);
68         constraint.setDeferrability(DatabaseMetaData.importedKeyNotDeferrable);
69
70         String JavaDoc quote = "'";
71         
72         try
73         {
74             EasyMock.expect(this.metaData.getIdentifierQuoteString()).andReturn(quote);
75             EasyMock.expect(this.metaData.supportsSchemasInDataManipulation()).andReturn(true);
76             EasyMock.expect(this.metaData.getIdentifierQuoteString()).andReturn(quote).times(4);
77             EasyMock.expect(this.metaData.supportsSchemasInDataManipulation()).andReturn(true);
78             EasyMock.expect(this.metaData.getIdentifierQuoteString()).andReturn(quote).times(4);
79             
80             this.control.replay();
81             
82             String JavaDoc sql = this.dialect.getCreateForeignKeyConstraintSQL(this.metaData, constraint);
83             
84             this.control.verify();
85             
86             assert sql.equals("ALTER TABLE 'schema'.'table' ADD CONSTRAINT 'fk_name' FOREIGN KEY ('column1','column2') REFERENCES 'other_schema'.'other_table' ('other_column1','other_column2') ON DELETE NO ACTION ON UPDATE NO ACTION") : sql;
87         }
88         catch (SQLException JavaDoc e)
89         {
90             assert false : e;
91         }
92     }
93 }
94
Popular Tags