KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > store > BootAllTest


1 /*
2    Derby - Class org.apache.derbyTesting.functionTests.tests.store.BootAllTest
3
4    Licensed to the Apache Software Foundation (ASF) under one
5    or more contributor license agreements. See the NOTICE file
6    distributed with this work for additional information
7    regarding copyright ownership. The ASF licenses this file
8    to you under the Apache License, Version 2.0 (the
9    "License"); you may not use this file except in compliance
10    with the License. You may obtain a copy of the License at
11    
12    http://www.apache.org/licenses/LICENSE-2.0
13    
14    Unless required by applicable law or agreed to in writing,
15    software distributed under the License is distributed on an
16    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17    KIND, either express or implied. See the License for the
18    specific language governing permissions and limitations
19    under the License.
20 */

21
22 package org.apache.derbyTesting.functionTests.tests.store;
23
24 import org.apache.derbyTesting.functionTests.util.TestUtil;
25 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
26
27 import junit.framework.*;
28 import java.sql.*;
29 import java.util.Properties JavaDoc;
30 import java.util.Arrays JavaDoc;
31
32 /**
33  * Tests for the system property "derby.system.bootAll"
34  *
35  * DERBY-1296 - Setting property derby.system.bootAll causes an Exception
36  *
37  */

38 public class BootAllTest extends BaseJDBCTestCase {
39
40     private Driver driver;
41     private String JavaDoc databases[] = new String JavaDoc[] {"wombat1", "wombat2", "wombat3"};
42     
43     final static String JavaDoc DATABASE_SHUT_DOWN = "08006";
44     final static String JavaDoc ALL_DATABASES_SHUT_DOWN = "XJ015";
45
46     /**
47      * Creates a new instance of BootAllTest
48      */

49     public BootAllTest(String JavaDoc name) {
50         super(name);
51     }
52
53     /**
54      * Create the databases
55      */

56     public void setUp() throws Exception JavaDoc {
57         for (int i = 0; i < databases.length; i++) {
58             Connection con = openConnection(databases[i]);
59             con.close();
60             try {
61                 openConnection(databases[i] + ";shutdown=true");
62             } catch (SQLException se) {
63                 assertEquals("Expected exception on setUp " + se.getSQLState(),
64                         DATABASE_SHUT_DOWN, se.getSQLState());
65             }
66         }
67         String JavaDoc url = getTestConfiguration().getJDBCUrl("");
68         driver = DriverManager.getDriver(url);
69         DriverManager.deregisterDriver(driver);
70         try {
71             driver.connect(url + ";shutdown=true", null);
72         } catch (SQLException se) {
73             assertEquals("Expected exception on tearDown " + se.getSQLState(),
74                     ALL_DATABASES_SHUT_DOWN, se.getSQLState());
75         }
76         System.runFinalization();
77         System.gc();
78     }
79
80     /**
81      * Shutdown all databases
82      */

83     public void tearDown() throws Exception JavaDoc {
84         String JavaDoc driverName = getTestConfiguration().getJDBCClient().getJDBCDriverName();
85         Class.forName(driverName);
86         println("Teardown of: " + getName());
87         try {
88             openConnection(";shutdown=true");
89         } catch (SQLException se) {
90             assertEquals("Expected exception on tearDown " + se.getSQLState(),
91                     ALL_DATABASES_SHUT_DOWN, se.getSQLState());
92         }
93     }
94
95     /**
96      * DERBY-1296 - Setting property derby.system.bootAll causes an Exception
97      *
98      * Check that setting the system property "derby.system.bootAll" will not
99      * cause an exception when used in combination with the system property
100      * "derby.system.home".
101      *
102      * The property "derby.system.home" is set by default for all tests and does
103      * not need to be explicitly set in this test.
104      */

105     public void testSettingBootAllPropertyWithHomePropertySet()
106             throws Exception JavaDoc
107     {
108         String JavaDoc returnedDatabases[] = null;
109
110         setSystemProperty("derby.system.bootAll", "true");
111
112         String JavaDoc driverName = getTestConfiguration().getJDBCClient().getJDBCDriverName();
113         String JavaDoc url = getTestConfiguration().getJDBCUrl("");
114
115         Class.forName(driverName).newInstance();
116         DriverManager.registerDriver(driver);
117
118         Driver driver = DriverManager.getDriver(url);
119
120         DriverPropertyInfo[] attributes = driver.getPropertyInfo(url, null);
121         for (int i = 0; i < attributes.length; i++) {
122             if (attributes[i].name.equalsIgnoreCase("databaseName")) {
123                 returnedDatabases = attributes[i].choices;
124             }
125         }
126
127         Arrays.sort(returnedDatabases);
128
129         assertEquals("The number of databases should be",
130                 databases.length,
131                 returnedDatabases.length);
132
133         for (int i = 0; i < databases.length; i++) {
134             assertEquals("Database names should be",
135                     databases[i],
136                     returnedDatabases[i]);
137         }
138
139     }
140     
141 }
142
Popular Tags