~brian-thomason/+junk/ha-jdbc

« back to all changes in this revision

Viewing changes to test/net/sf/hajdbc/dialect/TestFirebirdDialect.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:34:21 UTC
  • Revision ID: brian.thomason@canonical.com-20111220173421-p9jg95iq91jgdihh
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * HA-JDBC: High-Availability JDBC
 
3
 * Copyright (c) 2004-2007 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.Connection;
 
24
import java.sql.DatabaseMetaData;
 
25
import java.sql.ResultSet;
 
26
import java.sql.SQLException;
 
27
import java.sql.Statement;
 
28
import java.util.Collection;
 
29
import java.util.Iterator;
 
30
 
 
31
import net.sf.hajdbc.QualifiedName;
 
32
import net.sf.hajdbc.SequenceProperties;
 
33
 
 
34
import org.easymock.EasyMock;
 
35
import org.testng.annotations.DataProvider;
 
36
import org.testng.annotations.Test;
 
37
 
 
38
/**
 
39
 * @author Paul Ferraro
 
40
 *
 
41
 */
 
42
@SuppressWarnings("nls")
 
43
@Test
 
44
public class TestFirebirdDialect extends TestStandardDialect
 
45
{
 
46
        public TestFirebirdDialect()
 
47
        {
 
48
                super(new FirebirdDialect());
 
49
        }
 
50
        
 
51
        @Override
 
52
        public void testGetAlterSequenceSQL() throws SQLException
 
53
        {
 
54
                SequenceProperties sequence = EasyMock.createStrictMock(SequenceProperties.class);
 
55
                
 
56
                EasyMock.expect(sequence.getName()).andReturn("sequence");
 
57
                
 
58
                EasyMock.replay(sequence);
 
59
                
 
60
                String result = this.getAlterSequenceSQL(sequence, 1000L);
 
61
                
 
62
                EasyMock.verify(sequence);
 
63
                
 
64
                assert result.equals("SET GENERATOR sequence TO 1000") : result;
 
65
        }
 
66
 
 
67
        /**
 
68
         * @see net.sf.hajdbc.dialect.TestStandardDialect#testGetSequences()
 
69
         */
 
70
        @Override
 
71
        public void testGetSequences() throws SQLException
 
72
        {
 
73
                DatabaseMetaData metaData = EasyMock.createStrictMock(DatabaseMetaData.class);
 
74
                Connection connection = EasyMock.createStrictMock(Connection.class);
 
75
                Statement statement = EasyMock.createStrictMock(Statement.class);
 
76
                ResultSet resultSet = EasyMock.createStrictMock(ResultSet.class);
 
77
                
 
78
                EasyMock.expect(metaData.getConnection()).andReturn(connection);
 
79
                EasyMock.expect(connection.createStatement()).andReturn(statement);
 
80
                EasyMock.expect(statement.executeQuery("SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS")).andReturn(resultSet);
 
81
                EasyMock.expect(resultSet.next()).andReturn(true);
 
82
                EasyMock.expect(resultSet.getString(1)).andReturn("sequence1");
 
83
                EasyMock.expect(resultSet.next()).andReturn(true);
 
84
                EasyMock.expect(resultSet.getString(1)).andReturn("sequence2");
 
85
                EasyMock.expect(resultSet.next()).andReturn(false);
 
86
                
 
87
                statement.close();
 
88
                
 
89
                EasyMock.replay(metaData, connection, statement, resultSet);
 
90
                
 
91
                Collection<QualifiedName> results = this.getSequences(metaData);
 
92
                
 
93
                EasyMock.verify(metaData, connection, statement, resultSet);
 
94
                
 
95
                assert results.size() == 2 : results;
 
96
                
 
97
                Iterator<QualifiedName> iterator = results.iterator();
 
98
                QualifiedName sequence = iterator.next();
 
99
                String schema = sequence.getSchema();
 
100
                String name = sequence.getName();
 
101
                
 
102
                assert schema == null : schema;
 
103
                assert name.equals("sequence1") : name;
 
104
 
 
105
                sequence = iterator.next();
 
106
                schema = sequence.getSchema();
 
107
                name = sequence.getName();
 
108
                
 
109
                assert schema == null : schema;
 
110
                assert name.equals("sequence2") : name;
 
111
        }
 
112
        
 
113
        /**
 
114
         * @see net.sf.hajdbc.dialect.TestStandardDialect#testGetNextSequenceValueSQL()
 
115
         */
 
116
        @Override
 
117
        public void testGetNextSequenceValueSQL() throws SQLException
 
118
        {
 
119
                SequenceProperties sequence = EasyMock.createStrictMock(SequenceProperties.class);
 
120
                
 
121
                EasyMock.expect(sequence.getName()).andReturn("sequence");
 
122
                
 
123
                EasyMock.replay(sequence);
 
124
                
 
125
                String sql = this.getNextSequenceValueSQL(sequence);
 
126
                
 
127
                EasyMock.verify(sequence);
 
128
                
 
129
                assert sql.equals("SELECT GEN_ID(sequence, 1) FROM RDB$DATABASE") : sql;
 
130
        }
 
131
 
 
132
        /**
 
133
         * @see net.sf.hajdbc.dialect.TestStandardDialect#testGetSimpleSQL()
 
134
         */
 
135
        @Override
 
136
        public void testGetSimpleSQL() throws SQLException
 
137
        {
 
138
                String result = this.getSimpleSQL();
 
139
                
 
140
                assert result.equals("SELECT CURRENT_TIMESTAMP FROM RDB$DATABASE") : result;
 
141
        }
 
142
 
 
143
        @Override
 
144
        @DataProvider(name = "select-for-update-sql")
 
145
        Object[][] selectForUpdateProvider()
 
146
        {
 
147
                return new Object[][] {
 
148
                        new Object[] { "SELECT * FROM success WITH LOCK" },
 
149
                        new Object[] { "SELECT * FROM failure" },
 
150
                };
 
151
        }
 
152
 
 
153
        @Override
 
154
        @DataProvider(name = "sequence-sql")
 
155
        Object[][] sequenceSQLProvider()
 
156
        {
 
157
                return new Object[][] {
 
158
                        new Object[] { "SELECT GEN_ID(success, 1) FROM RDB$DATABASE" },
 
159
                        new Object[] { "SELECT GEN_ID(success, 1), * FROM table" },
 
160
                        new Object[] { "INSERT INTO table VALUES (GEN_ID(success, 1), 0)" },
 
161
                        new Object[] { "UPDATE table SET id = GEN_ID(success, 1)" },
 
162
                        new Object[] { "SELECT * FROM table" },
 
163
                };
 
164
        }
 
165
        
 
166
        /**
 
167
         * @see net.sf.hajdbc.dialect.TestStandardDialect#testParseInsertTable(java.lang.String)
 
168
         */
 
169
        @Override
 
170
        @Test(dataProvider = "insert-table-sql")
 
171
        public void testParseInsertTable(String sql) throws SQLException
 
172
        {
 
173
                String result = this.parseInsertTable(sql);
 
174
                
 
175
                assert result == null : result;
 
176
        }
 
177
}