Home | History | Annotate | Download | only in SQLite
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package tests.SQLite;
     18 
     19 import SQLite.Exception;
     20 import SQLite.JDBCDriver;
     21 import dalvik.annotation.TestTargetClass;
     22 
     23 import java.io.File;
     24 import java.io.IOException;
     25 import java.sql.Connection;
     26 import java.sql.SQLException;
     27 
     28 
     29 /**
     30  * Tests the SQLite.JDBCDriver.
     31  */
     32 @TestTargetClass(JDBCDriver.class)
     33 public class JDBCDriverFunctionalTest extends AbstractSqlTest {
     34 
     35 
     36 
     37     /**
     38      * The SQLite db file.
     39      */
     40     private  File dbFile = null;
     41 
     42     private String connectionURL = "empty";
     43 
     44     /**
     45      * Sets up an unit test by loading the SQLite.JDBCDriver, getting two
     46      * connections and calling the setUp method of the super class.
     47      * @throws Exception
     48      * @throws IllegalAccessException
     49      * @throws InstantiationException
     50      * @throws Exception
     51      * @throws Exception
     52      * @throws Exception
     53      * @throws Exception
     54      * @throws Exception
     55      */
     56     @Override
     57     public void setUp() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, Exception { // the Exception class needs to be fully
     58         // qualified since there is an Exception
     59         // class in the SQLite package.
     60 
     61         super.setUp();
     62     }
     63 
     64     /**
     65      * Tears down an unit test by calling the tearDown method of the super class
     66      * and deleting the SQLite test db file.
     67      */
     68     @Override
     69     protected void tearDown() throws SQLException {
     70         super.tearDown();
     71         dbFile.delete();
     72     }
     73 
     74 
     75     @Override
     76     protected String getConnectionURL() {
     77         if (connectionURL.equals("empty")) {
     78             String tmp = System.getProperty("java.io.tmpdir");
     79             File tmpDir = new File(tmp);
     80             if (tmpDir.isDirectory()) {
     81                 try {
     82                     dbFile = File.createTempFile("JDBCDriverFunctionalTest",
     83                             ".db", tmpDir);
     84                 } catch (IOException e) {
     85                     System.err.println("error creating temporary DB file.");
     86                 }
     87                 dbFile.deleteOnExit();
     88             } else {
     89                 System.err.println("java.io.tmpdir does not exist");
     90             }
     91 
     92             connectionURL = "jdbc:sqlite:/" + dbFile.getPath();
     93 
     94         }
     95 
     96         return connectionURL;
     97     }
     98 
     99     @Override
    100     protected String getDriverClassName() {
    101         return "SQLite.JDBCDriver";
    102     }
    103 
    104     @Override
    105     protected int getTransactionIsolation() {
    106         return Connection.TRANSACTION_SERIALIZABLE;
    107     }
    108 
    109 
    110 }
    111