001: /*
002: Derby - Class org.apache.derbyTesting.functionTests.tests.store.BootAllTest
003:
004: Licensed to the Apache Software Foundation (ASF) under one
005: or more contributor license agreements. See the NOTICE file
006: distributed with this work for additional information
007: regarding copyright ownership. The ASF licenses this file
008: to you under the Apache License, Version 2.0 (the
009: "License"); you may not use this file except in compliance
010: with the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing,
015: software distributed under the License is distributed on an
016: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: KIND, either express or implied. See the License for the
018: specific language governing permissions and limitations
019: under the License.
020: */
021:
022: package org.apache.derbyTesting.functionTests.tests.store;
023:
024: import org.apache.derbyTesting.functionTests.util.TestUtil;
025: import org.apache.derbyTesting.junit.BaseJDBCTestCase;
026:
027: import junit.framework.*;
028: import java.sql.*;
029: import java.util.Properties;
030: import java.util.Arrays;
031:
032: /**
033: * Tests for the system property "derby.system.bootAll"
034: *
035: * DERBY-1296 - Setting property derby.system.bootAll causes an Exception
036: *
037: */
038: public class BootAllTest extends BaseJDBCTestCase {
039:
040: private Driver driver;
041: private String databases[] = new String[] { "wombat1", "wombat2",
042: "wombat3" };
043:
044: final static String DATABASE_SHUT_DOWN = "08006";
045: final static String ALL_DATABASES_SHUT_DOWN = "XJ015";
046:
047: /**
048: * Creates a new instance of BootAllTest
049: */
050: public BootAllTest(String name) {
051: super (name);
052: }
053:
054: /**
055: * Create the databases
056: */
057: public void setUp() throws Exception {
058: for (int i = 0; i < databases.length; i++) {
059: Connection con = openConnection(databases[i]);
060: con.close();
061: try {
062: openConnection(databases[i] + ";shutdown=true");
063: } catch (SQLException se) {
064: assertEquals("Expected exception on setUp "
065: + se.getSQLState(), DATABASE_SHUT_DOWN, se
066: .getSQLState());
067: }
068: }
069: String url = getTestConfiguration().getJDBCUrl("");
070: driver = DriverManager.getDriver(url);
071: DriverManager.deregisterDriver(driver);
072: try {
073: driver.connect(url + ";shutdown=true", null);
074: } catch (SQLException se) {
075: assertEquals("Expected exception on tearDown "
076: + se.getSQLState(), ALL_DATABASES_SHUT_DOWN, se
077: .getSQLState());
078: }
079: System.runFinalization();
080: System.gc();
081: }
082:
083: /**
084: * Shutdown all databases
085: */
086: public void tearDown() throws Exception {
087: String driverName = getTestConfiguration().getJDBCClient()
088: .getJDBCDriverName();
089: Class.forName(driverName);
090: println("Teardown of: " + getName());
091: try {
092: openConnection(";shutdown=true");
093: } catch (SQLException se) {
094: assertEquals("Expected exception on tearDown "
095: + se.getSQLState(), ALL_DATABASES_SHUT_DOWN, se
096: .getSQLState());
097: }
098: }
099:
100: /**
101: * DERBY-1296 - Setting property derby.system.bootAll causes an Exception
102: *
103: * Check that setting the system property "derby.system.bootAll" will not
104: * cause an exception when used in combination with the system property
105: * "derby.system.home".
106: *
107: * The property "derby.system.home" is set by default for all tests and does
108: * not need to be explicitly set in this test.
109: */
110: public void testSettingBootAllPropertyWithHomePropertySet()
111: throws Exception {
112: String returnedDatabases[] = null;
113:
114: setSystemProperty("derby.system.bootAll", "true");
115:
116: String driverName = getTestConfiguration().getJDBCClient()
117: .getJDBCDriverName();
118: String url = getTestConfiguration().getJDBCUrl("");
119:
120: Class.forName(driverName).newInstance();
121: DriverManager.registerDriver(driver);
122:
123: Driver driver = DriverManager.getDriver(url);
124:
125: DriverPropertyInfo[] attributes = driver.getPropertyInfo(url,
126: null);
127: for (int i = 0; i < attributes.length; i++) {
128: if (attributes[i].name.equalsIgnoreCase("databaseName")) {
129: returnedDatabases = attributes[i].choices;
130: }
131: }
132:
133: Arrays.sort(returnedDatabases);
134:
135: assertEquals("The number of databases should be",
136: databases.length, returnedDatabases.length);
137:
138: for (int i = 0; i < databases.length; i++) {
139: assertEquals("Database names should be", databases[i],
140: returnedDatabases[i]);
141: }
142:
143: }
144:
145: }
|