001: /*
002: * $Id: TestDiskTableRowIterator.java,v 1.3 2005/05/02 22:32:04 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2005 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.engine.tables;
042:
043: import java.io.File;
044: import java.util.ArrayList;
045: import java.util.Iterator;
046: import java.util.List;
047: import java.util.Properties;
048:
049: import junit.framework.Test;
050: import junit.framework.TestSuite;
051:
052: import org.axiondb.AxionException;
053: import org.axiondb.Column;
054: import org.axiondb.Database;
055: import org.axiondb.ExternalTable;
056: import org.axiondb.Row;
057: import org.axiondb.RowIterator;
058: import org.axiondb.Table;
059: import org.axiondb.engine.Databases;
060: import org.axiondb.engine.rowiterators.AbstractRowIteratorTest;
061: import org.axiondb.engine.rows.SimpleRow;
062: import org.axiondb.io.FileUtil;
063: import org.axiondb.types.CharacterVaryingType;
064: import org.axiondb.types.IntegerType;
065:
066: /**
067: * Tests internal RowIterator implementation of {@link org.axiondb.engine.tables.DiskTable}.
068: *
069: * @version $Revision: 1.3 $ $Date: 2005/05/02 22:32:04 $
070: * @author Jonathan Giron
071: */
072: public class TestDiskTableRowIterator extends AbstractRowIteratorTest {
073:
074: private static final String DATABASE_NAME = "TESTDB";
075:
076: //------------------------------------------------------------ Conventional
077:
078: public TestDiskTableRowIterator(String testName) {
079: super (testName);
080: }
081:
082: public static Test suite() {
083: TestSuite suite = new TestSuite(TestDiskTableRowIterator.class);
084: return suite;
085: }
086:
087: protected void setUp() throws Exception {
088: _dbDir.mkdirs();
089: _db = Databases.getOrCreateDatabase(DATABASE_NAME, _dbDir);
090: _table = createTable("X_DISK");
091: buildColumns(_table);
092: }
093:
094: protected void tearDown() throws Exception {
095: super .tearDown();
096: _table.drop();
097: _db.shutdown();
098:
099: FileUtil.delete(_dbDir);
100: }
101:
102: protected Table createTable(String name) throws Exception {
103: return new DiskTable(name, _db);
104: }
105:
106: protected Properties setProperties(String name) {
107: Properties props = new Properties();
108:
109: props.setProperty(ExternalTable.PROP_LOADTYPE, "delimited");
110: props.setProperty(DelimitedFlatfileTable.PROP_FIELDDELIMITER,
111: ",");
112:
113: String eol = System.getProperty("line.separator");
114: props.setProperty(BaseFlatfileTable.PROP_RECORDDELIMITER, eol);
115: props.setProperty(BaseFlatfileTable.PROP_ISFIRSTLINEHEADER,
116: "true");
117:
118: _dataFileName = name + ".csv";
119: props.setProperty(BaseFlatfileTable.PROP_FILENAME,
120: _dataFileName);
121:
122: return props;
123: }
124:
125: protected RowIterator makeRowIterator() {
126: try {
127: return _table.getRowIterator(false);
128: } catch (AxionException e) {
129: throw new UnsupportedOperationException(
130: "Could not create RowIterator");
131: }
132: }
133:
134: protected int getSize() {
135: return 3;
136: }
137:
138: protected List makeRowList() {
139: List list = new ArrayList();
140: {
141: SimpleRow row = new SimpleRow(2);
142: row.set(0, new Integer(1));
143: row.set(1, "a");
144: list.add(row);
145: }
146: {
147: SimpleRow row = new SimpleRow(2);
148: row.set(0, new Integer(2));
149: row.set(1, "bb");
150: list.add(row);
151: }
152: {
153: SimpleRow row = new SimpleRow(2);
154: row.set(0, new Integer(3));
155: row.set(1, "ccc");
156: list.add(row);
157: }
158: return list;
159: }
160:
161: private void buildColumns(Table t) throws Exception {
162: t.addColumn(new Column("id", new IntegerType()));
163: t.addColumn(new Column("name", new CharacterVaryingType(10)));
164:
165: Iterator iter = makeRowList().iterator();
166: while (iter.hasNext()) {
167: t.addRow((Row) iter.next());
168: }
169: }
170:
171: private Table _table;
172: private File _dbDir = new File(new File("."), DATABASE_NAME);
173: private Database _db;
174: private String _dataFileName;
175: }
|