PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
16package org.diffkit.db.tst
17
18
19import java.util.regex.Pattern;
20
21import org.diffkit.db.DKDBFlavor;
22import org.diffkit.db.DKDBType;
23
24
25import groovy.util.GroovyTestCase;
26
27
28/**
29 * @author jpanico
30 */
31public class TestDBType extends GroovyTestCase {
32   
33   public void testGetBaseTypeName() {
34      assert DKDBType.getBaseTypeName('VARCHAR') == 'VARCHAR'
35      assert DKDBType.getBaseTypeName('VARCHAR()') == 'VARCHAR'
36      assert DKDBType.getBaseTypeName('VARCHAR(128)') == 'VARCHAR'
37   }
38   
39   public void testGetConcreteType() {
40      assert !DKDBType.getConcreteType(null, null)
41      assert !DKDBType.getConcreteType(DKDBFlavor.H2, null)
42      assert DKDBType.getConcreteType(null, 'VARCHAR') == DKDBType.VARCHAR
43      assert DKDBType.getConcreteType(null, '_H2_IDENTITY') == DKDBType._H2_IDENTITY
44      assert DKDBType.getConcreteType(DKDBFlavor.H2, '_H2_IDENTITY') == DKDBType._H2_IDENTITY
45      assert DKDBType.getConcreteType(DKDBFlavor.ORACLE, 'VARCHAR') == DKDBType._ORACLE_VARCHAR2
46      assert DKDBType.getConcreteType(DKDBFlavor.ORACLE, 'BIGINT') == DKDBType._ORACLE_NUMBER
47   }
48   
49   public void testSqlTypeName(){
50      assert DKDBType.VARCHAR.sqlTypeName == 'VARCHAR'
51      assert DKDBType._ORACLE_VARCHAR2.sqlTypeName == 'VARCHAR2'
52      assert DKDBType._ORACLE_NUMBER.sqlTypeName == 'NUMBER'
53   }
54   
55   public void testConcreteForAbstract(){
56      assert !DKDBType.getConcreteTypeForAbstractType(null, null)
57      assert !DKDBType.getConcreteTypeForAbstractType(DKDBFlavor.H2 , null)
58      
59      assert DKDBType.getConcreteTypeForAbstractType(null, DKDBType.VARCHAR) ==DKDBType.VARCHAR
60      assert DKDBType.getConcreteTypeForAbstractType(DKDBFlavor.H2, DKDBType.VARCHAR) ==DKDBType.VARCHAR
61      assert DKDBType.getConcreteTypeForAbstractType(DKDBFlavor.H2, DKDBType.VARCHAR) ==DKDBType.VARCHAR
62      assert DKDBType.getConcreteTypeForAbstractType(DKDBFlavor.ORACLE, DKDBType.VARCHAR) ==DKDBType._ORACLE_VARCHAR2
63   }
64   
65   public void testGetType(){
66      assert !DKDBType.getType(null, null)
67      assert !DKDBType.getType(DKDBFlavor.H2 , null)
68      assert DKDBType.getType(null , 'VARCHAR') == DKDBType.VARCHAR
69      shouldFail(RuntimeException) {
70         assert !DKDBType.getType(null , 'VARCHAR2')
71      }
72      assert DKDBType.getType(DKDBFlavor.ORACLE , 'VARCHAR2') == DKDBType._ORACLE_VARCHAR2
73   }
74   
75   public void testFlavorDemangler(){
76      def prefixPattern = Pattern.compile('^(_.*_)') 
77      def matcher = prefixPattern.matcher('_ORACLE_VARCHAR2')
78      assert matcher.find()
79      assert matcher.group( ) == '_ORACLE_'
80      
81      matcher = prefixPattern.matcher('ORACLE_VARCHAR2')
82      assert !matcher.find()
83   }
84}