001: /*
002: * $Id: TestMetaData.java,v 1.10 2005/12/20 18:32:44 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2002 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.functional;
042:
043: import java.sql.ResultSet;
044: import java.sql.ResultSetMetaData;
045: import java.sql.Types;
046:
047: import junit.framework.Test;
048: import junit.framework.TestSuite;
049:
050: /**
051: * @version $Revision: 1.10 $ $Date: 2005/12/20 18:32:44 $
052: * @author Chuck Burdick
053: */
054: public class TestMetaData extends AbstractFunctionalTest {
055:
056: //------------------------------------------------------------ Conventional
057:
058: public TestMetaData(String testName) {
059: super (testName);
060: }
061:
062: public static Test suite() {
063: return new TestSuite(TestMetaData.class);
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: //------------------------------------------------------------------- Tests
077:
078: public void testSimpleColumnMetaData() throws Exception {
079: createTableFoo();
080: populateTableFoo();
081: _rset = _stmt.executeQuery("SELECT * FROM foo");
082: ResultSetMetaData meta = _rset.getMetaData();
083:
084: assertEquals("Should indicate 3 columns", 3, meta
085: .getColumnCount());
086:
087: helpTestColumnMetaData(meta, 1, "NUM", Types.INTEGER, 10, 0);
088: helpTestColumnMetaData(meta, 2, "STR", Types.VARCHAR, 255, 0);
089: }
090:
091: public void testNumericColumnMetaData() throws Exception {
092: _stmt
093: .execute("CREATE TABLE nums (\"INT\" INTEGER, \"BIGINT\" BIGINT, \"FLOAT\" FLOAT, BIG NUMBER)");
094:
095: _rset = _stmt.executeQuery("SELECT * FROM nums");
096: ResultSetMetaData meta = _rset.getMetaData();
097:
098: assertEquals("Should indicate 4 columns", 4, meta
099: .getColumnCount());
100: helpTestColumnMetaData(meta, 1, "INT", Types.INTEGER, 10, 0);
101: helpTestColumnMetaData(meta, 2, "BIGINT", Types.BIGINT, 19, 0);
102: helpTestColumnMetaData(meta, 3, "FLOAT", Types.FLOAT, 12, 0);
103: helpTestColumnMetaData(meta, 4, "BIG", Types.NUMERIC, 22, 0);
104:
105: _rset = _stmt
106: .executeQuery("SELECT * FROM axion_columns WHERE table_name = 'NUMS' ORDER BY column_name");
107:
108: helpTestSystemTableColumns(_rset, "BIG", Types.NUMERIC, 22, 0,
109: 10);
110: helpTestSystemTableColumns(_rset, "BIGINT", Types.BIGINT, 19,
111: 0, 10);
112: helpTestSystemTableColumns(_rset, "FLOAT", Types.FLOAT, 12, 0,
113: 10);
114: helpTestSystemTableColumns(_rset, "INT", Types.INTEGER, 10, 0,
115: 10);
116: assertTrue("Should have no more rows", !_rset.next());
117: }
118:
119: private void helpTestColumnMetaData(ResultSetMetaData meta,
120: int colId, String name, int type, int precision, int scale)
121: throws Exception {
122: assertEquals("Should get expected column name", name, meta
123: .getColumnName(colId));
124: assertEquals("Should be expected type", type, meta
125: .getColumnType(colId));
126: assertEquals("Should be expected precision", precision, meta
127: .getPrecision(colId));
128: assertEquals("Should be expected scale", scale, meta
129: .getScale(colId));
130: }
131:
132: private void helpTestSystemTableColumns(ResultSet rset,
133: String name, int type, int precision, int scale, int radix)
134: throws Exception {
135: assertTrue("Should have a row", _rset.next());
136: assertEquals("Should get expected column name", name, rset
137: .getString(4));
138: assertEquals("Should be expected type", type, rset.getInt(5));
139: assertEquals("Should be expected precision", precision, rset
140: .getInt(7));
141: assertEquals("Should be expected scale", scale, rset.getInt(9));
142: assertEquals("Should be expected radix", radix, rset.getInt(10));
143: }
144: }
|