PageRenderTime 31ms CodeModel.GetById 24ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/tst/org/diffkit/db/tst/TestDBTableDataAccess.groovy

http://diffkit.googlecode.com/
Groovy | 83 lines | 51 code | 14 blank | 18 comment | 13 complexity | 729b8d4e8488f8bfff0ff1ba6c7169c9 MD5 | raw file
 1/**
 2 * Copyright 2010-2011 Joseph Panico
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.diffkit.db.tst
17
18
19import org.diffkit.db.DKDBConnectionInfo;
20import org.diffkit.db.DKDatabase 
21import org.diffkit.db.DKDBFlavor 
22import org.diffkit.db.DKDBTableDataAccess;
23
24import groovy.util.GroovyTestCase;
25
26
27/**
28 * @author jpanico
29 */
30public class TestDBTableDataAccess extends GroovyTestCase {
31   
32   public void testGetTables(){
33      
34      println "startsWith->" + 'TABLE_SCHEMA'.startsWith('TABLE_SCHEM')
35      
36      DKDBConnectionInfo connectionInfo = ['test', DKDBFlavor.H2,"mem:test", null, null, 'test', 'test']
37      println "connectionInfo->$connectionInfo"
38      DKDatabase connectionSource = [connectionInfo]
39      def connection = connectionSource.connection
40      println "connection->$connection"
41      def dbMeta = connection.metaData
42      DKDBTableDataAccess tableDataAccess = [connectionSource]
43      println "tableDataAccess->$tableDataAccess"
44      def tables = tableDataAccess.getTables(null, null, 'TABLES')
45      println "tables->$tables"
46      
47      assert tables
48      assert tables.size() == 1
49      println "tables[0]->${tables[0].description}"
50      
51      assert tables[0].tableName == 'TABLES'
52      assert tables[0].catalog == 'TEST'
53      assert tables[0].schema == 'INFORMATION_SCHEMA'
54      assert tables[0].columns 
55      assert tables[0].columns.length == 11 
56      
57      tables[0].columns.each { println "column->${it.description}" } 
58      assert tables[0].columns[0].name == 'TABLE_CATALOG'
59      assert tables[0].columns[0].ordinalPosition == 1
60      assert tables[0].columns[0].DBTypeName == 'VARCHAR'
61      assert tables[0].columns[0].size == -1
62      assert tables[0].columns[0].nullable == true
63   }
64   
65   public void testTableMaps(){
66      
67      DKDBConnectionInfo connectionInfo = ['test', DKDBFlavor.H2,"mem:test", null, null, 'test', 'test']
68      println "connectionInfo->$connectionInfo"
69      DKDatabase connectionSource = [connectionInfo]
70      def connection = connectionSource.connection
71      println "connection->$connection"
72      def dbMeta = connection.metaData
73      DKDBTableDataAccess tableDataAccess = [connectionSource]
74      println "tableDataAccess->$tableDataAccess"
75      def tableMaps = tableDataAccess.getTableMaps(null, null, null, dbMeta)
76      println "tableMaps->$tableMaps"
77      
78      assert tableMaps
79      assert tableMaps.find { it['TABLE_NAME'] == 'CATALOGS'}
80      assert tableMaps.find { it['TABLE_NAME'] == 'COLUMNS'}
81      assert tableMaps.find { it['TABLE_NAME'] == 'TABLES'}
82   }
83}