01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.derby;
17:
18: import java.io.File;
19: import java.io.IOException;
20: import java.sql.Connection;
21: import java.sql.DriverManager;
22: import java.sql.SQLException;
23: import java.util.Properties;
24:
25: import junit.framework.TestCase;
26: import org.apache.geronimo.system.serverinfo.ServerInfo;
27: import org.apache.geronimo.system.serverinfo.BasicServerInfo;
28:
29: /**
30: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
31: */
32: public class DerbySystemGBeanTest extends TestCase {
33: private File systemDir;
34:
35: public void testCreateSystemUsingServerInfo() throws Exception {
36: ServerInfo serverInfo = new BasicServerInfo(systemDir
37: .toString());
38: String derbyDir = "var/dbderby";
39: DerbySystemGBean gbean = new DerbySystemGBean(serverInfo,
40: derbyDir);
41: try {
42: gbean.doStart();
43: new org.apache.derby.jdbc.EmbeddedDriver();
44: connect();
45: gbean.doStop();
46: assertTrue(new File(systemDir, derbyDir + "/derby.log")
47: .exists());
48: } catch (Exception e) {
49: fail(e.getMessage());
50: }
51: }
52:
53: private void connect() throws SQLException {
54: Connection c = DriverManager
55: .getConnection("jdbc:derby:testdb;create=true");
56: c.close();
57: }
58:
59: protected void setUp() throws Exception {
60: try {
61: super .setUp();
62: systemDir = File.createTempFile("derbyTest", ".tmp");
63: systemDir.delete();
64: systemDir.mkdir();
65:
66: Properties props = System.getProperties();
67: props.remove("derby.system.home");
68: } catch (Exception e) {
69: delete(systemDir);
70: throw e;
71: }
72: }
73:
74: protected void tearDown() throws Exception {
75: delete(systemDir);
76: super .tearDown();
77: }
78:
79: private void delete(File file) throws IOException {
80: if (file == null) {
81: return;
82: }
83:
84: File[] files = file.listFiles();
85: if (files != null) {
86: for (int i = 0; i < files.length; i++) {
87: delete(files[i]);
88: }
89: }
90: file.delete();
91: }
92: }
|