001: /* Copyright (c) 2001-2005, The HSQL Development Group
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * Redistributions of source code must retain the above copyright notice, this
008: * list of conditions and the following disclaimer.
009: *
010: * Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * Neither the name of the HSQL Development Group nor the names of its
015: * contributors may be used to endorse or promote products derived from this
016: * software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
022: * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
025: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
026: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
027: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
028: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package org.hsqldb.test;
032:
033: import java.sql.Connection;
034: import java.sql.ResultSet;
035: import java.sql.Statement;
036:
037: import junit.framework.TestCase;
038: import junit.framework.TestResult;
039:
040: /**
041: * Tests for stored procedures.
042: *
043: * @author fredt@users
044: * @version 1.7.2
045: * @since 1.7.2
046: */
047: public class TestStoredProcedure extends TestBase {
048:
049: public TestStoredProcedure(String name) {
050: super (name);
051: }
052:
053: public void test() throws Exception {
054:
055: Connection conn = newConnection();
056: Statement statement;
057: int updateCount;
058:
059: try {
060: statement = conn.createStatement();
061:
062: ResultSet rs = statement
063: .executeQuery("call \"org.hsqldb.test.TestStoredProcedure.procTest1\"()");
064:
065: rs.next();
066:
067: int cols = rs.getInt(1);
068:
069: assertTrue("test result not correct", cols == 2);
070: } catch (Exception e) {
071: assertTrue("unable to execute call to procedure", false);
072: } finally {
073: conn.close();
074: }
075:
076: conn = newConnection();
077:
078: try {
079: statement = conn.createStatement();
080: } catch (Exception e) {
081: assertTrue("unexpected error", false);
082: } finally {
083: conn.close();
084: }
085: }
086:
087: public static int procTest1(Connection conn)
088: throws java.sql.SQLException {
089:
090: int cols;
091: java.sql.Statement stmt = conn.createStatement();
092:
093: stmt
094: .execute("CREATE temp TABLE MYTABLE(COL1 INTEGER,COL2 VARCHAR);");
095: stmt.execute("INSERT INTO MYTABLE VALUES (1,'test1');");
096: stmt.execute("INSERT INTO MYTABLE VALUES(2,'test2');");
097:
098: java.sql.ResultSet rs = stmt
099: .executeQuery("select * from MYTABLE");
100: java.sql.ResultSetMetaData meta = rs.getMetaData();
101:
102: cols = meta.getColumnCount();
103:
104: rs.close();
105: stmt.close();
106:
107: return cols;
108: }
109:
110: public static void main(String[] args) throws Exception {
111:
112: TestResult result;
113: TestCase test;
114: java.util.Enumeration failures;
115: int count;
116:
117: result = new TestResult();
118: test = new TestStoredProcedure("test");
119:
120: test.run(result);
121:
122: count = result.failureCount();
123:
124: System.out.println("TestStoredProcedure failure count: "
125: + count);
126:
127: failures = result.failures();
128:
129: while (failures.hasMoreElements()) {
130: System.out.println(failures.nextElement());
131: }
132: }
133: }
|