01: /*
02: * ColumnIdentifierTest.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.db;
13:
14: import java.sql.Types;
15:
16: import java.util.ArrayList;
17: import java.util.List;
18: import junit.framework.TestCase;
19:
20: public class ColumnIdentifierTest extends TestCase {
21: public ColumnIdentifierTest(String testName) {
22: super (testName);
23: }
24:
25: public void testCopy() {
26: ColumnIdentifier col = new ColumnIdentifier("mycol",
27: Types.VARCHAR, true);
28: ColumnIdentifier copy = col.createCopy();
29: assertEquals("Copy not equals", true, col.equals(copy));
30: }
31:
32: public void testSort() {
33: ColumnIdentifier col1 = new ColumnIdentifier("one",
34: Types.VARCHAR, true);
35: col1.setPosition(1);
36:
37: ColumnIdentifier col2 = new ColumnIdentifier("two",
38: Types.VARCHAR, true);
39: col2.setPosition(2);
40:
41: ColumnIdentifier col3 = new ColumnIdentifier("three",
42: Types.VARCHAR, true);
43: col3.setPosition(3);
44:
45: ColumnIdentifier col4 = new ColumnIdentifier("four",
46: Types.VARCHAR, true);
47: col4.setPosition(4);
48:
49: ColumnIdentifier col5 = new ColumnIdentifier("five",
50: Types.VARCHAR, true);
51: col5.setPosition(5);
52:
53: ColumnIdentifier col6 = new ColumnIdentifier("six",
54: Types.VARCHAR, true);
55: col6.setPosition(6);
56:
57: List<ColumnIdentifier> cols = new ArrayList<ColumnIdentifier>();
58: cols.add(col3);
59: cols.add(col6);
60: cols.add(col2);
61: cols.add(col5);
62: cols.add(col1);
63: cols.add(col4);
64: ColumnIdentifier.sortByPosition(cols);
65: for (int i = 0; i < cols.size(); i++) {
66: assertEquals("Wrong position in sorted list", i + 1, cols
67: .get(i).getPosition());
68: }
69:
70: }
71:
72: public void testCompare() {
73: ColumnIdentifier col1 = new ColumnIdentifier("mycol",
74: Types.VARCHAR, true);
75: ColumnIdentifier col2 = new ColumnIdentifier("\"mycol\"",
76: Types.VARCHAR, true);
77: assertEquals("Columns are not equal", true, col1.equals(col2));
78: assertEquals("Columns are not equal", 0, col1.compareTo(col2));
79: assertEquals("Columns are not equal", true,
80: col1.hashCode() == col2.hashCode());
81:
82: col1 = new ColumnIdentifier("mycol", Types.VARCHAR, true);
83: col2 = new ColumnIdentifier("MYCOL", Types.VARCHAR, true);
84: assertEquals("Columns are not equal", true, col1.equals(col2));
85: assertEquals("Columns are not equal", 0, col1.compareTo(col2));
86: assertEquals("Columns are not equal", true,
87: col1.hashCode() == col2.hashCode());
88:
89: col1 = new ColumnIdentifier("Pr\u00e4fix", Types.VARCHAR, true);
90: col2 = new ColumnIdentifier("\"PR\u00c4FIX\"", Types.VARCHAR,
91: true);
92: assertEquals("Columns are not equal", true, col1.equals(col2));
93: assertEquals("Columns are not equal", 0, col1.compareTo(col2));
94: assertEquals("Columns are not equal", true,
95: col1.hashCode() == col2.hashCode());
96: }
97:
98: }
|