mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
support initSqls
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
public class DruidDataSourceTest_initSql extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
List<Object> sqlList = new ArrayList<Object>();
|
||||
sqlList.add("select 123");
|
||||
sqlList.add(null);
|
||||
sqlList.add("");
|
||||
|
||||
dataSource.setConnectionInitSqls(sqlList);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void testDefault() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
MockConnection mockConn = conn.unwrap(MockConnection.class);
|
||||
|
||||
Assert.assertEquals("select 123", mockConn.getLastSql());
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidDataSourceFactory;
|
||||
|
||||
public class DruidDataSourceTest_initSql_factory extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
Properties properties = new Properties();
|
||||
properties.put(DruidDataSourceFactory.PROP_URL, "jdbc:mock:xxx");
|
||||
properties.put(DruidDataSourceFactory.PROP_INITCONNECTIONSQLS, ";;select 123");
|
||||
dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void testDefault() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
MockConnection mockConn = conn.unwrap(MockConnection.class);
|
||||
|
||||
Assert.assertEquals("select 123", mockConn.getLastSql());
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
public class DruidDataSourceTest9 extends TestCase {
|
||||
public class DruidDataSourceTest_initSqls extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
Reference in New Issue
Block a user