001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.modules.db.explorer.dlg;
029:
030: import org.netbeans.modules.db.util.DBTestBase;
031:
032: /**
033: *
034: * @author David
035: */
036: public class AddTableColumnDDLTest extends DBTestBase {
037:
038: public AddTableColumnDDLTest(String name) {
039: super (name);
040: }
041:
042: /**
043: * Basic test, nothing fancy
044: */
045: public void testAddTableColumn() throws Exception {
046: String tablename = "testAddColumn";
047: String colname = "testColumn";
048: String pkeyName = "id";
049:
050: createBasicTable(tablename, pkeyName);
051:
052: addColumn(tablename, colname);
053:
054: // Now verify the column exists
055: assertTrue(columnExists(tablename, colname));
056: }
057:
058: private void addColumn(String tablename, String colname)
059: throws Exception {
060: AddTableColumnDDL ddl = new AddTableColumnDDL(spec, drvSpec,
061: SCHEMA, fixIdentifier(tablename));
062:
063: ColumnItem col = new ColumnItem();
064: col.setProperty(ColumnItem.NAME, colname);
065: TypeElement type = new TypeElement("java.sql.Types.VARCHAR",
066: "VARCHAR");
067: col.setProperty(ColumnItem.TYPE, type);
068: col.setProperty(ColumnItem.SIZE, "255");
069:
070: ddl.execute(colname, col, null);
071: }
072:
073: public void testAddColumnToIndex() throws Exception {
074: String tablename = "testAddColumn";
075: String firstColname = "firstColumn";
076: String secondColname = "secondColumn";
077: String pkeyName = "id";
078: String indexName = "idx";
079:
080: createBasicTable(tablename, pkeyName);
081: addColumn(tablename, firstColname);
082: createSimpleIndex(tablename, indexName, firstColname);
083:
084: AddTableColumnDDL ddl = new AddTableColumnDDL(spec, drvSpec,
085: SCHEMA, fixIdentifier(tablename));
086:
087: ColumnItem col = new ColumnItem();
088: col.setProperty(ColumnItem.NAME, secondColname);
089: TypeElement type = new TypeElement("java.sql.Types.VARCHAR",
090: "VARCHAR");
091: col.setProperty(ColumnItem.TYPE, type);
092: col.setProperty(ColumnItem.SIZE, "255");
093: col.setProperty(ColumnItem.INDEX, new Boolean(true));
094:
095: ddl.execute(secondColname, col, fixIdentifier(indexName));
096:
097: // Now verify the column exists and is part of the index
098: assertTrue(columnInIndex(tablename, secondColname, indexName));
099:
100: }
101: }
|