001: /*
002: * HA-JDBC: High-Availability JDBC
003: * Copyright (c) 2004-2007 Paul Ferraro
004: *
005: * This library is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU Lesser General Public License as published by the
007: * Free Software Foundation; either version 2.1 of the License, or (at your
008: * option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
013: * for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public License
016: * along with this library; if not, write to the Free Software Foundation,
017: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * Contact: ferraro@users.sourceforge.net
020: */
021: package net.sf.hajdbc.dialect;
022:
023: import java.sql.DatabaseMetaData;
024: import java.sql.SQLException;
025: import java.util.Collection;
026:
027: import net.sf.hajdbc.ColumnProperties;
028: import net.sf.hajdbc.Dialect;
029: import net.sf.hajdbc.ForeignKeyConstraint;
030: import net.sf.hajdbc.QualifiedName;
031: import net.sf.hajdbc.TableProperties;
032:
033: import org.easymock.EasyMock;
034: import org.testng.annotations.DataProvider;
035: import org.testng.annotations.Test;
036:
037: /**
038: * @author Paul Ferraro
039: */
040: @SuppressWarnings("nls")
041: public class TestSybaseDialect extends TestStandardDialect {
042: @Override
043: protected Dialect createDialect() {
044: return new SybaseDialect();
045: }
046:
047: /*
048: @Override
049: @Test(dataProvider = "table")
050: public String getLockTableSQL(TableProperties properties) throws SQLException
051: {
052: EasyMock.expect(properties.getName()).andReturn("table");
053:
054: this.replay();
055:
056: String sql = this.dialect.getLockTableSQL(properties);
057:
058: this.verify();
059:
060: assert sql.equals("LOCK TABLE table IN SHARE MODE") : sql;
061:
062: return sql;
063: }
064: */
065: @Override
066: @Test(dataProvider="table")
067: public String getTruncateTableSQL(TableProperties properties)
068: throws SQLException {
069: EasyMock.expect(properties.getName()).andReturn("table");
070:
071: this .replay();
072:
073: String sql = this .dialect.getTruncateTableSQL(properties);
074:
075: this .verify();
076:
077: assert sql.equals("TRUNCATE TABLE table");
078:
079: return sql;
080: }
081:
082: @Override
083: @Test(dataProvider="foreign-key")
084: public String getCreateForeignKeyConstraintSQL(
085: ForeignKeyConstraint constraint) throws SQLException {
086: this .replay();
087:
088: String sql = this .dialect
089: .getCreateForeignKeyConstraintSQL(constraint);
090:
091: this .verify();
092:
093: assert sql
094: .equals("ALTER TABLE table ADD CONSTRAINT name FOREIGN KEY (column1, column2) REFERENCES foreign_table (foreign_column1, foreign_column2) ON DELETE CASCADE ON UPDATE RESTRICT") : sql;
095:
096: return sql;
097: }
098:
099: @Override
100: @Test(dataProvider="column")
101: public boolean isIdentity(ColumnProperties properties)
102: throws SQLException {
103: EasyMock.expect(properties.getDefaultValue()).andReturn(
104: "AUTOINCREMENT");
105:
106: this .replay();
107:
108: boolean identity = this .dialect.isIdentity(properties);
109:
110: this .verify();
111:
112: assert identity;
113:
114: this .reset();
115:
116: EasyMock.expect(properties.getDefaultValue()).andReturn(
117: "IDENTITY");
118:
119: this .replay();
120:
121: identity = this .dialect.isIdentity(properties);
122:
123: this .verify();
124:
125: assert identity;
126:
127: this .reset();
128:
129: EasyMock.expect(this .columnProperties.getDefaultValue())
130: .andReturn(null);
131:
132: this .replay();
133:
134: identity = this .dialect.isIdentity(properties);
135:
136: this .verify();
137:
138: assert !identity;
139:
140: return identity;
141: }
142:
143: @Override
144: @Test(dataProvider="sequence-sql")
145: public String parseSequence(String sql) throws SQLException {
146: this .replay();
147:
148: String sequence = this .dialect.parseSequence(sql);
149:
150: this .verify();
151:
152: assert (sequence == null) : sequence;
153:
154: return sequence;
155: }
156:
157: @Override
158: @Test(dataProvider="meta-data")
159: public Collection<QualifiedName> getSequences(
160: DatabaseMetaData metaData) throws SQLException {
161: this .replay();
162:
163: Collection<QualifiedName> sequences = this .dialect
164: .getSequences(metaData);
165:
166: this .verify();
167:
168: assert sequences.isEmpty() : sequences;
169:
170: return sequences;
171: }
172:
173: @Override
174: @DataProvider(name="current-date")
175: Object[][] currentDateProvider() {
176: java.sql.Date date = new java.sql.Date(System
177: .currentTimeMillis());
178:
179: return new Object[][] {
180: new Object[] { "SELECT CURRENT DATE FROM success", date },
181: new Object[] { "SELECT TODAY(*) FROM success", date },
182: new Object[] { "SELECT TODAY ( * ) FROM success", date },
183: new Object[] { "SELECT CURRENT DATES FROM failure",
184: date },
185: new Object[] { "SELECT CCURRENT DATE FROM failure",
186: date },
187: new Object[] { "SELECT NOTTODAY(*) FROM failure", date },
188: new Object[] { "SELECT 1 FROM failure", date }, };
189: }
190:
191: @Override
192: @Test(dataProvider="current-date")
193: public String evaluateCurrentDate(String sql, java.sql.Date date)
194: throws SQLException {
195: String expected = sql.contains("success") ? "SELECT '"
196: + date.toString() + "' FROM success" : sql;
197:
198: String evaluated = this .dialect.evaluateCurrentDate(sql, date);
199:
200: assert evaluated.equals(expected) : evaluated;
201:
202: return evaluated;
203: }
204:
205: @Override
206: @DataProvider(name="current-time")
207: Object[][] currentTimeProvider() {
208: java.sql.Time date = new java.sql.Time(System
209: .currentTimeMillis());
210:
211: return new Object[][] {
212: new Object[] { "SELECT CURRENT TIME FROM success", date },
213: new Object[] { "SELECT CCURRENT TIME FROM failure",
214: date },
215: new Object[] { "SELECT CURRENT TIMESTAMP FROM failure",
216: date },
217: new Object[] { "SELECT 1 FROM failure", date }, };
218: }
219:
220: @Override
221: @Test(dataProvider="current-time")
222: public String evaluateCurrentTime(String sql, java.sql.Time date)
223: throws SQLException {
224: String expected = sql.contains("success") ? "SELECT '"
225: + date.toString() + "' FROM success" : sql;
226:
227: String evaluated = this .dialect.evaluateCurrentTime(sql, date);
228:
229: assert evaluated.equals(expected) : evaluated;
230:
231: return evaluated;
232: }
233:
234: @Override
235: @DataProvider(name="current-timestamp")
236: Object[][] currentTimestampProvider() {
237: java.sql.Timestamp date = new java.sql.Timestamp(System
238: .currentTimeMillis());
239:
240: return new Object[][] {
241: new Object[] { "SELECT CURRENT TIMESTAMP FROM success",
242: date },
243: new Object[] { "SELECT GETDATE() FROM success", date },
244: new Object[] { "SELECT GETDATE ( ) FROM success", date },
245: new Object[] { "SELECT NOW(*) FROM success", date },
246: new Object[] { "SELECT NOW ( * ) FROM success", date },
247: new Object[] {
248: "SELECT CCURRENT TIMESTAMP FROM failure", date },
249: new Object[] {
250: "SELECT CURRENT TIMESTAMPS FROM failure", date },
251: new Object[] { "SELECT FORGETDATE() FROM failure", date },
252: new Object[] { "SELECT NNOW(*) FROM failure", date },
253: new Object[] { "SELECT 1 FROM failure", date }, };
254: }
255:
256: @Override
257: @Test(dataProvider="current-timestamp")
258: public String evaluateCurrentTimestamp(String sql,
259: java.sql.Timestamp date) throws SQLException {
260: String expected = sql.contains("success") ? "SELECT '"
261: + date.toString() + "' FROM success" : sql;
262:
263: String evaluated = this.dialect.evaluateCurrentTimestamp(sql,
264: date);
265:
266: assert evaluated.equals(expected) : evaluated;
267:
268: return evaluated;
269: }
270: }
|