001: /*
002: * $Id: TestGroupedRowIterator.java,v 1.11 2005/04/22 21:34:17 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2003-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.rowiterators;
042:
043: import java.util.ArrayList;
044: import java.util.HashMap;
045: import java.util.List;
046: import java.util.Map;
047:
048: import junit.framework.Test;
049: import junit.framework.TestSuite;
050:
051: import org.axiondb.ColumnIdentifier;
052: import org.axiondb.OrderNode;
053: import org.axiondb.Row;
054: import org.axiondb.RowIterator;
055: import org.axiondb.engine.rows.SimpleRow;
056:
057: /**
058: * @version $Revision: 1.11 $ $Date: 2005/04/22 21:34:17 $
059: * @author Rahul Dwivedi
060: * @author Ahimanikya Satapathy
061: */
062: public class TestGroupedRowIterator extends AbstractRowIteratorTest {
063:
064: //------------------------------------------------------------ Conventional
065:
066: public TestGroupedRowIterator(String testName) {
067: super (testName);
068: }
069:
070: public static Test suite() {
071: TestSuite suite = new TestSuite(TestGroupedRowIterator.class);
072: return suite;
073: }
074:
075: //---------------------------------------------------------- Abstract Impls
076:
077: public RowIterator makeRowIterator() {
078: ArrayList list = new ArrayList();
079: for (int i = 0; i <= 2; i++) {
080: for (int j = 0; j <= 2; j++) {
081: Row row = new SimpleRow(2);
082: row.set(0, new Integer(j));
083: row.set(1, new Integer(i));
084: list.add(row);
085: }
086: }
087: Map map = new HashMap();
088: map.put(new ColumnIdentifier("a"), new Integer(0));
089: map.put(new ColumnIdentifier("b"), new Integer(1));
090: List groupList = new ArrayList();
091: groupList.add(new ColumnIdentifier("a"));
092: groupList.add(new ColumnIdentifier("b"));
093:
094: // no aggregation involved selected both column and have both col in the group by
095: // caluse.. valid group by ..
096: // and since we are just testing Iterator only.
097: List selectList = new ArrayList();
098: selectList.add(new ColumnIdentifier("a"));
099: selectList.add(new ColumnIdentifier("b"));
100:
101: List orderBy = new ArrayList();
102: orderBy.add(new OrderNode(new ColumnIdentifier("a"), true));
103: orderBy.add(new OrderNode(new ColumnIdentifier("b"), true));
104:
105: RowIterator iter = null;
106: try {
107: iter = new GroupedRowIterator(new ListRowIterator(list),
108: map, groupList, selectList, null, orderBy);
109: } catch (Exception e) {
110: // do nothing pass null along.
111: }
112:
113: return iter;
114: }
115:
116: protected int getSize() {
117: return 9;
118: }
119:
120: // we need to form a a list that replicate the result that we expect after this group
121: // by.....initial iterator we pass in makeRowIterator() method is...
122: /*
123: * 0,0 1,0 2,0 0,1 1,1 2,1 0,2 1,2 2,2 the iterator created is similar to what we'll
124: * get for this query select a,b from table x group by a,b; the result should look
125: * like this ... taking into cosideration that group by sorts result in descending
126: * order..... 2,2 2,1 2,0 1,2 1,1 1,0 0,2 0,1 0,0
127: */
128: public List makeRowList() {
129: ArrayList list = new ArrayList();
130: for (int i = 2; i >= 0; i--) {
131: for (int j = 2; j >= 0; j--) {
132: Row row = new SimpleRow(2);
133: row.set(0, new Integer(i));
134: row.set(1, new Integer(j));
135: list.add(row);
136: }
137: }
138:
139: return list;
140: }
141:
142: //--------------------------------------------------------------- Lifecycle
143:
144: private ArrayList _selectList;
145: private ArrayList _groups;
146: private List _list;
147:
148: public void setUp() throws Exception {
149: super .setUp();
150: _list = new ArrayList();
151: for (int i = 0; i <= 2; i++) {
152: for (int j = 0; j <= 2; j++) {
153: Row row = new SimpleRow(2);
154: row.set(0, new Integer(j));
155: row.set(1, new Integer(i));
156: _list.add(row);
157: }
158: }
159: _groups = new ArrayList();
160: _groups.add(new ColumnIdentifier("a"));
161: _groups.add(new ColumnIdentifier("b"));
162:
163: // no aggregation involved selected both column and have both col in the group by
164: // caluse.. valid group by ..
165: // and since we are just testing Iterator only.
166: _selectList = new ArrayList();
167: _selectList.add(new ColumnIdentifier("a"));
168: _selectList.add(new ColumnIdentifier("b"));
169:
170: }
171:
172: public void tearDown() throws Exception {
173: super .tearDown();
174: _selectList = null;
175: _groups = null;
176: _list = null;
177: }
178:
179: //------------------------------------------------------------------- Tests
180:
181: public void testUnsupported() throws Exception {
182: GroupedRowIterator iterator = (GroupedRowIterator) makeRowIterator();
183: assertNotNull(iterator);
184: try {
185: iterator.add(null);
186: fail("Expected Exception: Unsupported");
187: } catch (UnsupportedOperationException e) {
188:
189: }
190:
191: try {
192: iterator.remove();
193: fail("Expected Exception: Unsupported");
194: } catch (UnsupportedOperationException e) {
195:
196: }
197:
198: try {
199: iterator.set(null);
200: fail("Expected Exception: Unsupported");
201: } catch (UnsupportedOperationException e) {
202:
203: }
204: }
205:
206: }
|