OSDN Git Service

AI 143664: am: CL 143631 am: CL 143455 Bringing the SQL tests down to zero failures...
[android-x86/dalvik.git] / libcore / sql / src / test / java / tests / SQLite / JDBCDriverTest.java
1 /*
2  * Copyright (C) 2008 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.TestLevel;
22 import dalvik.annotation.TestTargetClass;
23 import dalvik.annotation.TestTargetNew;
24 import dalvik.annotation.TestTargets;
25
26 import java.sql.Connection;
27 import java.sql.Driver;
28 import java.sql.DriverManager;
29 import java.sql.DriverPropertyInfo;
30 import java.sql.SQLException;
31
32
33 @TestTargetClass(JDBCDriver.class)
34 public class JDBCDriverTest extends JDBCDriverFunctionalTest {
35     
36     /**
37      * The SQLite db file.
38      */
39     private JDBCDriver jDriver;
40     
41     private Driver returnedDriver;
42
43     public void setUp() throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException, Exception  {
44         
45         try {
46             super.setUp();
47             returnedDriver = DriverManager.getDriver(getConnectionURL());
48             if (returnedDriver instanceof JDBCDriver) {
49                 this.jDriver = (JDBCDriver) returnedDriver;
50             }
51         } catch (SQLException e) {
52           System.out.println("Cannot get driver");
53             e.printStackTrace();
54         } catch (Exception e) {
55             System.out.println("DB Setup failed");
56             e.printStackTrace();
57         }
58    }
59
60     /**
61      * @tests JDBCDriver#JDBCDriver()
62      */
63     @TestTargetNew(
64         level = TestLevel.COMPLETE,
65         notes = "constructor test",
66         method = "JDBCDriver",
67         args = {}
68     )
69     public void testJDBCDriver() {
70         assertTrue(returnedDriver instanceof JDBCDriver);
71     }
72
73     /**
74      * @tests JDBCDriver#acceptsURL(String)
75      */
76     @TestTargets({
77         @TestTargetNew(
78             level = TestLevel.COMPLETE,
79             notes = "constructor test",
80             method = "acceptsURL",
81             args = {java.lang.String.class}
82         ),
83         @TestTargetNew(
84             level = TestLevel.COMPLETE,
85             notes = "constructor test",
86             // we have to list the Driver target explicitly, since SQLite
87             // is not part of the target packages
88             clazz = Driver.class,
89             method = "acceptsURL",
90             args = {java.lang.String.class}
91         )        
92     })
93     public void testAcceptsURL() {
94         try {
95             if (this.jDriver != null) {
96                 assertTrue(jDriver.acceptsURL(getConnectionURL()));
97             } else {
98                 fail("no Driver available");
99             }
100         } catch (SQLException e) {
101             fail("Driver does not accept URL");
102             e.printStackTrace();
103         }
104     }
105
106     /**
107      * @tests JDBCDriver#connect(String, java.util.Properties)
108      */
109     @TestTargets({    
110         @TestTargetNew(
111             level = TestLevel.COMPLETE,
112             notes = "method test",
113             method = "connect",
114             args = {java.lang.String.class, java.util.Properties.class}
115         ),
116         @TestTargetNew(
117             level = TestLevel.COMPLETE,
118             // we have to list the Driver target explicitly, since SQLite
119             // is not part of the target packages
120             clazz = Driver.class,
121             notes = "method test",
122             method = "connect",
123             args = {java.lang.String.class, java.util.Properties.class}
124         )
125     })
126     public void testConnect() {
127         try {
128             if (this.jDriver != null) {
129                 Connection c = jDriver.connect(getConnectionURL(), null);
130                 assertFalse(c.isClosed());
131                 DriverManager.getConnection(getConnectionURL());
132             } else {
133                 fail("no Driver available");
134             }
135         } catch (SQLException e) {
136             fail("Driver does not connect");
137             e.printStackTrace();
138         }
139     }
140
141     /**
142      * @tests JDBCDriver#getMajorVersion()
143      */
144    @TestTargets({    
145         @TestTargetNew(
146             level = TestLevel.COMPLETE,
147             notes = "method test",
148             method = "getMajorVersion",
149             args = {}
150         ),
151         @TestTargetNew(
152             level = TestLevel.COMPLETE,
153             // we have to list the Driver target explicitly, since SQLite
154             // is not part of the target packages
155             clazz = Driver.class,
156             notes = "method test",
157             method = "getMajorVersion",
158             args = {}
159         )
160     })
161     public void testGetMajorVersion() {
162         if (this.jDriver != null) {
163             assertTrue(jDriver.getMajorVersion() > 0);
164         } else {
165             fail("no Driver available");
166         }
167     }
168
169     /**
170      * @tests JDBCDriver#getMinorVersion()
171      */
172    @TestTargets({       
173        @TestTargetNew(
174             level = TestLevel.COMPLETE,
175             notes = "method test",
176             method = "getMinorVersion",
177             args = {}
178         ),
179         @TestTargetNew(
180             level = TestLevel.COMPLETE,
181             notes = "method test",
182             // we have to list the Driver target explicitly, since SQLite
183             // is not part of the target packages
184             clazz = Driver.class,            
185             method = "getMinorVersion",
186             args = {}
187         )
188    })
189    public void testGetMinorVersion() {
190         if (this.jDriver != null) {
191             assertTrue(jDriver.getMinorVersion() > 0);
192         } else {
193             fail("no version information available");
194         }
195     }
196
197     /**
198      * @tests JDBCDriver#getPropertyInfo(String, java.util.Properties)
199      */
200    @TestTargets({
201        @TestTargetNew(
202             level = TestLevel.COMPLETE,
203             notes = "method test",
204             method = "getPropertyInfo",
205             args = {java.lang.String.class, java.util.Properties.class}
206         ),
207         @TestTargetNew(
208             level = TestLevel.COMPLETE,
209             notes = "method test",
210             // we have to list the Driver target explicitly, since SQLite
211             // is not part of the target packages
212             clazz = Driver.class,            
213             method = "getPropertyInfo",
214             args = {java.lang.String.class, java.util.Properties.class}
215         )
216    })
217    public void testGetPropertyInfo() {
218         DriverPropertyInfo[] info = null;
219         try {
220             if (this.jDriver != null) {
221                 info = jDriver.getPropertyInfo(getConnectionURL(), null);
222                 assertNotNull(info);
223                 assertTrue(info.length > 0);
224             } else {
225                 fail("no Driver available");
226             }
227         } catch (SQLException e) {
228             fail("Driver property details not available");
229             e.printStackTrace();
230         }
231         
232         assertNotNull(info);
233      
234     }
235
236     /**
237      * @tests JDBCDriver#jdbcCompliant()
238      */
239    @TestTargets({    
240         @TestTargetNew(
241             level = TestLevel.COMPLETE,
242             notes = "method test",
243             method = "jdbcCompliant",
244             args = {}
245         ),
246         @TestTargetNew(
247             level = TestLevel.COMPLETE,
248             // we have to list the Driver target explicitly, since SQLite
249             // is not part of the target packages
250             clazz = Driver.class,
251             notes = "method test",
252             method = "jdbcCompliant",
253             args = {}
254         )
255     }) 
256     public void testJdbcCompliant() {
257         if (this.jDriver != null) {
258             assertFalse(jDriver.jdbcCompliant());
259         } else {
260             fail("no version information available");
261         }
262     }
263     /**
264      * Tears down an unit test by calling the tearDown method of the super class
265      * and deleting the SQLite test db file.
266      */
267     @Override
268     protected void tearDown() throws SQLException {
269         super.tearDown();
270     }
271
272 }