001: /*
002: * $Id: TestCreateIndexCommand.java,v 1.5 2005/12/20 18:32:27 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.commands;
042:
043: import junit.framework.Test;
044: import junit.framework.TestCase;
045: import junit.framework.TestSuite;
046:
047: import org.axiondb.ColumnIdentifier;
048: import org.axiondb.Database;
049: import org.axiondb.Literal;
050: import org.axiondb.Table;
051: import org.axiondb.TableIdentifier;
052: import org.axiondb.engine.MemoryDatabase;
053: import org.axiondb.types.CharacterVaryingType;
054:
055: /**
056: * @version $Revision: 1.5 $ $Date: 2005/12/20 18:32:27 $
057: * @author Ahimanikya Satapathy
058: */
059: public class TestCreateIndexCommand extends TestCase {
060:
061: //------------------------------------------------------------ Conventional
062:
063: public TestCreateIndexCommand(String testName) {
064: super (testName);
065: }
066:
067: public static void main(String args[]) {
068: String[] testCaseName = { TestCreateIndexCommand.class
069: .getName() };
070: junit.textui.TestRunner.main(testCaseName);
071: }
072:
073: public static Test suite() {
074: return new TestSuite(TestCreateIndexCommand.class);
075: }
076:
077: //--------------------------------------------------------------- Lifecycle
078: private Database _db = null;
079:
080: public void setUp() throws Exception {
081: _db = new MemoryDatabase();
082: }
083:
084: public void tearDown() throws Exception {
085: }
086:
087: //------------------------------------------------------------------- Tests
088:
089: public void testCreateIndex() throws Exception {
090: assertNull(_db.getTable("FOO"));
091: CreateTableCommand create = new CreateTableCommand("FOO");
092: Object defaultVal = new Literal("xyzzy",
093: new CharacterVaryingType(10));
094: create.addColumn("A", "varchar", "10", "0", defaultVal);
095: create.addColumn("B", "integer");
096: create.execute(_db);
097:
098: CreateIndexCommand icreate = new CreateIndexCommand();
099: icreate.setObjectName("FOO_INDEX");
100: icreate.addColumn(new ColumnIdentifier(new TableIdentifier(
101: "FOO"), "A"));
102: icreate.setTable(new TableIdentifier("FOO"));
103: icreate.execute(_db);
104: Table foo = _db.getTable("FOO");
105:
106: assertNotNull("Should get table back", foo);
107: assertEquals(true, foo.isColumnIndexed(foo.getColumn("A")));
108:
109: DropIndexCommand idrop = new DropIndexCommand("FOO_INDEX", true);
110: idrop.execute(_db);
111:
112: icreate = new CreateIndexCommand();
113: icreate.setObjectName("FOO_INDEX");
114: icreate.addColumn(new ColumnIdentifier(new TableIdentifier(
115: "FOO"), "A"));
116: icreate.setType("BOGUS");
117: icreate.setTable(new TableIdentifier("FOO"));
118:
119: try {
120: icreate.execute(_db);
121: fail("Expected Exception");
122: } catch (Exception e) {
123: // expected
124: }
125:
126: icreate.setType("BTREE");
127: icreate.setTable(new TableIdentifier("BOGUS"));
128: try {
129: icreate.execute(_db);
130: fail("Expected Exception");
131: } catch (Exception e) {
132: // expected
133: }
134:
135: icreate.setTable(new TableIdentifier("FOO"));
136: icreate.setObjectName("SYS_Bogus");
137: try {
138: icreate.execute(_db);
139: fail("Expected Exception");
140: } catch (Exception e) {
141: // expected
142: }
143:
144: icreate.setObjectName("FOO_INDEX");
145: icreate.addColumn(new ColumnIdentifier(new TableIdentifier(
146: "FOO"), "B"));
147: try {
148: icreate.execute(_db);
149: fail("Expected Exception");
150: } catch (Exception e) {
151: // expected
152: }
153:
154: }
155: }
|