001: /*
002: * $Id: TestFunctional.java,v 1.3 2003/11/07 08:11:13 jstrachan Exp $
003: * =======================================================================
004: * Copyright (c) 2002 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;
042:
043: import java.sql.Connection;
044: import java.sql.DriverManager;
045: import java.sql.ResultSet;
046: import java.sql.SQLException;
047: import java.sql.Statement;
048:
049: import junit.framework.Test;
050: import junit.framework.TestSuite;
051:
052: import org.apache.commons.logging.Log;
053: import org.apache.commons.logging.LogFactory;
054:
055: /**
056: * @version $Revision: 1.3 $ $Date: 2003/11/07 08:11:13 $
057: * @author Chuck Burdick
058: */
059: public class TestFunctional extends AbstractDbdirTest {
060: private static final Log _log = LogFactory
061: .getLog(TestFunctional.class);
062: private Connection _conn = null;
063: private ResultSet _rset = null;
064: private Statement _stmt = null;
065:
066: public TestFunctional(String testName) {
067: super (testName);
068: }
069:
070: public static void main(String args[]) {
071: String[] testCaseName = { TestFunctional.class.getName() };
072: junit.textui.TestRunner.main(testCaseName);
073: }
074:
075: public static Test suite() {
076: return new TestSuite(TestFunctional.class);
077: }
078:
079: public void setUp() throws SQLException, ClassNotFoundException {
080: Class.forName("org.axiondb.jdbc.AxionDriver");
081: _conn = DriverManager.getConnection("jdbc:axiondb:memdb");
082: _stmt = _conn.createStatement();
083: }
084:
085: public void tearDown() throws Exception {
086: cleanJdbc();
087: {
088: Connection conn = DriverManager
089: .getConnection("jdbc:axiondb:memdb");
090: Statement stmt = conn.createStatement();
091: stmt.execute("shutdown");
092: stmt.close();
093: conn.close();
094: }
095: super .tearDown();
096: }
097:
098: public void testCreate() {
099: _log.debug("Starting testCreate()");
100: assertNotNull("Should have a valid connection", _conn);
101: assertNotNull("Should have a valid statement", _stmt);
102: }
103:
104: public void testCreateTable() throws SQLException {
105: _log.debug("Starting testCreateTable()");
106: String sql = "CREATE TABLE foo ( test VARCHAR )";
107: assertTrue("Should not generate result set", !_stmt
108: .execute(sql));
109: }
110:
111: public void testInsertNoTable() {
112: _log.debug("Starting testInsertNoTable()");
113: try {
114: String sql = "INSERT INTO foo ( test ) VALUES ( 'this' )";
115: _stmt.execute(sql);
116: fail("Should throw SQLException because no tables defined");
117: } catch (SQLException e) {
118: // expected
119: }
120: }
121:
122: public void testInsertWrongTable() throws SQLException {
123: _log.debug("Starting testInsertWrongTable()");
124: testCreateTable();
125: try {
126: String sql = "INSERT INTO bar ( test ) VALUES ( 'this' )";
127: _stmt.execute(sql);
128: fail("Should throw SQLException because no tables defined");
129: } catch (SQLException e) {
130: // expected
131: }
132: }
133:
134: public void testInsert() throws SQLException {
135: _log.debug("Starting testInsert()");
136: testCreateTable();
137: String sql = "INSERT INTO foo ( test ) VALUES ( 'this' );";
138:
139: sql = "SELECT test FROM foo";
140: _rset = _stmt.executeQuery(sql);
141: assertNotNull("Should get results", _rset);
142: while (_rset.next()) {
143: assertEquals("Should have result", "this", _rset
144: .getString(1));
145: }
146: }
147:
148: // UTILITY METHODS
149:
150: private void cleanJdbc() {
151: try {
152: _rset.close();
153: } catch (Exception t) {
154: }
155: try {
156: _stmt.close();
157: } catch (Exception t) {
158: }
159: try {
160: _conn.close();
161: } catch (Exception t) {
162: }
163: _rset = null;
164: _stmt = null;
165: _conn = null;
166: }
167: }
|