ffc17aea798b5cf76b19df90af8464953440ef4b
[utils] /
1 package org.wamblee.support.persistence;
2
3 import java.sql.Connection;
4
5 import javax.sql.DataSource;
6
7 import org.junit.After;
8 import org.junit.Before;
9 import org.junit.Test;
10 import org.wamblee.support.persistence.Database;
11 import org.wamblee.support.persistence.DatabaseBuilder;
12
13
14 public class DerbyDatabaseTest {
15
16         private Database db; 
17         private DataSource ds; 
18         
19         @Before
20         public void setUp() { 
21                 db = DatabaseBuilder.getDatabase();
22                 ds = db.start();
23         }
24         
25         @After
26         public void tearDown() { 
27                 db.stop(); 
28         }
29         
30         @Test
31         public void testConnect() throws Exception { 
32                 Connection conn = ds.getConnection();
33                 try { 
34                         System.out.println("Database name: " + conn.getMetaData().getDatabaseProductName());  
35                 } finally { 
36                         conn.close();
37                 }
38         }
39         
40         @Test
41         public void testUseASecondTimeInTheSameTestCase() throws Exception { 
42                 testConnect(); 
43                 tearDown();
44                 setUp();
45                 testConnect();
46         }
47 }