Home » geronimo-2.2-source-release » org.apache.geronimo.derby » [javadoc | source]

    1   /**
    2    *
    3    * Copyright 2003-2004 The Apache Software Foundation
    4    *
    5    *  Licensed under the Apache License, Version 2.0 (the "License");
    6    *  you may not use this file except in compliance with the License.
    7    *  You may obtain a copy of the License at
    8    *
    9    *     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    */
   17   
   18   package org.apache.geronimo.derby;
   19   
   20   import java.io.File;
   21   import java.io.IOException;
   22   import java.sql.Connection;
   23   import java.sql.DriverManager;
   24   import java.sql.SQLException;
   25   import java.util.Properties;
   26   
   27   import junit.framework.TestCase;
   28   import org.apache.geronimo.system.serverinfo.ServerInfo;
   29   
   30   /**
   31    * @version $Rev: 47413 $ $Date: 2004-09-28 11:46:39 -0700 (Tue, 28 Sep 2004) $
   32    */
   33   public class DerbySystemGBeanTest extends TestCase {
   34       private File systemDir;
   35   
   36       public void testCreateSystemUsingServerInfo() throws Exception {
   37           ServerInfo serverInfo = new ServerInfo(systemDir.toString());
   38           String derbyDir = "var/dbderby";
   39           DerbySystemGBean gbean = new DerbySystemGBean(serverInfo, derbyDir);
   40           try {
   41               gbean.doStart();
   42               new org.apache.derby.jdbc.EmbeddedDriver();
   43               connect();
   44               gbean.doStop();
   45               assertTrue(new File(systemDir, derbyDir+"/derby.log").exists());
   46           } catch (Exception e) {
   47               fail(e.getMessage());
   48           }
   49       }
   50   
   51       private void connect() throws SQLException {
   52           Connection c = DriverManager.getConnection("jdbc:derby:testdb;create=true");
   53           c.close();
   54       }
   55   
   56       protected void setUp() throws Exception {
   57           try {
   58               super.setUp();
   59               systemDir = File.createTempFile("derbyTest", ".tmp");
   60               systemDir.delete();
   61               systemDir.mkdir();
   62   
   63               Properties props = System.getProperties();
   64               props.remove("derby.system.home");
   65           } catch (Exception e) {
   66               delete(systemDir);
   67               throw e;
   68           }
   69       }
   70   
   71       protected void tearDown() throws Exception {
   72           delete(systemDir);
   73           super.tearDown();
   74       }
   75   
   76       private void delete(File file) throws IOException {
   77           if (file == null) {
   78               return;
   79           }
   80   
   81           File[] files = file.listFiles();
   82           if (files != null) {
   83               for (int i = 0; i < files.length; i++) {
   84                   delete(files[i]);
   85               }
   86           }
   87           file.delete();
   88       }
   89   }

Home » geronimo-2.2-source-release » org.apache.geronimo.derby » [javadoc | source]