001: /*
002: * $Id: TestLazyRow.java,v 1.2 2005/03/31 00:07:08 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2002-2003 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.rows;
042:
043: import junit.framework.Test;
044: import junit.framework.TestCase;
045: import junit.framework.TestSuite;
046:
047: import org.axiondb.AxionException;
048: import org.axiondb.Row;
049: import org.axiondb.RowDecorator;
050: import org.axiondb.RowSource;
051:
052: /**
053: * @version $Revision: 1.2 $ $Date: 2005/03/31 00:07:08 $
054: * @author Ahimanikya Satapathy
055: */
056: public class TestLazyRow extends TestCase {
057:
058: //------------------------------------------------------------ Conventional
059:
060: public TestLazyRow(String testName) {
061: super (testName);
062: }
063:
064: public static Test suite() {
065: TestSuite suite = new TestSuite(TestLazyRow.class);
066: return suite;
067: }
068:
069: //--------------------------------------------------------------- Lifecycle
070:
071: //------------------------------------------------------------------- Tests
072:
073: public void testGet() throws Exception {
074: Row row = new LazyRow(new MockRowSource(), 0);
075: assertEquals(row.size(), 3);
076: assertEquals(row.get(0), new Integer(1));
077: assertEquals(row.get(1), "one");
078: assertEquals(row.get(2), "I");
079:
080: try {
081: LazyRow lazyRow = new LazyRow(new MockRowSource(), 4);
082: lazyRow.get(2);
083: fail("Expected Exception");
084: } catch (Exception e) {
085: // expected
086: }
087: }
088:
089: public void testGetOutOfBounds() throws Exception {
090: Row row = new LazyRow(new MockRowSource(), 0, 0, "one");
091:
092: try {
093: row.get(-1);
094: fail("Expected Exception");
095: } catch (Exception e) {
096: // expected
097: }
098:
099: try {
100: row.get(3);
101: fail("Expected Exception");
102: } catch (Exception e) {
103: // expected
104: }
105: }
106:
107: public void testSetOutOfBounds() throws Exception {
108: Row row = new LazyRow(new MockRowSource(), 1);
109:
110: try {
111: row.set(-1, null);
112: fail("Expected Exception");
113: } catch (Exception e) {
114: // expected
115: }
116:
117: try {
118: row.set(3, null);
119: fail("Expected Exception");
120: } catch (Exception e) {
121: // expected
122: }
123: }
124:
125: public void testGetRowReturnsNull() throws Exception {
126: MockRowSource source = new MockRowSource();
127: Row row = new LazyRow(source, 1);
128: source.updateRow(1, null);
129: assertNull(row.get(1));
130: }
131:
132: public void testSet() throws Exception {
133: Row row = new LazyRow(new MockRowSource(), 0);
134:
135: assertEquals(3, row.size());
136:
137: row.set(0, null);
138: assertNull(row.get(0));
139: assertNull(row.get(0));
140:
141: row.set(2, "xyzzy");
142: assertEquals("xyzzy", row.get(2));
143: }
144:
145: class MockRowSource implements RowSource {
146: private Row[] rows = new Row[2];
147:
148: public MockRowSource() {
149: rows[0] = new SimpleRow(3);
150: rows[0].set(0, new Integer(1));
151: rows[0].set(1, "one");
152: rows[0].set(2, "I");
153:
154: rows[1] = new SimpleRow(3);
155: rows[1].set(0, "a");
156: rows[1].set(1, "uno");
157: rows[1].set(2, "i");
158: }
159:
160: public Row getRow(int id) throws AxionException {
161: try {
162: return rows[id];
163: } catch (IndexOutOfBoundsException e) {
164: throw new AxionException("Invalid Row Index", e);
165: }
166: }
167:
168: public RowDecorator makeRowDecorator() {
169: throw new UnsupportedOperationException("Not Implemented");
170: }
171:
172: public int getColumnCount() {
173: return 3;
174: }
175:
176: public int getColumnIndex(String name) throws AxionException {
177: throw new UnsupportedOperationException("Not Implemented");
178: }
179:
180: void updateRow(int i, Row row) {
181: rows[i] = row;
182: }
183: }
184:
185: }
|