mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
test refactor
This commit is contained in:
@@ -170,25 +170,20 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty</artifactId>
|
||||
<version>6.1.26</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -196,6 +191,14 @@
|
||||
<artifactId>spring</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ import com.alibaba.druid.spring.IUserService;
|
||||
import com.alibaba.druid.spring.User;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
public class SpringFilterTest extends TestCase {
|
||||
public class SpringIbatisFilterTest extends TestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
@@ -34,7 +34,7 @@ public class SpringFilterTest extends TestCase {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"com/alibaba/druid/pool/spring-config-1.xml");
|
||||
"com/alibaba/druid/pool/ibatis/spring-config-ibatis.xml");
|
||||
|
||||
DataSource dataSource = (DataSource) context.getBean("dataSource");
|
||||
|
||||
+70
-92
@@ -1,92 +1,70 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
|
||||
default-lazy-init="false">
|
||||
|
||||
<bean class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"
|
||||
id="master-sqlMapClient">
|
||||
<property name="configLocation" value="com/alibaba/druid/pool/ibatis-config-druid-test.xml" />
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="sequence-dao" class="com.alibaba.druid.spring.SequenceDao">
|
||||
<property name="sqlMapClient" ref="master-sqlMapClient" />
|
||||
</bean>
|
||||
<bean id="sequence-service" class="com.alibaba.druid.spring.SequenceService">
|
||||
<property name="dao" ref="sequence-dao" />
|
||||
</bean>
|
||||
|
||||
<bean id="user-dao" class="com.alibaba.druid.spring.UserDao">
|
||||
<property name="sqlMapClient" ref="master-sqlMapClient" />
|
||||
</bean>
|
||||
<bean id="user-service" class="com.alibaba.druid.spring.UserService">
|
||||
<property name="dao" ref="user-dao" />
|
||||
<property name="sequenceService" ref="sequence-service" />
|
||||
</bean>
|
||||
<!-- -->
|
||||
|
||||
<bean id="test-filter" class="com.alibaba.druid.bvt.pool.SpringFilterTest$TestFilter">
|
||||
</bean>
|
||||
<bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
|
||||
</bean>
|
||||
|
||||
<bean id="wall-filter-config" class="com.alibaba.druid.wall.WallConfig"
|
||||
init-method="init">
|
||||
<property name="dir" value="META-INF/druid/wall/mysql" />
|
||||
<property name="noneBaseStatementAllow" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
|
||||
<property name="dbType" value="mysql" />
|
||||
<property name="config" ref="wall-filter-config" />
|
||||
</bean>
|
||||
|
||||
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
|
||||
init-method="init" destroy-method="close">
|
||||
<property name="url">
|
||||
<value>jdbc:derby:memory:spring-test;create=true</value>
|
||||
</property>
|
||||
<property name="initialSize">
|
||||
<value>1</value>
|
||||
</property>
|
||||
<property name="maxActive">
|
||||
<value>20</value>
|
||||
</property>
|
||||
<property name="proxyFilters">
|
||||
<list>
|
||||
<ref bean="test-filter" />
|
||||
<ref bean="stat-filter" />
|
||||
<ref bean="wall-filter" />
|
||||
</list>
|
||||
</property>
|
||||
<property name="filters" value="log4j" />
|
||||
</bean>
|
||||
|
||||
<bean id="mbeanServer" class="com.alibaba.druid.spring.MBeanServerFactoryBean" />
|
||||
|
||||
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"
|
||||
lazy-init="false">
|
||||
<property name="beans">
|
||||
<map>
|
||||
<entry key="com.alibaba.druid.test:type=WallConfig"
|
||||
value-ref="wall-filter-config" />
|
||||
<entry key="com.alibaba.druid.test:type=WallFilter"
|
||||
value-ref="wall-filter" />
|
||||
<entry key="com.alibaba.druid.test:type=StatFilter"
|
||||
value-ref="stat-filter" />
|
||||
</map>
|
||||
</property>
|
||||
<property name="server" ref="mbeanServer" />
|
||||
</bean>
|
||||
|
||||
<bean id="txManager-druid-test"
|
||||
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<tx:annotation-driven transaction-manager="txManager-druid-test" proxy-target-class="false" />
|
||||
</beans>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
|
||||
default-lazy-init="false">
|
||||
|
||||
<bean id="test-filter" class="com.alibaba.druid.bvt.pool.SpringFilterTest$TestFilter">
|
||||
</bean>
|
||||
<bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
|
||||
</bean>
|
||||
|
||||
<bean id="wall-filter-config" class="com.alibaba.druid.wall.WallConfig"
|
||||
init-method="init">
|
||||
<property name="dir" value="META-INF/druid/wall/mysql" />
|
||||
<property name="noneBaseStatementAllow" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean id="wall-filter" class="com.alibaba.druid.wall.WallFilter">
|
||||
<property name="dbType" value="mysql" />
|
||||
<property name="config" ref="wall-filter-config" />
|
||||
</bean>
|
||||
|
||||
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
|
||||
init-method="init" destroy-method="close">
|
||||
<property name="url">
|
||||
<value>jdbc:derby:memory:spring-test;create=true</value>
|
||||
</property>
|
||||
<property name="initialSize">
|
||||
<value>1</value>
|
||||
</property>
|
||||
<property name="maxActive">
|
||||
<value>20</value>
|
||||
</property>
|
||||
<property name="proxyFilters">
|
||||
<list>
|
||||
<ref bean="test-filter" />
|
||||
<ref bean="stat-filter" />
|
||||
<ref bean="wall-filter" />
|
||||
</list>
|
||||
</property>
|
||||
<property name="filters" value="log4j" />
|
||||
</bean>
|
||||
|
||||
<bean id="dataSourceMbeanServer" class="com.alibaba.druid.spring.MBeanServerFactoryBean" />
|
||||
|
||||
<bean id="dataSourceExporter" class="org.springframework.jmx.export.MBeanExporter"
|
||||
lazy-init="false">
|
||||
<property name="beans">
|
||||
<map>
|
||||
<entry key="com.alibaba.druid.test:type=WallConfig"
|
||||
value-ref="wall-filter-config" />
|
||||
<entry key="com.alibaba.druid.test:type=WallFilter"
|
||||
value-ref="wall-filter" />
|
||||
<entry key="com.alibaba.druid.test:type=StatFilter"
|
||||
value-ref="stat-filter" />
|
||||
</map>
|
||||
</property>
|
||||
<property name="server" ref="dataSourceMbeanServer" />
|
||||
</bean>
|
||||
|
||||
<bean id="txManager-druid-test"
|
||||
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<tx:annotation-driven transaction-manager="txManager-druid-test" proxy-target-class="false" />
|
||||
</beans>
|
||||
+2
-2
@@ -4,6 +4,6 @@
|
||||
<settings cacheModelsEnabled="true" enhancementEnabled="true"
|
||||
lazyLoadingEnabled="true" maxRequests="512" maxSessions="128"
|
||||
maxTransactions="32" useStatementNamespaces="true" />
|
||||
<sqlMap resource="com/alibaba/druid/pool/Sequence.xml" />
|
||||
<sqlMap resource="com/alibaba/druid/pool/User.xml" />
|
||||
<sqlMap resource="com/alibaba/druid/pool/ibatis/Sequence.xml" />
|
||||
<sqlMap resource="com/alibaba/druid/pool/ibatis/User.xml" />
|
||||
</sqlMapConfig>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
|
||||
default-lazy-init="false">
|
||||
|
||||
<bean class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"
|
||||
id="master-sqlMapClient">
|
||||
<property name="configLocation" value="com/alibaba/druid/pool/ibatis/ibatis-config-druid-test.xml" />
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="sequence-dao" class="com.alibaba.druid.spring.SequenceDao">
|
||||
<property name="sqlMapClient" ref="master-sqlMapClient" />
|
||||
</bean>
|
||||
<bean id="sequence-service" class="com.alibaba.druid.spring.SequenceService">
|
||||
<property name="dao" ref="sequence-dao" />
|
||||
</bean>
|
||||
|
||||
<bean id="user-dao" class="com.alibaba.druid.spring.UserDao">
|
||||
<property name="sqlMapClient" ref="master-sqlMapClient" />
|
||||
</bean>
|
||||
<bean id="user-service" class="com.alibaba.druid.spring.UserService">
|
||||
<property name="dao" ref="user-dao" />
|
||||
<property name="sequenceService" ref="sequence-service" />
|
||||
</bean>
|
||||
|
||||
<import resource="classpath:com/alibaba/druid/pool/dataSource.xml"/>
|
||||
</beans>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
|
||||
default-lazy-init="false">
|
||||
|
||||
<bean class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"
|
||||
id="master-sqlMapClient">
|
||||
<property name="configLocation" value="com/alibaba/druid/pool/ibatis-config-druid-test.xml" />
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
<bean id="sequence-dao" class="com.alibaba.druid.spring.SequenceDao">
|
||||
<property name="sqlMapClient" ref="master-sqlMapClient" />
|
||||
</bean>
|
||||
<bean id="sequence-service" class="com.alibaba.druid.spring.SequenceService">
|
||||
<property name="dao" ref="sequence-dao" />
|
||||
</bean>
|
||||
|
||||
<bean id="user-dao" class="com.alibaba.druid.spring.UserDao">
|
||||
<property name="sqlMapClient" ref="master-sqlMapClient" />
|
||||
</bean>
|
||||
<bean id="user-service" class="com.alibaba.druid.spring.UserService">
|
||||
<property name="dao" ref="user-dao" />
|
||||
<property name="sequenceService" ref="sequence-service" />
|
||||
</bean>
|
||||
|
||||
<import resource="classpath:com/alibaba/druid/pool/dataSource.xml"/>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user