PageRenderTime 40ms CodeModel.GetById 19ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

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