mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add testcase & remove unused code
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.filter.Filter;
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterManager;
|
||||
|
||||
public class FilterManagerTest extends TestCase {
|
||||
|
||||
public void test_instance() throws Exception {
|
||||
new FilterManager();
|
||||
}
|
||||
|
||||
public void test_loadFilter() throws Exception {
|
||||
Exception error = null;
|
||||
|
||||
try {
|
||||
FilterManager.loadFilter(new ArrayList<Filter>(), ErrorFilter.class.getName());
|
||||
} catch (SQLException e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
public void test_loadFilter_2() throws Exception {
|
||||
Exception error = null;
|
||||
|
||||
try {
|
||||
FilterManager.loadFilter(new ArrayList<Filter>(), ErrorFilter.class.getName());
|
||||
} catch (SQLException e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
public static class ErrorFilter extends FilterAdapter {
|
||||
|
||||
public ErrorFilter(){
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.alibaba.druid.bvt.proxy.filter;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.stat.StatFilter;
|
||||
|
||||
public class StatFilterTest3 extends TestCase {
|
||||
public void test_dbType() throws Exception {
|
||||
StatFilter filter = new StatFilter();
|
||||
|
||||
Assert.assertFalse(filter.isMergeSql());
|
||||
|
||||
filter.setDbType("mysql");
|
||||
filter.setMergeSql(true);
|
||||
|
||||
Assert.assertTrue(filter.isMergeSql());
|
||||
Assert.assertEquals("mysql", filter.getDbType());
|
||||
|
||||
Assert.assertEquals("SELECT ?\nLIMIT ?" , filter.mergeSql("select 'x' limit 1"));
|
||||
}
|
||||
|
||||
public void test_dbType_error() throws Exception {
|
||||
StatFilter filter = new StatFilter();
|
||||
filter.setDbType("mysql");
|
||||
filter.setMergeSql(true);
|
||||
|
||||
Assert.assertEquals("mysql", filter.getDbType());
|
||||
|
||||
Assert.assertEquals("sdafawer asf " , filter.mergeSql("sdafawer asf "));
|
||||
}
|
||||
|
||||
public void test_merge() throws Exception {
|
||||
StatFilter filter = new StatFilter();
|
||||
filter.setDbType("mysql");
|
||||
filter.setMergeSql(false);
|
||||
|
||||
Assert.assertEquals("mysql", filter.getDbType());
|
||||
|
||||
Assert.assertEquals("select 'x' limit 1" , filter.mergeSql("select 'x' limit 1"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user