001: /*
002: * $Id: TestColumnIdentifier.java,v 1.12 2006/01/10 21:02:37 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2002-2004 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040:
041: package org.axiondb;
042:
043: import junit.framework.Test;
044: import junit.framework.TestSuite;
045:
046: import org.axiondb.types.IntegerType;
047:
048: /**
049: * @version $Revision: 1.12 $ $Date: 2006/01/10 21:02:37 $
050: * @author Chuck Burdick
051: * @author Dave Pekarek Krohn
052: */
053: public class TestColumnIdentifier extends BaseSelectableTest {
054:
055: //------------------------------------------------------------ Conventional
056:
057: public TestColumnIdentifier(String testName) {
058: super (testName);
059: }
060:
061: public static Test suite() {
062: TestSuite suite = new TestSuite(TestColumnIdentifier.class);
063: return suite;
064: }
065:
066: //--------------------------------------------------------------- Lifecycle
067:
068: public void setUp() throws Exception {
069: super .setUp();
070: }
071:
072: public void tearDown() throws Exception {
073: super .tearDown();
074: }
075:
076: //--------------------------------------------------------------- Framework
077:
078: public Selectable makeSelectable() {
079: return new ColumnIdentifier(new TableIdentifier("TNAME",
080: "TALIAS"), "CNAME", "CALIAS", new IntegerType());
081: }
082:
083: //------------------------------------------------------------------- Tests
084:
085: public void testDottedAsterisk() {
086: ColumnIdentifier id = new ColumnIdentifier("FOO.*");
087: assertEquals("Should get just column name back", "*", id
088: .getName());
089: assertEquals("Should get table-or-alias name back", "FOO", id
090: .getTableName());
091: }
092:
093: public void testAsterisk() {
094: ColumnIdentifier id = new ColumnIdentifier("*");
095: assertEquals("Should get just column name back", "*", id
096: .getName());
097: assertEquals("Should get table-or-alias name back", null, id
098: .getTableName());
099: }
100:
101: public void testDottedIdentifier() {
102: ColumnIdentifier id = new ColumnIdentifier("FOO.BAR");
103: assertEquals("Should get just column name back", "BAR", id
104: .getName());
105: assertEquals("Should get table-or-alias name back", "FOO", id
106: .getTableName());
107: }
108:
109: public void testDottedIdentifier2() {
110: ColumnIdentifier id = new ColumnIdentifier(null, "FOO.BAR",
111: null, null);
112: assertEquals("Should get just column name back", "BAR", id
113: .getName());
114: assertEquals("Should get table-or-alias name back", "FOO", id
115: .getTableName());
116: }
117:
118: public void testNullTableConstructor() {
119: ColumnIdentifier id = new ColumnIdentifier(null, "BAR");
120: assertEquals("Should get just column name back", "BAR", id
121: .getName());
122: }
123:
124: public void testFullConstructorWithNulls() {
125: ColumnIdentifier id = new ColumnIdentifier(null, "BAR", null,
126: null);
127: assertEquals("Should get just column name back", "BAR", id
128: .getName());
129: }
130:
131: public void testNullConstructor() {
132: ColumnIdentifier id = new ColumnIdentifier(null);
133: assertNull(id.getName());
134: assertNull(id.getAlias());
135: assertEquals(id, new ColumnIdentifier(null));
136: assertEquals(id.hashCode(), (new ColumnIdentifier(null))
137: .hashCode());
138: }
139:
140: public void testEquals() throws Exception {
141: ColumnIdentifier column1 = new ColumnIdentifier(null, "NAME",
142: "ALIAS");
143: ColumnIdentifier column2 = new ColumnIdentifier(null, "NAME",
144: "ALIAS2");
145: ColumnIdentifier column3 = new ColumnIdentifier(null, "NAME");
146: assertTrue(column1.equals(column1));
147: assertTrue(column2.equals(column2));
148: assertTrue(column3.equals(column3));
149: assertTrue(column1.getCanonicalIdentifier().equals(
150: column2.getCanonicalIdentifier()));
151: assertTrue(column2.getCanonicalIdentifier().equals(
152: column1.getCanonicalIdentifier()));
153: assertTrue(column1.getCanonicalIdentifier().equals(
154: column3.getCanonicalIdentifier()));
155: assertTrue(column3.getCanonicalIdentifier().equals(
156: column1.getCanonicalIdentifier()));
157: assertTrue(!column1.equals(column2));
158: assertTrue(!column2.equals(column1));
159: assertTrue(!column1.equals(column3));
160: assertTrue(!column3.equals(column1));
161: assertTrue(column1.hashCode() != column2.hashCode());
162: assertTrue(column1.hashCode() != column3.hashCode());
163: assertTrue(column2.hashCode() != column3.hashCode());
164: }
165:
166: public void testCanonicalIdentifier() {
167: ColumnIdentifier column = new ColumnIdentifier(null, "NAME",
168: "ALIAS2");
169: assertNull(column.getCanonicalIdentifier().getAlias());
170: }
171:
172: public void testTableAlias() {
173: ColumnIdentifier column = new ColumnIdentifier(null, "NAME",
174: "ALIAS2");
175: assertNull(column.getTableAlias());
176: ColumnIdentifier id = new ColumnIdentifier(new TableIdentifier(
177: "TABLENAME", "TABLEALIAS"), "COLMNNAME", "COLUMNALIAS");
178: assertNotNull(id.getTableAlias());
179: }
180:
181: public void testGetLabel() {
182: {
183: ColumnIdentifier id = new ColumnIdentifier(
184: new TableIdentifier("TABLENAME", "TABLEALIAS"),
185: "COLUMNNAME", "COLUMNALIAS");
186: assertEquals("COLUMNALIAS", id.getLabel());
187: }
188: {
189: ColumnIdentifier id = new ColumnIdentifier(
190: new TableIdentifier("TABLENAME", "TABLEALIAS"),
191: "COLUMNNAME", null);
192: assertEquals("COLUMNNAME", id.getLabel());
193: }
194: }
195:
196: public void testToString() {
197: ColumnIdentifier id = new ColumnIdentifier(null, "XYZZY");
198: assertNotNull(id.toString());
199: id.setTableIdentifier(new TableIdentifier("THETABLE"));
200: assertNotNull(id.toString());
201: }
202:
203: public void testToStringWithAlias() {
204: ColumnIdentifier id = new ColumnIdentifier(null, "XYZZY");
205: assertNotNull(id.toString());
206: id.setTableIdentifier(new TableIdentifier("THETABLE"));
207: assertNotNull(id.toString());
208: id.setAlias("COLALIAS");
209: assertTrue(id.toString().toUpperCase().indexOf("AS") != -1);
210: }
211:
212: }
|