01: /*
02: * ImportStringVerifierTest.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.sql;
13:
14: import java.sql.Types;
15: import junit.framework.TestCase;
16: import workbench.db.ColumnIdentifier;
17: import workbench.storage.ResultInfo;
18:
19: /**
20: *
21: * @author support@sql-workbench.net
22: */
23: public class ImportStringVerifierTest extends TestCase {
24: public ImportStringVerifierTest(String testName) {
25: super (testName);
26: }
27:
28: public void testCheckData() {
29: try {
30: String data = "id\tfirstname\tlastname\n1\tArthur\tDent";
31: ColumnIdentifier id = new ColumnIdentifier("ID",
32: Types.INTEGER);
33: ColumnIdentifier fname = new ColumnIdentifier("FIRSTNAME",
34: Types.VARCHAR);
35: ColumnIdentifier lname = new ColumnIdentifier("LASTNAME",
36: Types.VARCHAR);
37: ResultInfo info = new ResultInfo(new ColumnIdentifier[] {
38: id, lname, fname });
39: ImportStringVerifier v = new ImportStringVerifier(data,
40: info);
41: assertTrue(v.checkData());
42:
43: data = "1\tArthur\tDent";
44: v = new ImportStringVerifier(data, info);
45: // If the number of columns matches, it is assumed the data is "OK"
46: assertTrue(v.checkData());
47:
48: data = "Arthur\tDent";
49: v = new ImportStringVerifier(data, info);
50: assertFalse(v.checkData());
51: } catch (Exception e) {
52: e.printStackTrace();
53: fail(e.getMessage());
54: }
55: }
56:
57: }
|