KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestMaxDBDialect extends TestDefaultDialect
38 {
39     @Override JavaDoc
40     protected Dialect createDialect()
41     {
42         return new MaxDBDialect();
43     }
44
45     @Override JavaDoc
46     public void testGetSimpleSQL()
47     {
48         String JavaDoc sql = this.dialect.getSimpleSQL();
49         
50         assert sql.equals("SELECT 1 FROM DUAL") : sql;
51     }
52
53     @Override JavaDoc
54     public void testGetTruncateTableSQL()
55     {
56         String JavaDoc schema = "schema";
57         String JavaDoc table = "table";
58         String JavaDoc quote = "'";
59         
60         try
61         {
62             EasyMock.expect(this.metaData.supportsSchemasInDataManipulation()).andReturn(true);
63             EasyMock.expect(this.metaData.getIdentifierQuoteString()).andReturn(quote).times(2);
64             
65             this.control.replay();
66             
67             String JavaDoc sql = this.dialect.getTruncateTableSQL(this.metaData, schema, table);
68             
69             this.control.verify();
70             
71             assert sql.equals("TRUNCATE TABLE 'schema'.'table'") : sql;
72         }
73         catch (SQLException JavaDoc e)
74         {
75             assert false : e;
76         }
77     }
78
79     /**
80      * 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)}
81      */

82     @Override JavaDoc
83     public void testGetCreateForeignKeyConstraintSQL()
84     {
85         ForeignKeyConstraint constraint = new ForeignKeyConstraint("fk_name", "schema", "table");
86         constraint.getColumnList().add("column1");
87         constraint.getColumnList().add("column2");
88         constraint.setForeignSchema("other_schema");
89         constraint.setForeignTable("other_table");
90         constraint.getForeignColumnList().add("other_column1");
91         constraint.getForeignColumnList().add("other_column2");
92         constraint.setUpdateRule(DatabaseMetaData.importedKeyNoAction);
93         constraint.setDeleteRule(DatabaseMetaData.importedKeyNoAction);
94         constraint.setDeferrability(DatabaseMetaData.importedKeyNotDeferrable);
95
96         String JavaDoc quote = "'";
97         
98         try
99         {
100             EasyMock.expect(this.metaData.getIdentifierQuoteString()).andReturn(quote);
101             EasyMock.expect(this.metaData.supportsSchemasInDataManipulation()).andReturn(true);
102             EasyMock.expect(this.metaData.getIdentifierQuoteString()).andReturn(quote).times(4);
103             EasyMock.expect(this.metaData.supportsSchemasInDataManipulation()).andReturn(true);
104             EasyMock.expect(this.metaData.getIdentifierQuoteString()).andReturn(quote).times(4);
105             
106             this.control.replay();
107             
108             String JavaDoc sql = this.dialect.getCreateForeignKeyConstraintSQL(this.metaData, constraint);
109             
110             this.control.verify();
111             
112             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") : sql;
113         }
114         catch (SQLException JavaDoc e)
115         {
116             assert false : e;
117         }
118     }
119 }
120
Popular Tags