/tst/org/diffkit/db/tst/TestDBType.groovy

http://diffkit.googlecode.com/ · Groovy · 84 lines · 51 code · 15 blank · 18 comment · 14 complexity · 09e800964e58b8b5f5ed31909f2b25c6 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 java.util.regex.Pattern;
  18. import org.diffkit.db.DKDBFlavor;
  19. import org.diffkit.db.DKDBType;
  20. import groovy.util.GroovyTestCase;
  21. /**
  22. * @author jpanico
  23. */
  24. public class TestDBType extends GroovyTestCase {
  25. public void testGetBaseTypeName() {
  26. assert DKDBType.getBaseTypeName('VARCHAR') == 'VARCHAR'
  27. assert DKDBType.getBaseTypeName('VARCHAR()') == 'VARCHAR'
  28. assert DKDBType.getBaseTypeName('VARCHAR(128)') == 'VARCHAR'
  29. }
  30. public void testGetConcreteType() {
  31. assert !DKDBType.getConcreteType(null, null)
  32. assert !DKDBType.getConcreteType(DKDBFlavor.H2, null)
  33. assert DKDBType.getConcreteType(null, 'VARCHAR') == DKDBType.VARCHAR
  34. assert DKDBType.getConcreteType(null, '_H2_IDENTITY') == DKDBType._H2_IDENTITY
  35. assert DKDBType.getConcreteType(DKDBFlavor.H2, '_H2_IDENTITY') == DKDBType._H2_IDENTITY
  36. assert DKDBType.getConcreteType(DKDBFlavor.ORACLE, 'VARCHAR') == DKDBType._ORACLE_VARCHAR2
  37. assert DKDBType.getConcreteType(DKDBFlavor.ORACLE, 'BIGINT') == DKDBType._ORACLE_NUMBER
  38. }
  39. public void testSqlTypeName(){
  40. assert DKDBType.VARCHAR.sqlTypeName == 'VARCHAR'
  41. assert DKDBType._ORACLE_VARCHAR2.sqlTypeName == 'VARCHAR2'
  42. assert DKDBType._ORACLE_NUMBER.sqlTypeName == 'NUMBER'
  43. }
  44. public void testConcreteForAbstract(){
  45. assert !DKDBType.getConcreteTypeForAbstractType(null, null)
  46. assert !DKDBType.getConcreteTypeForAbstractType(DKDBFlavor.H2 , null)
  47. assert DKDBType.getConcreteTypeForAbstractType(null, DKDBType.VARCHAR) ==DKDBType.VARCHAR
  48. assert DKDBType.getConcreteTypeForAbstractType(DKDBFlavor.H2, DKDBType.VARCHAR) ==DKDBType.VARCHAR
  49. assert DKDBType.getConcreteTypeForAbstractType(DKDBFlavor.H2, DKDBType.VARCHAR) ==DKDBType.VARCHAR
  50. assert DKDBType.getConcreteTypeForAbstractType(DKDBFlavor.ORACLE, DKDBType.VARCHAR) ==DKDBType._ORACLE_VARCHAR2
  51. }
  52. public void testGetType(){
  53. assert !DKDBType.getType(null, null)
  54. assert !DKDBType.getType(DKDBFlavor.H2 , null)
  55. assert DKDBType.getType(null , 'VARCHAR') == DKDBType.VARCHAR
  56. shouldFail(RuntimeException) {
  57. assert !DKDBType.getType(null , 'VARCHAR2')
  58. }
  59. assert DKDBType.getType(DKDBFlavor.ORACLE , 'VARCHAR2') == DKDBType._ORACLE_VARCHAR2
  60. }
  61. public void testFlavorDemangler(){
  62. def prefixPattern = Pattern.compile('^(_.*_)')
  63. def matcher = prefixPattern.matcher('_ORACLE_VARCHAR2')
  64. assert matcher.find()
  65. assert matcher.group( ) == '_ORACLE_'
  66. matcher = prefixPattern.matcher('ORACLE_VARCHAR2')
  67. assert !matcher.find()
  68. }
  69. }