1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/*
Derby - Class
org.apache.derbyTesting.functionTests.tests.jdbcapi.DriverMgrAuthenticationTest
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.jdbcapi;
import java.sql.DriverManager;
import java.sql.SQLException;
import junit.framework.Test;
import org.apache.derbyTesting.junit.BaseTestSuite;
import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.TestConfiguration;
// Extends AuthenticationTest.java which only holds DataSource calls
// this class uses some of the same methods but uses DriverManager to
// obtain connections
public class DriverMgrAuthenticationTest extends AuthenticationTest {
/** Creates a new instance of the Test */
public DriverMgrAuthenticationTest(String name) {
super(name);
}
public static Test suite() {
// This test uses driverManager and so is not suitable for JSR169
if (JDBC.vmSupportsJSR169())
return new BaseTestSuite(
"DriverManager not available with JSR169;" +
"empty DriverMgrAuthenticationTest");
else {
BaseTestSuite suite =
new BaseTestSuite("DriverMgrAuthenticationTest");
suite.addTest(
baseSuite("DriverMgrAuthenticationTest:embedded"));
suite.addTest(TestConfiguration.clientServerDecorator(
baseSuite("DriverMgrAuthenticationTest:client")));
return suite;
}
}
// baseSuite takes advantage of setting system properties as defined
// in AuthenticationTest
public static Test baseSuite(String name) {
BaseTestSuite suite =
new BaseTestSuite("DriverMgrAuthenticationTest");
Test test = new DriverMgrAuthenticationTest(
"testConnectShutdownAuthentication");
setBaseProps(suite, test);
test = new DriverMgrAuthenticationTest("testUserFunctions");
setBaseProps(suite, test);
test = new DriverMgrAuthenticationTest("testNotFullAccessUsers");
setBaseProps(suite, test);
test = new DriverMgrAuthenticationTest(
"testChangePasswordAndDatabasePropertiesOnly");
setBaseProps(suite, test);
// only part of this fixture runs with network server / client
test = new DriverMgrAuthenticationTest("testGreekCharacters");
setBaseProps(suite, test);
test = new DriverMgrAuthenticationTest("testSystemShutdown");
setBaseProps(suite, test);
// The test needs to run in a new single use database as we're
// setting a number of properties
return TestConfiguration.singleUseDatabaseDecorator(suite);
}
protected void assertConnectionOK(
String dbName, String user, String password)
throws SQLException
{
String url = TestConfiguration.getCurrent().getJDBCUrl(dbName);
DriverManager.getConnection(url, user, password).close();
}
// getConnection(), using url connection attributes
protected void assertConnectionWOUPOK(
String dbName, String user, String password)
throws SQLException
{
String url = TestConfiguration.getCurrent().getJDBCUrl(dbName);
String url2 = url + ";user=" + user + ";password=" + password;
DriverManager.getConnection(url2).close();
}
protected void assertConnectionFail(
String expectedSqlState, String dbName, String user, String password)
throws SQLException
{
String url = TestConfiguration.getCurrent().getJDBCUrl(dbName);
try {
DriverManager.getConnection(url, user, password);
fail("Connection should've been refused/failed");
}
catch (SQLException e) {
assertSQLState(expectedSqlState, e);
}
}
protected void assertConnectionWOUPFail(
String expectedSqlState, String dbName, String user, String password)
throws SQLException
{
String url = TestConfiguration.getCurrent().getJDBCUrl(dbName);
String url2 = url + ";user=" + user + ";password=" + password;
try {
DriverManager.getConnection(url2);
fail("Connection should've been refused/failed");
}
catch (SQLException e) {
assertSQLState(expectedSqlState, e);
}
}
protected void assertShutdownOK(
String dbName, String user, String password)
throws SQLException {
String url = TestConfiguration.getCurrent().getJDBCUrl(dbName) +
";shutdown=true";
try {
DriverManager.getConnection(url, user, password);
fail ("expected a failed shutdown connection");
} catch (SQLException e) {
// expect 08006 on successful shutdown
assertSQLState("08006", e);
}
}
// differs from assertShutdownOK by using getConnection(url)
protected void assertShutdownWOUPOK(
String dbName, String user, String password)
throws SQLException {
String url = TestConfiguration.getCurrent().getJDBCUrl(dbName);
url = url + ";shutdown=true;user=" + user + ";password=" + password;
try {
DriverManager.getConnection(url, null);
fail ("expected a error after shutdown connection");
} catch (SQLException e) {
// expect 08006 on successful shutdown
assertSQLState("08006", e);
}
}
protected void assertShutdownFail(
String expectedSqlState, String dbName, String user, String password)
throws SQLException
{
String url = TestConfiguration.getCurrent().getJDBCUrl(dbName) +
";shutdown=true";
try {
DriverManager.getConnection(url, user, password);
fail("expected failed shutdown");
} catch (SQLException e) {
assertSQLState(expectedSqlState, e);
}
}
// differs from assertShutdownFail in using getConnection(url)
protected void assertShutdownWOUPFail(
String expectedSqlState, String dbName, String user, String password)
throws SQLException
{
String url = TestConfiguration.getCurrent().getJDBCUrl(dbName);
String url2 =
url + ";user=" + user + ";password=" + password + ";shutdown=true";
try {
DriverManager.getConnection(url2);
fail("expected failed shutdown");
} catch (SQLException e) {
assertSQLState(expectedSqlState, e);
}
}
protected void assertSystemShutdownOK(
String dbName, String user, String password)
throws SQLException
{
String url = TestConfiguration.getCurrent().getJDBCUrl(dbName);
if (usingDerbyNetClient() && dbName=="")
// The junit test harness that kicked off the test will hang when
// we attempt to shutdown the system - most likely because we're
// shutting down the system while the network server thread is
// still alive, so it gets confused...
return;
String url2 =
url + ";user=" + user + ";password=" + password + ";shutdown=true";
try {
DriverManager.getConnection(url2);
fail("expected successful shutdown");
} catch (SQLException e) {
assertSQLState("XJ015", e);
}
}
protected void assertSystemShutdownFail(
String expectedSqlState, String dbName, String user, String password)
throws SQLException
{
String url = TestConfiguration.getCurrent().getJDBCUrl(dbName);
if (usingDerbyNetClient() && dbName=="")
// The junit test harness that kicked off the test will hang when
// we attempt to shutdown the system - most likely because we're
// shutting down the system while the network server thread is
// still alive, so it gets confused...
return;
String url2 =
url + ";user=" + user + ";password=" + password + ";shutdown=true";
try {
//DriverManager.getConnection(url2, user, password);
DriverManager.getConnection(url2);
fail("expected failed shutdown");
} catch (SQLException e) {
assertSQLState(expectedSqlState, e);
}
}
public void assertConnectionFail(String dbName) throws SQLException {
// this method needs to not use default user/pwd (APP, APP).
String url = TestConfiguration.getCurrent().getJDBCUrl(dbName);
try {
DriverManager.getConnection(url);
fail("expected connection to fail");
}
catch (SQLException e) {
assertSQLState("08004", e);
}
}
}
|