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,43 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.filter.wall;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.wall.WallProvider;
|
||||
import com.alibaba.druid.wall.spi.SQLServerWallProvider;
|
||||
|
||||
/**
|
||||
* SQLServerWallTest
|
||||
*
|
||||
* @author RaymondXiu
|
||||
* @version 1.0, 2012-3-18
|
||||
* @see
|
||||
*/
|
||||
public class SQLServerWallTest_8 extends TestCase {
|
||||
|
||||
public void test_true() throws Exception {
|
||||
WallProvider provider = new SQLServerWallProvider();
|
||||
|
||||
provider.getConfig().setMustParameterized(true);
|
||||
|
||||
Assert.assertFalse(provider.checkValid("select * from t where fid = 1"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.alibaba.druid.bvt.pool.vendor;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.vendor.InformixExceptionSorter;
|
||||
|
||||
public class InformixExceptionSorterTest extends TestCase {
|
||||
|
||||
public void test_informix() throws Exception {
|
||||
InformixExceptionSorter sorter = new InformixExceptionSorter();
|
||||
Assert.assertEquals(false, sorter.isExceptionFatal(new SQLException()));
|
||||
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -710)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79716)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79730)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79734)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79735)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79736)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79756)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79757)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79758)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79759)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79760)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79788)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79811)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79812)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79836)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79837)));
|
||||
Assert.assertEquals(true, sorter.isExceptionFatal(new SQLException("", "", -79879)));
|
||||
Assert.assertEquals(false, sorter.isExceptionFatal(new SQLException("", "", 100)));
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.alibaba.druid.bvt.pool.vendor;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.vendor.SybaseExceptionSorter;
|
||||
|
||||
public class SybaseExceptionSorterTest extends TestCase {
|
||||
|
||||
public void test_false() throws Exception {
|
||||
SybaseExceptionSorter sorter = new SybaseExceptionSorter();
|
||||
Assert.assertFalse(sorter.isExceptionFatal(new SQLException()));
|
||||
}
|
||||
|
||||
public void test_false_2() throws Exception {
|
||||
SybaseExceptionSorter sorter = new SybaseExceptionSorter();
|
||||
Assert.assertFalse(sorter.isExceptionFatal(new SQLException("xxx")));
|
||||
}
|
||||
|
||||
public void test_true() throws Exception {
|
||||
SybaseExceptionSorter sorter = new SybaseExceptionSorter();
|
||||
Assert.assertTrue(sorter.isExceptionFatal(new SQLException("JZ0C0")));
|
||||
}
|
||||
|
||||
public void test_true_1() throws Exception {
|
||||
SybaseExceptionSorter sorter = new SybaseExceptionSorter();
|
||||
Assert.assertTrue(sorter.isExceptionFatal(new SQLException("JZ0C1")));
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.alibaba.druid.bvt.pool.vendor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.ValidConnectionCheckerAdapter;
|
||||
|
||||
|
||||
public class ValidConnectionCheckerAdapterTest extends TestCase {
|
||||
public void test_adapter() throws Exception {
|
||||
ValidConnectionCheckerAdapter adapter = new ValidConnectionCheckerAdapter();
|
||||
adapter.configFromProperties(System.getProperties());
|
||||
Assert.assertTrue(adapter.isValidConnection(null, null, 10));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.alibaba.druid.bvt.spring;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import com.alibaba.druid.support.ibatis.SqlMapClientWrapper;
|
||||
import com.ibatis.sqlmap.engine.impl.SqlMapClientImpl;
|
||||
|
||||
public class SqlMapExecutorWrapperTest extends TestCase {
|
||||
|
||||
private ClassPathXmlApplicationContext context = null;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
context = new ClassPathXmlApplicationContext("com/alibaba/druid/pool/ibatis/spring-config-ibatis.xml");
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void test_wrap() throws Exception {
|
||||
SqlMapClientImpl client = (SqlMapClientImpl) context.getBean("master-sqlMapClient");
|
||||
Assert.assertNotNull(client);
|
||||
|
||||
SqlMapClientWrapper wrapper = new SqlMapClientWrapper(client);
|
||||
wrapper.getClient();
|
||||
wrapper.startTransaction();
|
||||
wrapper.endTransaction();
|
||||
wrapper.startTransaction(Connection.TRANSACTION_NONE);
|
||||
wrapper.endTransaction();
|
||||
wrapper.setUserConnection(wrapper.getUserConnection());
|
||||
wrapper.getCurrentConnection();
|
||||
wrapper.getDataSource();
|
||||
wrapper.openSession().close();
|
||||
wrapper.openSession(wrapper.getCurrentConnection()).close();
|
||||
wrapper.getSession();
|
||||
wrapper.flushDataCache();
|
||||
Exception error = null;
|
||||
try {
|
||||
wrapper.flushDataCache(null);
|
||||
} catch (Exception ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
wrapper.startTransaction();
|
||||
wrapper.commitTransaction();
|
||||
|
||||
wrapper.getMappedStatement("Sequence.getValue");
|
||||
|
||||
wrapper.isEnhancementEnabled();
|
||||
wrapper.isLazyLoadingEnabled();
|
||||
|
||||
wrapper.getSqlExecutor();
|
||||
|
||||
wrapper.getDelegate();
|
||||
|
||||
wrapper.getResultObjectFactory();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.test.TestUtils;
|
||||
|
||||
public class SQLCommentStatementTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "COMMENT on table t1 IS 'xxx'";
|
||||
|
||||
SQLStatementParser parser = new SQLStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.outputSqlServer(stmt);
|
||||
|
||||
Assert.assertEquals("COMMENT ON TABLE t1 IS 'xxx'", text);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodAbsTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
public void test_abs_int() throws Exception {
|
||||
Assert.assertEquals(12, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "abs(-12)"));
|
||||
Assert.assertEquals(12, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "abs(12)"));
|
||||
}
|
||||
|
||||
public void test_abs_long() throws Exception {
|
||||
Assert.assertEquals(12L, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "abs(?)", 12L));
|
||||
Assert.assertEquals(12L, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "abs(?)", -12L));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodCosTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.cos(1), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "cos(1)"));
|
||||
Assert.assertEquals(Math.cos(1.001), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "cos(1.001)"));
|
||||
Assert.assertEquals(Math.cos(0), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "cos(0)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodLog10Test extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.log10(1), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "log10(1)"));
|
||||
Assert.assertEquals(Math.log10(1.001), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "log10(1.001)"));
|
||||
Assert.assertEquals(Math.log10(0), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "log10(0)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodLogTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.log(1), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "log(1)"));
|
||||
Assert.assertEquals(Math.log(1.001), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "log(1.001)"));
|
||||
Assert.assertEquals(Math.log(0), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "log(0)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodPowerTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.pow(1, 2), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "power(1, 2)"));
|
||||
Assert.assertEquals(Math.pow(3, 4), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "power(3, 4)"));
|
||||
Assert.assertEquals(Math.pow(4, 5), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "pow(4, 5)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodRandom extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertNotNull(SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "rand()"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodSinTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.sin(1), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sin(1)"));
|
||||
Assert.assertEquals(Math.sin(1.001), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sin(1.001)"));
|
||||
Assert.assertEquals(Math.sin(0), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sin(0)"));
|
||||
Assert.assertEquals(Math.sin(2), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sin(2)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodSqrtTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.sqrt(1), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sqrt(1)"));
|
||||
Assert.assertEquals(Math.sqrt(1.001), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sqrt(1.001)"));
|
||||
Assert.assertEquals(Math.sqrt(0), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "sqrt(0)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalMethodTanTest extends TestCase {
|
||||
public void test_reverse() throws Exception {
|
||||
Assert.assertEquals(Math.tan(1), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "tan(1)"));
|
||||
Assert.assertEquals(Math.tan(1.001), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "tan(1.001)"));
|
||||
Assert.assertEquals(Math.tan(0), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "tan(0)"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_add extends TestCase {
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(3, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (byte) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte_1() throws Exception {
|
||||
Assert.assertEquals(3, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (byte) 1, "2"));
|
||||
}
|
||||
|
||||
public void test_byte_2() throws Exception {
|
||||
Assert.assertEquals(null, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (byte) 1, null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_add_long extends TestCase {
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(3L, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (long) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte_1() throws Exception {
|
||||
Assert.assertEquals(3L, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (long) 1, "2"));
|
||||
}
|
||||
|
||||
public void test_byte_2() throws Exception {
|
||||
Assert.assertEquals(null, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (long) 1, null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_add_short extends TestCase {
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(3, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (short) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte_1() throws Exception {
|
||||
Assert.assertEquals(3, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (short) 1, "2"));
|
||||
}
|
||||
|
||||
public void test_byte_2() throws Exception {
|
||||
Assert.assertEquals(null, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? + ?", (short) 1, null));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_div extends TestCase {
|
||||
public void test_long() throws Exception {
|
||||
Assert.assertEquals(0L, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", (long) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_int() throws Exception {
|
||||
Assert.assertEquals(0, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", (int) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_short() throws Exception {
|
||||
Assert.assertEquals(0, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", (short) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(0, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", (byte) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigInteger() throws Exception {
|
||||
Assert.assertEquals(BigInteger.ZERO, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", BigInteger.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigDecimal() throws Exception {
|
||||
Assert.assertEquals(new BigDecimal("0.5"), SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", BigDecimal.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_float() throws Exception {
|
||||
Assert.assertEquals(0.5F, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", (float) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_double() throws Exception {
|
||||
Assert.assertEquals(0.5D, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?/?", (double) 1, (byte) 2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_gt extends TestCase {
|
||||
public void test_long() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? > ?", (long) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_int() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? > ?", (int) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_short() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? > ?", (short) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? > ?", (byte) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigInteger() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?>?", BigInteger.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigDecimal() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?>?", BigDecimal.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_float() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?>?", (float) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_double() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?>?", (double) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_String() throws Exception {
|
||||
Assert.assertEquals(false, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?>?", "1", "2"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_lt extends TestCase {
|
||||
public void test_long() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? < ?", (long) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_int() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? < ?", (int) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_short() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? < ?", (short) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? < ?", (byte) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigInteger() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<?", BigInteger.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigDecimal() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<?", BigDecimal.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_float() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<?", (float) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_double() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<?", (double) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_String() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<?", "1", "2"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.alibaba.druid.bvt.sql.eval;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
|
||||
public class EvalTest_lteq extends TestCase {
|
||||
public void test_long() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? <= ?", (long) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_int() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? <= ?", (int) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_short() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? <= ?", (short) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_byte() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "? <= ?", (byte) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigInteger() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<=?", BigInteger.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_BigDecimal() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<=?", BigDecimal.ONE, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_float() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<=?", (float) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_double() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<=?", (double) 1, (byte) 2));
|
||||
}
|
||||
|
||||
public void test_String() throws Exception {
|
||||
Assert.assertEquals(true, SQLEvalVisitorUtils.evalExpr(JdbcConstants.MYSQL, "?<=?", "1", "2"));
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -31,13 +31,13 @@ public class MySqlParameterizedOutputVisitorTest extends TestCase {
|
||||
public void test_0() throws Exception {
|
||||
validate("SELECT * FROM T WHERE ID IN (?, ?, ?)", "SELECT *\nFROM T\nWHERE ID IN (?)");
|
||||
validate("SELECT * FROM T WHERE ID = 5", "SELECT *\nFROM T\nWHERE ID = ?");
|
||||
validate("SELECT * FROM T WHERE 1 = 0 AND ID = 5", "SELECT *\nFROM T\nWHERE 1 = 0\nAND ID = ?");
|
||||
validate("SELECT * FROM T WHERE 1 = 0 AND ID = 5", "SELECT *\nFROM T\nWHERE 1 = 0\n\tAND ID = ?");
|
||||
validate("SELECT * FROM T WHERE ID = ? OR ID = ?", "SELECT *\nFROM T\nWHERE ID = ?");
|
||||
validate("SELECT * FROM T WHERE A.ID = ? OR A.ID = ?", "SELECT *\nFROM T\nWHERE A.ID = ?");
|
||||
validate("SELECT * FROM T WHERE 1 = 0 OR a.id = ? OR a.id = ? OR a.id = ? OR a.id = ?",
|
||||
"SELECT *\nFROM T\nWHERE 1 = 0\nOR a.id = ?");
|
||||
"SELECT *\nFROM T\nWHERE 1 = 0\n\tOR a.id = ?");
|
||||
validateOracle("SELECT * FROM T WHERE 1 = 0 OR a.id = ? OR a.id = ? OR a.id = ? OR a.id = ?",
|
||||
"SELECT *\nFROM T\nWHERE 1 = 0\nOR a.id = ?");
|
||||
"SELECT *\nFROM T\nWHERE 1 = 0\n\tOR a.id = ?");
|
||||
validateOracle("SELECT * FROM T WHERE A.ID = ? OR A.ID = ?", "SELECT *\nFROM T\nWHERE A.ID = ?");
|
||||
validate("INSERT INTO T (F1, F2) VALUES(?, ?), (?, ?), (?, ?)", "INSERT INTO T (F1, F2) VALUES (?, ?)");
|
||||
validate("update net_device d, sys_user u set d.resp_user_id=u.id where d.resp_user_login_name=u.username and d.id in (42354)", //
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.stat.TableStat.Column;
|
||||
|
||||
public class MySqlUpdateTest_2 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "UPDATE `z_code` SET (f1, f2) = (1, 2)";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(1, visitor.getTables().size());
|
||||
Assert.assertEquals(2, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("z_code")));
|
||||
|
||||
Assert.assertTrue(visitor.getColumns().contains(new Column("z_code", "f1")));
|
||||
Assert.assertTrue(visitor.getColumns().contains(new Column("z_code", "f2")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.oracle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor;
|
||||
|
||||
public class OracleSelectTest43 extends OracleTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = //
|
||||
"SELECT * FROM table(t_department) " + //
|
||||
"WHERE name IN ('0000','4444') " + //
|
||||
"ORDER BY name ASC"; //
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("relationships : " + visitor.getRelationships());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(1, visitor.getTables().size());
|
||||
|
||||
Assert.assertEquals(1, visitor.getColumns().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh")));
|
||||
|
||||
// Assert.assertTrue(visitor.getOrderByColumns().contains(new TableStat.Column("employees", "last_name")));
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ package com.alibaba.druid.bvt.sql.oracle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.alibaba.druid.bvt.sql.postgresql;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGExportParameterVisitor;
|
||||
|
||||
|
||||
public class PGExportParameterVisitorTest extends TestCase {
|
||||
public void test_pg() throws Exception {
|
||||
String sql = "select fname, count(*) from t where fid = 1 group by fname order by 1";
|
||||
|
||||
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
List<Object> parameters = new ArrayList<Object>();
|
||||
PGExportParameterVisitor visitor = new PGExportParameterVisitor(parameters);
|
||||
stmt.accept(visitor);
|
||||
|
||||
Assert.assertEquals(1, parameters.size());
|
||||
Assert.assertEquals(1, parameters.get(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.alibaba.druid.bvt.sql.postgresql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGExportParameterVisitor;
|
||||
|
||||
|
||||
public class PGExportParameterVisitorTest1 extends TestCase {
|
||||
public void test_pg() throws Exception {
|
||||
String sql = "select fname, count(*) from t where fid = 1 group by fname order by 1";
|
||||
|
||||
PGSQLStatementParser parser = new PGSQLStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
PGExportParameterVisitor visitor = new PGExportParameterVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
List<Object> parameters = visitor.getParameters();
|
||||
|
||||
Assert.assertEquals(1, parameters.size());
|
||||
Assert.assertEquals(1, parameters.get(0));
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.alibaba.druid.bvt.sql.sqlserver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.MSSQLServerExportParameterVisitor;
|
||||
|
||||
public class MSSQLServerExportParameterVisitorTest extends TestCase {
|
||||
|
||||
public void test_sqlserver() throws Exception {
|
||||
String sql = "select fname, count(*) from t where fid = 1 group by fname order by 1";
|
||||
|
||||
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
|
||||
SQLStatement stmt = parser.parseStatementList().get(0);
|
||||
|
||||
List<Object> parameters = new ArrayList<Object>();
|
||||
MSSQLServerExportParameterVisitor visitor = new MSSQLServerExportParameterVisitor(parameters);
|
||||
stmt.accept(visitor);
|
||||
|
||||
Assert.assertEquals(1, parameters.size());
|
||||
Assert.assertEquals(1, parameters.get(0));
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.sqlserver;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
|
||||
import com.alibaba.druid.sql.test.TestUtils;
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.sqlserver;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerParameterizedOutputVisitor;
|
||||
|
||||
public class SQLServerParameterizedOutputVisitorTest extends TestCase {
|
||||
|
||||
public void test_simple() throws Exception {
|
||||
String sql = "select GEN_VAL " + //
|
||||
"from ID_GENERATOR with (updlock, rowlock) " + //
|
||||
"where GEN_NAME = 'T_USERS' AND FID = 3 AND FSTATE IN (1, 2, 3)"; //
|
||||
|
||||
String expect = "SELECT GEN_VAL" + //
|
||||
"\nFROM ID_GENERATOR WITH (updlock, rowlock)" + //
|
||||
"\nWHERE GEN_NAME = ?" +
|
||||
"\n\tAND FID = ?" +
|
||||
"\n\tAND FSTATE IN (?)";
|
||||
|
||||
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
|
||||
String text = outputSqlServer(stmtList);
|
||||
|
||||
Assert.assertEquals(expect, text);
|
||||
}
|
||||
|
||||
public static String outputSqlServer(List<SQLStatement> stmtList) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
SQLServerOutputVisitor visitor = new SQLServerParameterizedOutputVisitor(out);
|
||||
|
||||
for (SQLStatement stmt : stmtList) {
|
||||
stmt.accept(visitor);
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.sqlserver;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
|
||||
import com.alibaba.druid.sql.test.TestUtils;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.alibaba.druid.bvt.support.ibatis;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.support.ibatis.DruidDataSourceFactory;
|
||||
|
||||
|
||||
public class DruidDataSourceFactoryTest extends TestCase {
|
||||
public void test_facttory() throws Exception {
|
||||
DruidDataSourceFactory factory = new DruidDataSourceFactory();
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("url", "jdbc:mock:xx");
|
||||
factory.initialize(properties);
|
||||
DruidDataSource dataSource = (DruidDataSource) factory.getDataSource();
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.alibaba.druid.bvt.support.logging;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl;
|
||||
|
||||
public class JakartaCommonsLoggingImplTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
JakartaCommonsLoggingImpl impl = new JakartaCommonsLoggingImpl(DruidDataSource.class.getName());
|
||||
|
||||
impl.isDebugEnabled();
|
||||
impl.isInfoEnabled();
|
||||
impl.isWarnEnabled();
|
||||
impl.debug("");
|
||||
impl.debug("", new Exception());
|
||||
impl.info("");
|
||||
impl.warn("");
|
||||
impl.warn("", new Exception());
|
||||
impl.error("");
|
||||
impl.error("", new Exception());
|
||||
Assert.assertEquals(1, impl.getInfoCount());
|
||||
Assert.assertEquals(2, impl.getErrorCount());
|
||||
Assert.assertEquals(2, impl.getWarnCount());
|
||||
Assert.assertEquals(1, impl.getInfoCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.alibaba.druid.bvt.support.logging;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.support.logging.Jdk14LoggingImpl;
|
||||
|
||||
public class Jdk14LoggingImplTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
Jdk14LoggingImpl impl = new Jdk14LoggingImpl(DruidDataSource.class.getName());
|
||||
|
||||
impl.isDebugEnabled();
|
||||
impl.isInfoEnabled();
|
||||
impl.isWarnEnabled();
|
||||
impl.debug("");
|
||||
impl.debug("", new Exception());
|
||||
impl.info("");
|
||||
impl.warn("");
|
||||
impl.warn("", new Exception());
|
||||
impl.error("");
|
||||
impl.error("", new Exception());
|
||||
Assert.assertEquals(1, impl.getInfoCount());
|
||||
Assert.assertEquals(2, impl.getErrorCount());
|
||||
Assert.assertEquals(2, impl.getWarnCount());
|
||||
Assert.assertEquals(1, impl.getInfoCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.alibaba.druid.bvt.support.logging;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.support.logging.Log4jImpl;
|
||||
|
||||
public class Log4jImplTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
Log4jImpl impl = new Log4jImpl(DruidDataSource.class.getName());
|
||||
|
||||
impl.isDebugEnabled();
|
||||
impl.isInfoEnabled();
|
||||
impl.isWarnEnabled();
|
||||
impl.debug("");
|
||||
impl.debug("", new Exception());
|
||||
impl.info("");
|
||||
impl.warn("");
|
||||
impl.warn("", new Exception());
|
||||
impl.error("");
|
||||
impl.error("", new Exception());
|
||||
Assert.assertEquals(1, impl.getInfoCount());
|
||||
Assert.assertEquals(2, impl.getErrorCount());
|
||||
Assert.assertEquals(2, impl.getWarnCount());
|
||||
Assert.assertEquals(1, impl.getInfoCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.alibaba.druid.bvt.support.logging;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.support.logging.NoLoggingImpl;
|
||||
|
||||
public class NoLoggingImplTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
NoLoggingImpl impl = new NoLoggingImpl(DruidDataSource.class.getName());
|
||||
|
||||
impl.isDebugEnabled();
|
||||
impl.isInfoEnabled();
|
||||
impl.isWarnEnabled();
|
||||
impl.debug("");
|
||||
impl.debug("", new Exception());
|
||||
impl.info("");
|
||||
impl.warn("");
|
||||
impl.warn("", new Exception());
|
||||
impl.error("");
|
||||
impl.error("", new Exception());
|
||||
Assert.assertEquals(1, impl.getInfoCount());
|
||||
Assert.assertEquals(2, impl.getErrorCount());
|
||||
Assert.assertEquals(2, impl.getWarnCount());
|
||||
Assert.assertEquals(1, impl.getInfoCount());
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package com.alibaba.druid.bvt.support.logging;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.support.logging.SLF4JImpl;
|
||||
|
||||
@@ -20,5 +22,9 @@ public class SLF4JImplTest extends TestCase {
|
||||
impl.warn("", new Exception());
|
||||
impl.error("");
|
||||
impl.error("", new Exception());
|
||||
Assert.assertEquals(1, impl.getInfoCount());
|
||||
Assert.assertEquals(2, impl.getErrorCount());
|
||||
Assert.assertEquals(2, impl.getWarnCount());
|
||||
Assert.assertEquals(1, impl.getInfoCount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.alibaba.druid.bvt.support.spring;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockBlob;
|
||||
import com.alibaba.druid.mock.MockClob;
|
||||
import com.alibaba.druid.mock.MockResultSet;
|
||||
import com.alibaba.druid.support.spring.DruidLobHandler;
|
||||
|
||||
public class DruidLobHandlerTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
DruidLobHandler handler = new DruidLobHandler();
|
||||
List<Object[]> rows = new ArrayList<Object[]>();
|
||||
rows.add(new Object[] { null, new MockBlob(), new MockClob() });
|
||||
MockResultSet rs = new MockResultSet(null, rows);
|
||||
rs.next();
|
||||
|
||||
handler.getBlobAsBinaryStream(rs, 1);
|
||||
handler.getBlobAsBinaryStream(rs, "1");
|
||||
handler.getBlobAsBytes(rs, 1);
|
||||
handler.getBlobAsBytes(rs, "1");
|
||||
|
||||
handler.getBlobAsBinaryStream(rs, 2);
|
||||
handler.getBlobAsBinaryStream(rs, "2");
|
||||
handler.getBlobAsBytes(rs, 2);
|
||||
handler.getBlobAsBytes(rs, "2");
|
||||
|
||||
handler.getClobAsAsciiStream(rs, 1);
|
||||
handler.getClobAsAsciiStream(rs, "1");
|
||||
handler.getClobAsCharacterStream(rs, 1);
|
||||
handler.getClobAsCharacterStream(rs, "1");
|
||||
handler.getClobAsString(rs, 1);
|
||||
handler.getClobAsString(rs, "1");
|
||||
|
||||
handler.getClobAsAsciiStream(rs, 3);
|
||||
handler.getClobAsAsciiStream(rs, "3");
|
||||
handler.getClobAsCharacterStream(rs, 3);
|
||||
handler.getClobAsCharacterStream(rs, "3");
|
||||
handler.getClobAsString(rs, 3);
|
||||
handler.getClobAsString(rs, "3");
|
||||
|
||||
handler.getLobCreator();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.alibaba.druid.bvt.utils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.util.ConcurrentIdentityHashMap;
|
||||
|
||||
public class ConcurrentIdentityHashMapTest extends TestCase {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.alibaba.druid.bvt.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.util.ConcurrentIdentityHashMap;
|
||||
|
||||
public class ConcurrentIdentityHashMapTest2 extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
ConcurrentIdentityHashMap<Integer, Object> map = new ConcurrentIdentityHashMap<Integer, Object>();
|
||||
map.put(Integer.valueOf(1), "");
|
||||
Assert.assertEquals(map.get(Integer.valueOf(1)), "");
|
||||
Assert.assertEquals(map.get(new Integer(1)), null);
|
||||
|
||||
Assert.assertTrue(map.containsValue(""));
|
||||
|
||||
{
|
||||
Exception error = null;
|
||||
try {
|
||||
map.containsValue(null);
|
||||
} catch (NullPointerException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
{
|
||||
Exception error = null;
|
||||
try {
|
||||
map.put(Integer.valueOf(1), null);
|
||||
} catch (NullPointerException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
{
|
||||
Exception error = null;
|
||||
try {
|
||||
map.putIfAbsent(Integer.valueOf(1), null);
|
||||
} catch (NullPointerException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
map.put(Integer.valueOf(1), "123");
|
||||
Assert.assertEquals(map.get(Integer.valueOf(1)), "123");
|
||||
Assert.assertEquals(map.get(new Integer(1)), null);
|
||||
|
||||
map.putIfAbsent(Integer.valueOf(1), "234");
|
||||
Assert.assertEquals(map.get(Integer.valueOf(1)), "123");
|
||||
Assert.assertEquals(map.get(new Integer(1)), null);
|
||||
|
||||
map.remove(new Integer(1));
|
||||
Assert.assertEquals(map.get(Integer.valueOf(1)), "123");
|
||||
Assert.assertFalse(map.isEmpty());
|
||||
|
||||
map.remove(Integer.valueOf(1));
|
||||
Assert.assertEquals(map.get(Integer.valueOf(1)), null);
|
||||
Assert.assertTrue(map.isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.alibaba.druid.bvt.utils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.util.ConcurrentIdentityHashMap;
|
||||
|
||||
public class ConcurrentIdentityHashMapTest3 extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
ConcurrentIdentityHashMap<Integer, Object> map = new ConcurrentIdentityHashMap<Integer, Object>(16, 0.75f, 2);
|
||||
|
||||
Integer[] keys = new Integer[10000];
|
||||
for (int i = 0; i < keys.length; ++i) {
|
||||
keys[i] = i;
|
||||
}
|
||||
for (int i = 0; i < keys.length; ++i) {
|
||||
map.put(keys[i], "");
|
||||
}
|
||||
Assert.assertEquals(keys.length, map.size());
|
||||
for (int i = 0; i < keys.length; ++i) {
|
||||
map.put(keys[i], "");
|
||||
}
|
||||
for (Map.Entry<Integer, Object> entry : map.entrySet()) {
|
||||
entry.getKey();
|
||||
entry.getValue();
|
||||
}
|
||||
Assert.assertEquals(keys.length, map.size());
|
||||
for (int i = 0; i < keys.length; ++i) {
|
||||
map.remove(keys[i]);
|
||||
}
|
||||
Assert.assertEquals(0, map.size());
|
||||
map.keys();
|
||||
map.entrySet();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.alibaba.druid.bvt.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.util.DaemonThreadFactory;
|
||||
|
||||
|
||||
public class DaemonThreadFactoryTest extends TestCase {
|
||||
public void test_0 () throws Exception {
|
||||
Runnable task = new Runnable() {
|
||||
public void run() {
|
||||
|
||||
}
|
||||
};
|
||||
DaemonThreadFactory factory = new DaemonThreadFactory("test");
|
||||
Assert.assertEquals("[test-1]", factory.newThread(task).getName());
|
||||
Assert.assertEquals("[test-2]", factory.newThread(task).getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.alibaba.druid.bvt.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.util.jdbc.LocalResultSet;
|
||||
|
||||
public class LocalResultSetTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
LocalResultSet rs = new LocalResultSet(null);
|
||||
rs.getRows().add(new Object[1]);
|
||||
rs.getRows().add(new Object[1]);
|
||||
Assert.assertTrue(rs.next());
|
||||
Assert.assertTrue(rs.next());
|
||||
Assert.assertFalse(rs.next());
|
||||
Assert.assertTrue(rs.previous());
|
||||
Assert.assertFalse(rs.previous());
|
||||
rs.getInt(1);
|
||||
Assert.assertTrue(rs.wasNull());
|
||||
rs.updateObject(1, 2);
|
||||
Assert.assertEquals(2, rs.getInt(1));
|
||||
Assert.assertFalse(rs.wasNull());
|
||||
rs.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.utils;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import com.alibaba.druid.util.MySqlUtils;
|
||||
import com.mysql.jdbc.ConnectionImpl;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class MySqlUtilsTest extends TestCase {
|
||||
public void test_() throws Exception {
|
||||
Constructor<ConnectionImpl> constructor = ConnectionImpl.class.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
ConnectionImpl conn = constructor.newInstance();
|
||||
MySqlUtils.createXAConnection(conn);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user