001: /*
002: * $Id: TestDropConstraintCommand.java,v 1.6 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.ColumnIdentifier;
049: import org.axiondb.constraints.NotNullConstraint;
050:
051: /**
052: * @version $Revision: 1.6 $ $Date: 2005/12/20 18:32:27 $
053: * @author Rodney Waldhoff
054: */
055: public class TestDropConstraintCommand extends BaseAxionCommandTest {
056:
057: //------------------------------------------------------------ Conventional
058:
059: public TestDropConstraintCommand(String testName) {
060: super (testName);
061: }
062:
063: public static Test suite() {
064: return new TestSuite(TestDropConstraintCommand.class);
065: }
066:
067: //--------------------------------------------------------------- Lifecycle
068: private NotNullConstraint _constraint = null;
069:
070: public void setUp() throws Exception {
071: super .setUp();
072: CreateTableCommand create = new CreateTableCommand("FOO");
073: create.addColumn("A", "varchar", "10");
074: create.addColumn("B", "integer");
075: create.execute(getDatabase());
076: _constraint = new NotNullConstraint("BAR");
077: _constraint.addSelectable(new ColumnIdentifier("A"));
078: AddConstraintCommand cmd = new AddConstraintCommand("FOO",
079: _constraint);
080: cmd.execute(getDatabase());
081: }
082:
083: public void tearDown() throws Exception {
084: super .tearDown();
085: _constraint = null;
086: }
087:
088: protected AxionCommand makeCommand() {
089: return new DropConstraintCommand("FOO", "BAR", false);
090: }
091:
092: //------------------------------------------------------------------- Tests
093:
094: public void testExecute() throws Exception {
095: DropConstraintCommand cmd = new DropConstraintCommand("FOO",
096: "BAR", false);
097: assertTrue(!cmd.execute(getDatabase()));
098: }
099:
100: public void testExecuteUpdate() throws Exception {
101: DropConstraintCommand cmd = new DropConstraintCommand("FOO",
102: "BAR", false);
103: assertEquals(0, cmd.executeUpdate(getDatabase()));
104: }
105:
106: public void testExecuteQuery() throws Exception {
107: DropConstraintCommand cmd = new DropConstraintCommand("FOO",
108: "BAR", false);
109: try {
110: cmd.executeQuery(getDatabase());
111: fail("Expected UnsupportedOperationException");
112: } catch (UnsupportedOperationException e) {
113: // expected
114: }
115: }
116:
117: public void testExecuteWithNullTable() throws Exception {
118: DropConstraintCommand cmd = new DropConstraintCommand(null,
119: "BAR", false);
120: try {
121: cmd.execute(getDatabase());
122: fail("Expected AxionException");
123: } catch (AxionException e) {
124: // expected
125: }
126: }
127:
128: public void testExecuteWithNullConstraint() throws Exception {
129: DropConstraintCommand cmd = new DropConstraintCommand("FOO",
130: null, false);
131: try {
132: cmd.execute(getDatabase());
133: fail("Expected AxionException");
134: } catch (AxionException e) {
135: // expected
136: }
137: }
138:
139: public void testExecuteWithBadTable() throws Exception {
140: DropConstraintCommand cmd = new DropConstraintCommand("XYZZY",
141: "BAR", false);
142: try {
143: cmd.execute(getDatabase());
144: fail("Expected AxionException");
145: } catch (AxionException e) {
146: // expected
147: }
148: }
149:
150: public void testExecuteWithBadConstraint() throws Exception {
151: DropConstraintCommand cmd = new DropConstraintCommand("FOO",
152: "XYZZY", false);
153: try {
154: cmd.execute(getDatabase());
155: fail("Expected AxionException");
156: } catch (AxionException e) {
157: // expected
158: }
159: }
160:
161: }
|