Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 63405 invoked from network); 15 Jul 2008 17:01:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 15 Jul 2008 17:01:57 -0000 Received: (qmail 58638 invoked by uid 500); 15 Jul 2008 17:01:57 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 58617 invoked by uid 500); 15 Jul 2008 17:01:57 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 58608 invoked by uid 99); 15 Jul 2008 17:01:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jul 2008 10:01:57 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jul 2008 17:01:12 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 948512388A0A; Tue, 15 Jul 2008 10:01:36 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r676970 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java Date: Tue, 15 Jul 2008 17:01:36 -0000 To: derby-commits@db.apache.org From: kmarsden@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080715170136.948512388A0A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kmarsden Date: Tue Jul 15 10:01:36 2008 New Revision: 676970 URL: http://svn.apache.org/viewvc?rev=676970&view=rev Log: DERBY-3754 Convert "org.apache.derbyTesting.functionTests.tests.lang.connect.sql" to junit Contributed by Junjie Peng Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java (with props) Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java?rev=676970&view=auto ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java (added) +++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java Tue Jul 15 10:01:36 2008 @@ -0,0 +1,140 @@ +/* + + Derby - Class org.apache.derbyTesting.functionTests.tests.lang.ConnectTest + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License +*/ +package org.apache.derbyTesting.functionTests.tests.lang; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.derbyTesting.junit.BaseJDBCTestCase; +import org.apache.derbyTesting.junit.JDBC; +import org.apache.derbyTesting.junit.TestConfiguration; + +/** + * Test case for connect.sql. + */ +public class ConnectTest extends BaseJDBCTestCase{ + + public ConnectTest(String name) { + super(name); + } + + public static Test suite() { + if ( JDBC.vmSupportsJSR169()) + // Test uses DriverManager which + // is not supported with JSR169 + return + new TestSuite("empty ConnectTest:DriverManager not supported"); + else + return TestConfiguration.defaultSuite(ConnectTest.class); + } + + /** + * Test whether we can reconnect. + */ + public void testConnectRepeatedly() throws SQLException { + String url = "jdbc:derby:wombat;create=true"; + Connection con = DriverManager.getConnection(url); + + Statement st = con.createStatement(); + JDBC.assertSingleValueResultSet(st.executeQuery("values 1"), "1"); + st.close(); + con.close(); + + // Can we reconnect? + con = DriverManager.getConnection(url); + st = con.createStatement(); + JDBC.assertSingleValueResultSet(st.executeQuery("values 1"), "1"); + st.close(); + con.close(); + } + + /** + * Test on kinds of database names. + */ + public void testDBName() throws SQLException { + // Do we get a non-internal error when we try to create + // over an existing directory? (T#674) + String url = "jdbc:derby:wombat/seg0;create=true"; + try { + DriverManager.getConnection(url); + fail("Error XBM0J is expected"); + } catch (SQLException e) { + assertEquals("XJ041", e.getSQLState()); + } + + // -- check to ensure an empty database name is taken + // -- as the name, over any connection attribute. + // -- this should fail. + url = "jdbc:derby: ;databaseName=wombat"; + try { + DriverManager.getConnection(url); + fail("Error XJ004 is expected"); + } catch (SQLException e) { + assertEquals("XJ004", e.getSQLState()); + } + + // and this should succeed (no database name in URL) + url = "jdbc:derby:;databaseName=wombat"; + Connection con = DriverManager.getConnection(url); + con.close(); + } + + /** + * Doing some simple grant/revoke negative tests in legacy database. + * All should fail with errors. + */ + public void testGrantAndRevoke() throws SQLException { + String url = "jdbc:derby:wombat"; + Connection con = DriverManager.getConnection(url); + + String sql = "create table mytab(i int)"; + Statement st = con.createStatement(); + st.execute(sql); + + sql = "grant select on mytab to satheesh"; + try { + st.executeUpdate(sql); + fail("Error 42Z60 is expected"); + } catch (SQLException e) { + assertEquals("42Z60", e.getSQLState()); + } + + sql = "revoke select on mytab to satheesh"; + try { + st.executeUpdate(sql); + fail("Error 42Z60 is expected"); + } catch (SQLException e) { + assertEquals("42Z60", e.getSQLState()); + } + + sql = "drop table mytab"; + st.execute(sql); + + st.close(); + con.close(); + } +} Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConnectTest.java ------------------------------------------------------------------------------ svn:eol-style = native