PageRenderTime 88ms CodeModel.GetById 11ms app.highlight 72ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://diffkit.googlecode.com/
Groovy | 557 lines | 481 code | 34 blank | 42 comment | 215 complexity | 645236107660d1daef46e94a96340520 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
 19import java.sql.Time 
 20import java.sql.Timestamp;
 21
 22import groovy.util.GroovyTestCase;
 23import org.diffkit.common.DKUserException 
 24import org.diffkit.diff.sns.DKPoiSheet 
 25import org.diffkit.diff.engine.DKColumnModel;
 26import org.diffkit.diff.engine.DKTableModel 
 27import org.diffkit.diff.engine.DKColumnModel.Type;
 28
 29import org.diffkit.util.DKResourceUtil 
 30import org.diffkit.util.DKTimeUtil;
 31
 32
 33/**
 34 * @author jpanico
 35 */
 36public class TestPoiSheet extends GroovyTestCase {
 37   
 38   // isSorted = false, so Iterator should sort the rows on the simple key; 
 39   // user defined model does not include ROW_NUM
 40   public void testSortHard() {
 41      DKColumnModel col1 = [0, 'COLUMN1', DKColumnModel.Type.INTEGER]
 42      DKColumnModel col2 = [1, 'COLUMN2', DKColumnModel.Type.STRING]
 43      DKColumnModel col3 = [2, 'COLUMN3', DKColumnModel.Type.DECIMAL]
 44      DKColumnModel col4 = [3, 'COLUMN4', DKColumnModel.Type.DECIMAL]
 45      DKColumnModel col5 = [4, 'COLUMN5', DKColumnModel.Type.MIXED]
 46      DKColumnModel col6 = [5, 'COLUMN6', DKColumnModel.Type.MIXED]
 47      DKColumnModel col7 = [6, 'COLUMN7', DKColumnModel.Type.REAL]
 48      DKColumnModel col8 = [7, 'COLUMN8', DKColumnModel.Type.STRING]
 49      DKColumnModel[] cols = [col1,col2,col3,col4,col5,col6,col7,col8]
 50      DKTableModel tableModel = ['MyModel', cols, (int[])[0]]
 51      assert !tableModel.hasRowNum()
 52      
 53      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
 54      println "sourceFile->$sourceFile"
 55      assert sourceFile
 56      DKPoiSheet poiSheet = [sourceFile, "Sheet1", false, true, false]
 57      assert poiSheet.hasHeader()
 58      Iterator rowIterator = poiSheet.getRowIterator(tableModel)
 59      assert rowIterator
 60      assert rowIterator.hasNext()
 61      def aRow = rowIterator.next()
 62      assert aRow
 63      assert aRow[0] == -2222
 64      aRow = rowIterator.next()
 65      assert aRow[0] == -1111
 66      aRow = rowIterator.next()
 67      assert aRow[0] == 2222
 68      aRow = rowIterator.next()
 69      assert aRow[0] == 11111
 70      assert ! rowIterator.hasNext()
 71   }
 72   
 73   // isSorted = false, so Iterator should sort the rows on the simple key; 
 74   // user defined model does not include ROW_NUM
 75   public void testSortMedium() {
 76      DKColumnModel col1 = [0, 'A', DKColumnModel.Type.STRING]
 77      DKColumnModel col2 = [1, 'B', DKColumnModel.Type.INTEGER]
 78      DKColumnModel col3 = [2, 'C', DKColumnModel.Type.DATE]
 79      DKColumnModel col4 = [3, 'D', DKColumnModel.Type.STRING]
 80      DKColumnModel col5 = [4, 'E', DKColumnModel.Type.TIME]
 81      DKColumnModel col6 = [5, 'F', DKColumnModel.Type.INTEGER]
 82      DKColumnModel col7 = [6, 'G', DKColumnModel.Type.DECIMAL]
 83      DKColumnModel col8 = [7, 'H', DKColumnModel.Type.DECIMAL]
 84      DKColumnModel col9 = [8, 'I', DKColumnModel.Type.DECIMAL]
 85      DKColumnModel col10 = [9, 'J', DKColumnModel.Type.TIMESTAMP]
 86      DKColumnModel col11 = [10, 'K', DKColumnModel.Type.STRING]
 87      DKColumnModel col12 = [12, 'L', DKColumnModel.Type.INTEGER]
 88      DKColumnModel col13 = [13, 'M', DKColumnModel.Type.INTEGER]
 89      DKColumnModel col14 = [14, 'N', DKColumnModel.Type.STRING]
 90      DKColumnModel col15 = [15, 'O', DKColumnModel.Type.STRING]
 91      DKColumnModel col16 = [16, 'P', DKColumnModel.Type.STRING]
 92      DKColumnModel[] cols = [col1,col2,col3,col4,col5,col6,col7,col8, col9, col10, col11, col12, col13,col14,col15,col16]
 93      DKTableModel tableModel = ['MyModel', cols, (int[])[0]]
 94      assert !tableModel.hasRowNum()
 95      
 96      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
 97      println "sourceFile->$sourceFile"
 98      assert sourceFile
 99      DKPoiSheet poiSheet = [sourceFile, "easy sheet", false, false, false]
100      Iterator rowIterator = poiSheet.getRowIterator(tableModel)
101      assert rowIterator
102      assert rowIterator.hasNext()
103      def aRow = rowIterator.next()
104      assert aRow
105      assert aRow[0] == 'aaaa'
106      aRow = rowIterator.next()
107      assert aRow[0] == 'bbbb'
108      (1..10).each { rowIterator.next()}
109      aRow = rowIterator.next()
110      assert aRow[0] == 'nnnn'
111      (1..7).each { aRow = rowIterator.next()}
112      assert aRow[0] == 'uuuu'
113      assert ! rowIterator.hasNext()
114   }
115   // isSorted = false, so Iterator should sort the rows on ROW_NUM, which means
116   // no change in ordering
117   public void testSortEasy() {
118      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
119      println "sourceFile->$sourceFile"
120      assert sourceFile
121      DKPoiSheet poiSheet = [sourceFile, "easy sheet", false, false, false]
122      Iterator rowIterator = poiSheet.getRowIterator(poiSheet.createModelFromSheet())
123      assert rowIterator
124      assert rowIterator.hasNext()
125      def aRow = rowIterator.next()
126      assert aRow
127      assert aRow[0] == 1
128      aRow = rowIterator.next()
129      assert aRow[0] == 2
130      (1..10).each { rowIterator.next()}
131      aRow = rowIterator.next()
132      assert aRow[0] == 13
133      (1..7).each { aRow = rowIterator.next()}
134      assert aRow[0] == 20
135      assert aRow[1] == 'uuuu'
136      assert ! rowIterator.hasNext()
137   }
138   
139   // read rows using RowIterator, based on model explicitly supplied by Unit. 
140   // There is no ROW_NUM col specified, so that column shouldn't show up.
141   public void testRowIteratorWithModelEasy() {
142      DKColumnModel col1 = [0, 'COLUMN1', DKColumnModel.Type.INTEGER]
143      DKColumnModel col2 = [1, 'COLUMN2', DKColumnModel.Type.STRING]
144      DKColumnModel col3 = [2, 'COLUMN3', DKColumnModel.Type.DECIMAL]
145      DKColumnModel col4 = [3, 'COLUMN4', DKColumnModel.Type.DECIMAL]
146      DKColumnModel col5 = [4, 'COLUMN5', DKColumnModel.Type.STRING]
147      DKColumnModel col6 = [5, 'COLUMN6', DKColumnModel.Type.STRING]
148      DKColumnModel col7 = [6, 'COLUMN7', DKColumnModel.Type.REAL]
149      DKColumnModel col8 = [7, 'COLUMN8', DKColumnModel.Type.STRING]
150      DKColumnModel[] cols = [col1,col2,col3,col4,col5,col6,col7,col8]
151      DKTableModel tableModel = ['MyModel', cols, (int[])[0]]
152      assert !tableModel.hasRowNum()
153      
154      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
155      println "sourceFile->$sourceFile"
156      assert sourceFile
157      DKPoiSheet poiSheet = [sourceFile, "Sheet1", true, true, false]
158      Iterator rowIterator = poiSheet.getRowIterator(tableModel)
159      assert rowIterator
160      assert rowIterator.hasNext()
161      def aRow = rowIterator.next()
162      assert aRow
163      // first row should be row_num=2, because there is a header, first 
164      // column is COLUMN1, because there is no ROW_NUM
165      assert aRow[0] == 11111
166      
167      rowIterator.next()
168      rowIterator.next()
169      aRow = rowIterator.next()
170      
171      assert aRow
172      assert aRow[0] == -2222
173      assert aRow[0].class == Long.class
174      assert aRow[1] == '       '
175      assert aRow[1].class == String.class
176      assert aRow[2] == 0.0
177      assert aRow[2].class == BigDecimal.class
178      assert aRow[3] == 3.0
179      assert aRow[3].class == BigDecimal.class
180      assert aRow[4] == '-1.0'
181      assert aRow[4].class == String.class
182      // ????
183      assert aRow[5].toString() == '31-Dec-1899'
184      assert aRow[5].class == String.class
185      assert aRow[6] == 14.2
186      assert aRow[6].class == Double.class
187      assert aRow[7] == 'FALSE'
188      assert aRow[7].class == String.class
189      
190   }
191   
192   // read rows using RowIterator, based on model extracted from Sheet
193   public void testRowIteratorHard() {
194      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
195      println "sourceFile->$sourceFile"
196      assert sourceFile
197      DKPoiSheet poiSheet = [sourceFile, "Sheet1", true, true, false]
198      Iterator rowIterator = poiSheet.getRowIterator(poiSheet.createModelFromSheet())
199      assert rowIterator
200      assert rowIterator.hasNext()
201      def aRow = rowIterator.next()
202      assert aRow
203      assert aRow.class == Object[].class
204      // first row should be row_num=2, because there is a header
205      assert aRow[0] == 2
206      rowIterator.next()
207      rowIterator.next()
208      aRow = rowIterator.next()
209      assert aRow
210      assert aRow[0] == 5
211      assert aRow[0].class == Integer.class
212      assert aRow[1] == -2222
213      assert aRow[1].class == Long.class
214      assert aRow[2] == '       '
215      assert aRow[2].class == String.class
216      assert aRow[3] == 0.0
217      assert aRow[3].class == BigDecimal.class
218      assert aRow[4] == 3.0
219      assert aRow[4].class == BigDecimal.class
220      assert aRow[5] == '-1.0'
221      assert aRow[5].class == String.class
222      // ????
223      assert aRow[6].toString() == '31-Dec-1899'
224      assert aRow[6].class == String.class
225      assert aRow[7] == 14.2
226      assert aRow[7].class == Double.class
227      assert aRow[8] == 'FALSE'
228      assert aRow[8].class == String.class
229   }
230   
231   // read rows using RowIterator, based on model extracted from Sheet
232   public void testRowIteratorEasy() {
233      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
234      println "sourceFile->$sourceFile"
235      assert sourceFile
236      DKPoiSheet poiSheet = [sourceFile, "easy sheet", true, false, false]
237      Iterator rowIterator = poiSheet.getRowIterator(poiSheet.createModelFromSheet())
238      assert rowIterator
239      assert rowIterator.hasNext()
240      def aRow = rowIterator.next()
241      assert aRow
242      assert aRow.class == Object[].class
243      assert aRow[0] == 1
244      assert aRow[0].class == Integer.class
245      assert aRow[1] == 'aaaa'
246      assert aRow[1].class == String.class
247      assert aRow[2] == 1111
248      assert aRow[2].class == BigDecimal.class
249      assert aRow[3] == DKTimeUtil.createDate( 2008, 0, 1)
250      assert aRow[3].class == Date.class
251      assert aRow[4] == 'zzzz'
252      assert aRow[4].class == String.class
253      assert aRow[5].toString() == '00:31:31'
254      assert aRow[5].class == Time.class
255      assert aRow[6] == 1234
256      assert aRow[6].class == BigDecimal.class
257      assert aRow[7] == 123456.78
258      assert aRow[7].class == BigDecimal.class
259      assert aRow[8] == 1234.5678
260      assert aRow[8].class == BigDecimal.class
261      assert aRow[9] == 1234.5678
262      assert aRow[9].class == BigDecimal.class
263      assert aRow[10].toString() == '2004-05-23 14:25:10.487'
264      assert aRow[10].class == Timestamp.class
265      assert aRow[11] == 'TRUE'
266      assert aRow[11].class == String.class
267      assert aRow[12] == 10
268      assert aRow[12].class == Long.class
269      assert aRow[13] == 12345
270      assert aRow[13].class == BigDecimal.class
271      assert aRow[14] == 'column14'
272      assert aRow[14].class == String.class
273      assert aRow[15] == 'column15'
274      assert aRow[15].class == String.class
275      assert aRow[16] == 'my clobby text'
276      assert aRow[16].class == String.class
277      while(rowIterator.hasNext()) {
278         aRow = rowIterator.next();
279         print "aRow->${aRow[0]} "
280         println "${aRow[1]} "
281      }
282      assert !rowIterator.hasNext()
283   }
284   
285   // read row using types explicitly specified in Unit
286   public void testReadRowHard() {
287      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
288      println "sourceFile->$sourceFile"
289      assert sourceFile
290      DKPoiSheet poiSheet = [sourceFile, "Sheet1", false, false, false]
291      def rows = poiSheet.rows
292      assert rows
293      // ROW_NUM = 4
294      def row = rows.get(4)
295      Type[] types = [Type.INTEGER,Type.INTEGER,Type.STRING,Type.DECIMAL,Type.DECIMAL,Type.MIXED,Type.TIME,Type.REAL,Type.BOOLEAN]
296      def result = DKPoiSheet.readRow( row, types, true)
297      assert result
298      assert result.length == types.length
299      assert result[0] == 5
300      assert result[0].class == Integer.class
301      assert result[1] == -2222
302      assert result[1].class == Long.class
303      assert result[2] == '       '
304      assert result[2].class == String.class
305      assert result[3] == 0.0
306      assert result[3].class == BigDecimal.class
307      assert result[4] == 3.0
308      assert result[4].class == BigDecimal.class
309      assert result[5] == '-1.0'
310      assert result[5].class == String.class
311      assert result[6].toString() == '05:00:00'
312      assert result[6].class == Time.class
313      assert result[7] == 14.2
314      assert result[7].class == Double.class
315      assert result[8] == Boolean.FALSE
316      assert result[8].class == Boolean.class
317   }
318   
319   // read row using types explicitly specified in Unit
320   public void testReadRowEasy() {
321      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
322      println "sourceFile->$sourceFile"
323      assert sourceFile
324      DKPoiSheet poiSheet = [sourceFile, "easy sheet", false, false, false]
325      def rows = poiSheet.rows
326      assert rows
327      def row = rows.get(0)
328      Type[] types = [Type.INTEGER,Type.STRING,Type.INTEGER,Type.DATE,Type.STRING,Type.TIME,Type.INTEGER,Type.DECIMAL,Type.DECIMAL,Type.DECIMAL,Type.TIMESTAMP,Type.BOOLEAN,Type.INTEGER,Type.INTEGER,Type.STRING,Type.STRING,Type.STRING]
329      def result = DKPoiSheet.readRow( row, types, true)
330      assert result
331      assert result.length == types.length
332      assert result[0] == 1
333      assert result[0].class == Integer.class
334      assert result[1] == 'aaaa'
335      assert result[1].class == String.class
336      assert result[2] == 1111
337      assert result[2].class == Long.class
338      assert result[3] == DKTimeUtil.createDate( 2008, 0, 1)
339      assert result[3].class == Date.class
340      assert result[4] == 'zzzz'
341      assert result[4].class == String.class
342      assert result[5].toString() == '00:31:31'
343      assert result[5].class == Time.class
344      assert result[6] == 1234
345      assert result[6].class == Long.class
346      assert result[7] == 123456.78
347      assert result[7].class == BigDecimal.class
348      assert result[8] == 1234.5678
349      assert result[8].class == BigDecimal.class
350      assert result[9] == 1234.5678
351      assert result[9].class == BigDecimal.class
352      assert result[10].toString() == '2004-05-23 14:25:10.487'
353      assert result[10].class == Timestamp.class
354      assert result[11] == Boolean.TRUE
355      assert result[11].class == Boolean.class
356      assert result[12] == 10
357      assert result[12].class == Long.class
358      assert result[13] == 12345
359      assert result[13].class == Long.class
360      assert result[14] == 'column14'
361      assert result[14].class == String.class
362      assert result[15] == 'column15'
363      assert result[15].class == String.class
364      assert result[16] == 'my clobby text'
365      assert result[16].class == String.class
366   }
367   
368   // read cells using types explicitly specified in Unit
369   public void testReadCellHard() {
370      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
371      println "sourceFile->$sourceFile"
372      assert sourceFile
373      DKPoiSheet poiSheet = [sourceFile, "Sheet1", false, false, false]
374      def rows = poiSheet.rows
375      assert rows
376      // ROW_NUM = 4
377      def row = rows.get(3)
378      assert DKPoiSheet.readCell( row.getCell(0), Type.INTEGER).class == Long.class
379      assert DKPoiSheet.readCell( row.getCell(1), Type.STRING).class == String.class
380      assert !DKPoiSheet.readCell( row.getCell(2), Type.DECIMAL)
381      assert DKPoiSheet.readCell( row.getCell(3), Type.DECIMAL).class == BigDecimal.class
382      assert !DKPoiSheet.readCell( row.getCell(4), Type.DATE)
383      assert DKPoiSheet.readCell( row.getCell(5), Type.TIME).class == Time.class
384      assert DKPoiSheet.readCell( row.getCell(6), Type.REAL).class == Double.class
385      assert DKPoiSheet.readCell( row.getCell(7), Type.BOOLEAN).class == Boolean.class
386      
387      // ROW_NUM = 5
388      row = rows.get(4)
389      assert DKPoiSheet.readCell( row.getCell(4), Type.MIXED).class == String.class
390      assert DKPoiSheet.readCell( row.getCell(7), Type.BOOLEAN).class == Boolean.class
391   }
392   
393   // read cells using types explicitly specified in Unit
394   public void testReadCellEasy() {
395      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
396      println "sourceFile->$sourceFile"
397      assert sourceFile
398      DKPoiSheet poiSheet = [sourceFile, "easy sheet", false, false, false]
399      def rows = poiSheet.rows
400      assert rows
401      def row = rows.get(0)
402      assert DKPoiSheet.readCell( row.getCell(0), Type.STRING).class == String.class
403      assert DKPoiSheet.readCell( row.getCell(1), Type.DECIMAL).class == BigDecimal.class
404      assert DKPoiSheet.readCell( row.getCell(2), Type.DATE).class == Date.class
405      assert DKPoiSheet.readCell( row.getCell(4), Type.TIME).class == Time.class
406      assert DKPoiSheet.readCell( row.getCell(9), Type.TIMESTAMP).class == Timestamp.class
407      assert DKPoiSheet.readCell( row.getCell(10), Type.BOOLEAN).class == Boolean.class
408   }
409   
410   public void testCreateModel() {
411      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
412      println "sourceFile->$sourceFile"
413      assert sourceFile
414      DKPoiSheet poiSheet = [sourceFile, "easy sheet", false, false, false]
415      def model = poiSheet.createModelFromSheet()
416      assert model
417      assert model.name == 'easy sheet'
418      assert model.keyColumnNames == (String[])['<ROW_NUM>']
419      assert model.columns.length == 17
420      assert model.columns[0].name == '<ROW_NUM>'
421      assert model.columns[0].type == Type.INTEGER
422      assert model.columns[1].name == 'A'
423      assert model.columns[1].type == Type.STRING
424      assert model.columns[2].name == 'B'
425      assert model.columns[2].type == Type.DECIMAL
426      assert model.columns[3].name == 'C'
427      assert model.columns[3].type == Type.DATE
428      assert model.columns[5].name == 'E'
429      assert model.columns[5].type == Type.TIME
430      assert model.columns[10].name == 'J'
431      assert model.columns[10].type == Type.TIMESTAMP
432      assert model.columns[11].name == 'K'
433      assert model.columns[11].type == Type.STRING
434      
435      poiSheet = [sourceFile, "Sheet1", false, true, false]
436      model = poiSheet.createModelFromSheet()
437      assert model
438      assert model.name == 'Sheet1'
439      assert model.keyColumnNames == (String[])['<ROW_NUM>']
440      assert model.columns.length == 9
441      assert model.columns[0].name == '<ROW_NUM>'
442      assert model.columns[0].type == Type.INTEGER
443      assert model.columns[1].name == 'COLUMN1'
444      assert model.columns[1].type == Type.INTEGER
445      assert model.columns[2].name == 'COLUMN2'
446      assert model.columns[2].type == Type.STRING
447      assert model.columns[3].name == 'COLUMN3'
448      assert model.columns[3].type == Type.DECIMAL
449      assert model.columns[5].name == 'COLUMN5'
450      assert model.columns[5].type == Type.MIXED
451      assert model.columns[7].name == 'COLUMN7'
452      assert model.columns[7].type == Type.REAL
453   }
454   
455   public void testDiscoverColumnTypes(){
456      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
457      println "sourceFile->$sourceFile"
458      assert sourceFile
459      DKPoiSheet poiSheet = [sourceFile, "easy sheet", false, false, false]
460      def columnTypes = poiSheet.discoverColumnTypes(poiSheet.getRows())
461      assert columnTypes
462      assert columnTypes.size() == 16
463      assert columnTypes[0] == DKColumnModel.Type.STRING
464      assert columnTypes[1] == DKColumnModel.Type.DECIMAL
465      assert columnTypes[2] == DKColumnModel.Type.DATE
466      assert columnTypes[3] == DKColumnModel.Type.STRING
467      assert columnTypes[4] == DKColumnModel.Type.TIME
468      assert columnTypes[5] == DKColumnModel.Type.DECIMAL
469      assert columnTypes[6] == DKColumnModel.Type.DECIMAL
470      assert columnTypes[7] == DKColumnModel.Type.DECIMAL
471      assert columnTypes[8] == DKColumnModel.Type.DECIMAL
472      assert columnTypes[9] == DKColumnModel.Type.TIMESTAMP
473      assert columnTypes[10] == DKColumnModel.Type.STRING
474      assert columnTypes[11] == DKColumnModel.Type.INTEGER
475      assert columnTypes[12] == DKColumnModel.Type.DECIMAL
476      assert columnTypes[13] == DKColumnModel.Type.STRING
477      assert columnTypes[14] == DKColumnModel.Type.STRING
478      assert columnTypes[15] == DKColumnModel.Type.STRING
479      
480      poiSheet = [sourceFile, "Sheet1", false, true, false]
481      columnTypes = poiSheet.discoverColumnTypes(poiSheet.getRows())
482      assert columnTypes
483      assert columnTypes.size() == 8
484      assert columnTypes[0] == DKColumnModel.Type.INTEGER
485      assert columnTypes[1] == DKColumnModel.Type.STRING
486      assert columnTypes[2] == DKColumnModel.Type.DECIMAL
487      assert columnTypes[3] == DKColumnModel.Type.DECIMAL
488      assert columnTypes[4] == DKColumnModel.Type.MIXED
489      assert columnTypes[5] == DKColumnModel.Type.MIXED
490      assert columnTypes[6] == DKColumnModel.Type.REAL
491      assert columnTypes[7] == DKColumnModel.Type.STRING
492   }
493   
494   public void testGetHeaderRow(){
495      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
496      println "sourceFile->$sourceFile"
497      assert sourceFile
498      DKPoiSheet poiSheet = [sourceFile, null, false, false, false]
499      assert !poiSheet.getHeaderRow()
500      poiSheet = [sourceFile, null, false, true, false]
501      def headerRow =  poiSheet.getHeaderRow()
502      assert headerRow
503      println "lastCellNum->$headerRow.lastCellNum"
504      println "firstCellNum->$headerRow.firstCellNum"
505   }
506   
507   public void testGetRows(){
508      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
509      println "sourceFile->$sourceFile"
510      assert sourceFile
511      DKPoiSheet poiSheet = [sourceFile, null, false, false, false]
512      def rows = poiSheet.rows
513      assert rows
514      assert rows.size() == 5
515   }
516   
517   public void testValidateLazy(){
518      File doesNotExistFile = ['./does_not_exist']
519      assert !doesNotExistFile.exists()
520      DKPoiSheet poiSheet = new DKPoiSheet(doesNotExistFile, null, false, false, true)
521      // this is a validation failure
522      shouldFail(DKUserException) { poiSheet.validate() }
523      
524      // this is a validation failure
525      shouldFail(DKUserException) { 
526         poiSheet = new DKPoiSheet(doesNotExistFile, null, false, false, false)
527      }
528   }
529   
530   public void testGetSheet(){
531      def sourceFile = DKResourceUtil.findResourceAsFile('xcel_test.xls', this)
532      println "sourceFile->$sourceFile"
533      assert sourceFile
534      DKPoiSheet poiSheet = [sourceFile, null, false, false, false]
535      def internalSheet = poiSheet.getSheet()
536      println "internalSheet->$internalSheet"
537      assert internalSheet
538      assert internalSheet.sheetName == 'Sheet1'
539      
540      poiSheet = [sourceFile, 'Sheet1', false, false, false]
541      internalSheet = poiSheet.getSheet()
542      println "internalSheet->$internalSheet"
543      assert internalSheet
544      assert internalSheet.sheetName == 'Sheet1'
545      
546      poiSheet = [sourceFile, 'easy sheet', false, false, false]
547      internalSheet = poiSheet.getSheet()
548      println "internalSheet->$internalSheet"
549      assert internalSheet
550      assert internalSheet.sheetName == 'easy sheet'
551      
552      poiSheet = [sourceFile, 'does_not_exist', false, false, false]
553      shouldFail(IOException) { 
554         internalSheet = poiSheet.getSheet()
555      }
556   }
557}