1   package test.tuigwaa;
2   
3   import java.sql.Connection;
4   import java.sql.PreparedStatement;
5   import java.sql.ResultSet;
6   
7   import javax.sql.DataSource;
8   
9   import junit.extensions.TestSetup;
10  import junit.framework.Test;
11  import junit.framework.TestCase;
12  import junit.framework.TestSuite;
13  
14  import org.seasar.extension.dbcp.ConnectionPool;
15  import org.seasar.framework.container.S2Container;
16  import org.seasar.framework.container.factory.S2ContainerFactory;
17  
18  import com.isenshi.util.extlib.HSQLDBUtil;
19  
20  /***
21   * @author someda
22   */
23  public class HsqldbTest extends TestCase {
24  
25  	private static S2Container container;
26  	
27  	DataSource datasource;
28  	ConnectionPool connectionPool;
29  	
30  	public static Test suite() throws Exception{
31  		
32  		TestSuite suite = new TestSuite(HsqldbTest.class);
33  		TestSetup setup = new TestSetup(suite){
34  			
35  			public void setUp() throws Exception{
36  				container = S2ContainerFactory.create("dicon/basedb.dicon");
37  				container.init();				
38  			}
39  			
40  		};
41  		return setup;
42  	}
43  		
44  	public void setUp(){
45  		datasource = (DataSource) container.getComponent(DataSource.class);
46  		connectionPool = (ConnectionPool)container.getComponent(ConnectionPool.class);
47  	}
48  	
49  	public void testShowPoolsize(){
50  		System.out.println("active pool    : " + connectionPool.getActivePoolSize());
51  		System.out.println("free pool      : " + connectionPool.getFreePoolSize());
52  		System.out.println("tx active pool : " + connectionPool.getTxActivePoolSize());		
53  	}
54  	
55  		
56  	public void testShutdown() throws Exception{
57  		
58  		HSQLDBUtil.shutdown(datasource);		
59  		
60  		Connection con = datasource.getConnection();
61  		PreparedStatement pstmt = con.prepareStatement("select * from uri");
62  		ResultSet rs = pstmt.executeQuery();
63  		while(rs.next()){
64  			System.out.println(rs.getString("URI_STRING"));
65  		}
66  	}
67  		
68  }