/tst/org/diffkit/diff/sns/tst/TestTableModelUtil.groovy

http://diffkit.googlecode.com/ · Groovy · 80 lines · 46 code · 16 blank · 18 comment · 12 complexity · be5375aed2cfb80230030c0fb72cd28b 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.diff.sns.tst
  17. import org.diffkit.db.DKDBColumn
  18. import org.diffkit.db.DKDBFlavor;
  19. import org.diffkit.db.DKDBPrimaryKey
  20. import org.diffkit.db.DKDBTable;
  21. import org.diffkit.diff.engine.DKColumnModel;
  22. import org.diffkit.diff.sns.DKTableModelUtil;
  23. import groovy.util.GroovyTestCase;
  24. /**
  25. * @author jpanico
  26. */
  27. public class TestTableModelUtil extends GroovyTestCase {
  28. public void testCreateColumnModel(){
  29. def table = this.createCustomerMetaTable()
  30. def firstName = DKTableModelUtil.createDefaultColumnModel(DKDBFlavor.H2,table.columns[0])
  31. assert firstName.name == 'first_name'
  32. assert firstName.index == 0
  33. assert firstName.type == DKColumnModel.Type.STRING
  34. def age = DKTableModelUtil.createDefaultColumnModel(DKDBFlavor.H2,table.columns[5])
  35. assert age.name == 'age'
  36. assert age.index == 5
  37. assert age.type == DKColumnModel.Type.INTEGER
  38. }
  39. public void testCreateTableModel(){
  40. def table = this.createCustomerMetaTable()
  41. def tableModel = DKTableModelUtil.createDefaultTableModel(DKDBFlavor.H2,table, null)
  42. assert tableModel
  43. assert tableModel.name == 'CUSTOMER'
  44. assert tableModel.columns
  45. assert tableModel.columns.length == 6
  46. assert tableModel.columns[0].name == 'first_name'
  47. assert tableModel.columns[0].index == 0
  48. assert tableModel.columns[0].type == DKColumnModel.Type.STRING
  49. assert tableModel.key == (int[])[0,1]
  50. }
  51. private DKDBTable createCustomerMetaTable(){
  52. DKDBColumn column1 = ['first_name', 1, 'VARCHAR', 20, true]
  53. DKDBColumn column2 = ['last_name', 2, 'VARCHAR', -1, true]
  54. DKDBColumn column3 = ['address', 3, 'VARCHAR', -1, true]
  55. DKDBColumn column4 = ['city', 4, 'VARCHAR', -1, true]
  56. DKDBColumn column5 = ['country', 5, 'VARCHAR', -1, true]
  57. DKDBColumn column6 = ['age', 6, 'INTEGER', -1, true]
  58. DKDBColumn[] columns = [column1, column2, column3, column4, column5, column6]
  59. String[] pkColNames = ['first_name', 'last_name']
  60. DKDBPrimaryKey pk = ['pk_customer', pkColNames]
  61. DKDBTable table = [ null, null, 'CUSTOMER', columns, pk]
  62. return table
  63. }
  64. }