001: /*
002: * $Id: TestJoinedRow.java,v 1.2 2004/10/01 23:40:09 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.Row;
048: import org.axiondb.engine.rows.JoinedRow;
049: import org.axiondb.engine.rows.SimpleRow;
050:
051: /**
052: * @version $Revision: 1.2 $ $Date: 2004/10/01 23:40:09 $
053: * @author Rodney Waldhoff
054: * @author Ahimanikya Satapathy
055: */
056: public class TestJoinedRow extends TestCase {
057:
058: //------------------------------------------------------------ Conventional
059:
060: public TestJoinedRow(String testName) {
061: super (testName);
062: }
063:
064: public static Test suite() {
065: TestSuite suite = new TestSuite(TestJoinedRow.class);
066: return suite;
067: }
068:
069: //--------------------------------------------------------------- Lifecycle
070:
071: //------------------------------------------------------------------- Tests
072:
073: public void testOneRow() throws Exception {
074: Row row = new SimpleRow(3);
075: row.set(0, new Integer(1));
076: row.set(1, "one");
077: row.set(2, "I");
078:
079: JoinedRow join = new JoinedRow();
080: join.addRow(row);
081:
082: assertEquals(row.size(), join.size());
083: assertEquals(row.get(0), join.get(0));
084: assertEquals(row.get(1), join.get(1));
085: assertEquals(row.get(2), join.get(2));
086: }
087:
088: public void testGetOutOfBounds() throws Exception {
089: Row row = new SimpleRow(3);
090: row.set(0, new Integer(1));
091: row.set(1, "one");
092: row.set(2, "I");
093:
094: JoinedRow join = new JoinedRow();
095: join.addRow(row);
096:
097: try {
098: join.get(-1);
099: fail("Expected IndexOutOfBoundsException");
100: } catch (IndexOutOfBoundsException e) {
101: // expected
102: }
103:
104: try {
105: join.get(3);
106: fail("Expected IndexOutOfBoundsException");
107: } catch (IndexOutOfBoundsException e) {
108: // expected
109: }
110: }
111:
112: public void testSetOutOfBounds() throws Exception {
113: Row row = new SimpleRow(3);
114: row.set(0, new Integer(1));
115: row.set(1, "one");
116: row.set(2, "I");
117:
118: JoinedRow join = new JoinedRow();
119: join.addRow(row);
120:
121: try {
122: join.set(-1, null);
123: fail("Expected IndexOutOfBoundsException");
124: } catch (IndexOutOfBoundsException e) {
125: // expected
126: }
127:
128: try {
129: join.set(3, null);
130: fail("Expected IndexOutOfBoundsException");
131: } catch (IndexOutOfBoundsException e) {
132: // expected
133: }
134: }
135:
136: public void testTwoRows() throws Exception {
137: Row one = new SimpleRow(3);
138: one.set(0, new Integer(1));
139: one.set(1, "one");
140: one.set(2, "I");
141:
142: Row two = new SimpleRow(3);
143: two.set(0, "a");
144: two.set(1, "uno");
145: two.set(2, "i");
146:
147: JoinedRow join = new JoinedRow();
148: join.addRow(one);
149: join.addRow(two);
150:
151: assertEquals(6, join.size());
152: assertEquals(one.get(0), join.get(0));
153: assertEquals(one.get(1), join.get(1));
154: assertEquals(one.get(2), join.get(2));
155: assertEquals(two.get(0), join.get(3));
156: assertEquals(two.get(1), join.get(4));
157: assertEquals(two.get(2), join.get(5));
158: }
159:
160: public void testSet() throws Exception {
161: Row one = new SimpleRow(3);
162: one.set(0, new Integer(1));
163: one.set(1, "one");
164: one.set(2, "I");
165:
166: Row two = new SimpleRow(3);
167: two.set(0, "a");
168: two.set(1, "uno");
169: two.set(2, "i");
170:
171: JoinedRow join = new JoinedRow();
172: join.addRow(one);
173: join.addRow(two);
174:
175: assertEquals(6, join.size());
176: assertEquals(one.get(0), join.get(0));
177: assertEquals(one.get(1), join.get(1));
178: assertEquals(one.get(2), join.get(2));
179: assertEquals(two.get(0), join.get(3));
180: assertEquals(two.get(1), join.get(4));
181: assertEquals(two.get(2), join.get(5));
182:
183: join.set(0, null);
184: assertNull(join.get(0));
185: assertNull(one.get(0));
186:
187: join.set(3, "xyzzy");
188: assertEquals("xyzzy", join.get(3));
189: assertEquals("xyzzy", two.get(0));
190: }
191:
192: }
|