001: /*
002: * $Id: TestRemountCommand.java,v 1.4 2005/12/20 18:32:27 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2002-2004 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.commands;
042:
043: import junit.framework.Test;
044: import junit.framework.TestSuite;
045:
046: import org.axiondb.AxionCommand;
047: import org.axiondb.AxionException;
048: import org.axiondb.Literal;
049: import org.axiondb.Row;
050: import org.axiondb.RowIterator;
051: import org.axiondb.Table;
052: import org.axiondb.TableIdentifier;
053: import org.axiondb.engine.rows.SimpleRow;
054:
055: /**
056: * @version $Revision: 1.4 $ $Date: 2005/12/20 18:32:27 $
057: * @author Ahimanikya Satapathy
058: */
059: public class TestRemountCommand extends BaseAxionCommandTest {
060:
061: //------------------------------------------------------------ Conventional
062:
063: public TestRemountCommand(String testName) {
064: super (testName);
065: }
066:
067: public static Test suite() {
068: return new TestSuite(TestRemountCommand.class);
069: }
070:
071: //--------------------------------------------------------------- Lifecycle
072:
073: public void setUp() throws Exception {
074: super .setUp();
075: {
076: CreateTableCommand cmd = new CreateTableCommand("FOO");
077: cmd.addColumn("ID", "integer");
078: cmd.addColumn("NAME", "varchar", "10");
079: cmd.execute(getDatabase());
080: }
081: populateTable();
082: }
083:
084: public void tearDown() throws Exception {
085: super .tearDown();
086: }
087:
088: protected AxionCommand makeCommand() {
089: return new TruncateCommand();
090: }
091:
092: protected void populateTable() throws Exception {
093: Table table = getDatabase().getTable("FOO");
094: {
095: Row row = new SimpleRow(2);
096: row.set(0, new Integer(1));
097: row.set(1, "one");
098: table.addRow(row);
099: }
100: {
101: Row row = new SimpleRow(2);
102: row.set(0, new Integer(2));
103: row.set(1, "two");
104: table.addRow(row);
105: }
106: }
107:
108: //------------------------------------------------------------------- Tests
109:
110: public void testExecute() throws Exception {
111: Table table = getDatabase().getTable("FOO");
112: RowIterator iter = table.getRowIterator(true);
113: assertNotNull(iter);
114: assertTrue(iter.hasNext());
115: assertNotNull(iter.next());
116: assertTrue(iter.hasNext());
117: assertNotNull(iter.next());
118: assertTrue(!iter.hasNext());
119: table.shutdown();
120:
121: RemountCommand cmd = new RemountCommand();
122: cmd.setTable(new TableIdentifier(table.getName()));
123: cmd.setDataFilesOnly(true);
124: cmd.setDirectory(getDbdir().getCanonicalPath());
125: assertNotNull(cmd.toString());
126: assertTrue(!cmd.execute(getDatabase()));
127:
128: table = getDatabase().getTable("FOO");
129: iter = table.getRowIterator(true);
130: assertNotNull(iter);
131: assertTrue(iter.hasNext());
132: assertNotNull(iter.next());
133: assertTrue(iter.hasNext());
134: assertNotNull(iter.next());
135: assertTrue(!iter.hasNext());
136: table.shutdown();
137:
138: try {
139: cmd = new RemountCommand();
140: cmd.setTable(new TableIdentifier("bogus"));
141: cmd.setDirectory(getDbdir().getCanonicalPath());
142: cmd.execute(getDatabase());
143: fail("Expected Exception");
144: } catch (AxionException e) {
145: // expected
146: }
147:
148: try {
149: cmd = new RemountCommand();
150: cmd.execute(getDatabase());
151: fail("Expected Exception");
152: } catch (AxionException e) {
153: // expected
154: }
155:
156: cmd = new RemountCommand();
157: Literal path = new Literal(getDbdir().getCanonicalPath());
158: cmd.setDirectory(path);
159: cmd.executeUpdate(getDatabase());
160:
161: table = getDatabase().getTable("FOO");
162: iter = table.getRowIterator(true);
163: assertNotNull(iter);
164: assertTrue(iter.hasNext());
165: assertNotNull(iter.next());
166: assertTrue(iter.hasNext());
167: assertNotNull(iter.next());
168: assertTrue(!iter.hasNext());
169: }
170:
171: public void testExecuteQuery() throws Exception {
172: RemountCommand cmd = new RemountCommand();
173: assertExecuteQueryIsNotSupported(cmd);
174: }
175:
176: }
|