/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. */
  16. package org.diffkit.db.tst
  17. import org.diffkit.db.DKDBConnectionInfo;
  18. import org.diffkit.db.DKDatabase
  19. import org.diffkit.db.DKDBFlavor
  20. import org.diffkit.db.DKDBTableDataAccess;
  21. import groovy.util.GroovyTestCase;
  22. /**
  23. * @author jpanico
  24. */
  25. public class TestDBTableDataAccess extends GroovyTestCase {
  26. public void testGetTables(){
  27. println "startsWith->" + 'TABLE_SCHEMA'.startsWith('TABLE_SCHEM')
  28. DKDBConnectionInfo connectionInfo = ['test', DKDBFlavor.H2,"mem:test", null, null, 'test', 'test']
  29. println "connectionInfo->$connectionInfo"
  30. DKDatabase connectionSource = [connectionInfo]
  31. def connection = connectionSource.connection
  32. println "connection->$connection"
  33. def dbMeta = connection.metaData
  34. DKDBTableDataAccess tableDataAccess = [connectionSource]
  35. println "tableDataAccess->$tableDataAccess"
  36. def tables = tableDataAccess.getTables(null, null, 'TABLES')
  37. println "tables->$tables"
  38. assert tables
  39. assert tables.size() == 1
  40. println "tables[0]->${tables[0].description}"
  41. assert tables[0].tableName == 'TABLES'
  42. assert tables[0].catalog == 'TEST'
  43. assert tables[0].schema == 'INFORMATION_SCHEMA'
  44. assert tables[0].columns
  45. assert tables[0].columns.length == 11
  46. tables[0].columns.each { println "column->${it.description}" }
  47. assert tables[0].columns[0].name == 'TABLE_CATALOG'
  48. assert tables[0].columns[0].ordinalPosition == 1
  49. assert tables[0].columns[0].DBTypeName == 'VARCHAR'
  50. assert tables[0].columns[0].size == -1
  51. assert tables[0].columns[0].nullable == true
  52. }
  53. public void testTableMaps(){
  54. DKDBConnectionInfo connectionInfo = ['test', DKDBFlavor.H2,"mem:test", null, null, 'test', 'test']
  55. println "connectionInfo->$connectionInfo"
  56. DKDatabase connectionSource = [connectionInfo]
  57. def connection = connectionSource.connection
  58. println "connection->$connection"
  59. def dbMeta = connection.metaData
  60. DKDBTableDataAccess tableDataAccess = [connectionSource]
  61. println "tableDataAccess->$tableDataAccess"
  62. def tableMaps = tableDataAccess.getTableMaps(null, null, null, dbMeta)
  63. println "tableMaps->$tableMaps"
  64. assert tableMaps
  65. assert tableMaps.find { it['TABLE_NAME'] == 'CATALOGS'}
  66. assert tableMaps.find { it['TABLE_NAME'] == 'COLUMNS'}
  67. assert tableMaps.find { it['TABLE_NAME'] == 'TABLES'}
  68. }
  69. }