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:
@@ -25,6 +25,7 @@ import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.JdbcTraceManager;
|
||||
import com.alibaba.druid.util.JMXUtils;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class TestTraceFilter extends TestCase {
|
||||
|
||||
public void test_loop() throws Exception {
|
||||
@@ -45,5 +46,6 @@ public class TestTraceFilter extends TestCase {
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,386 @@
|
||||
package com.alibaba.druid.bvt.filter.wall;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import com.alibaba.druid.wall.WallFilter;
|
||||
|
||||
public class WallFilterTest2 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
private WallFilter wallFilter;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
dataSource.setUrl("jdbc:h2:mem:wall_test;");
|
||||
dataSource.setFilters("wall");
|
||||
dataSource.setDbType(JdbcConstants.MARIADB);
|
||||
dataSource.init();
|
||||
|
||||
wallFilter = (WallFilter) dataSource.getProxyFilters().get(0);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_wallFilter() throws Exception {
|
||||
Assert.assertEquals(JdbcConstants.MARIADB, wallFilter.getDbType());
|
||||
Assert.assertFalse(wallFilter.isLogViolation());
|
||||
wallFilter.setLogViolation(true);
|
||||
Assert.assertTrue(wallFilter.isLogViolation());
|
||||
wallFilter.setLogViolation(false);
|
||||
Assert.assertFalse(wallFilter.isLogViolation());
|
||||
|
||||
Assert.assertTrue(wallFilter.isThrowException());
|
||||
wallFilter.setThrowException(false);
|
||||
Assert.assertFalse(wallFilter.isThrowException());
|
||||
wallFilter.setThrowException(true);
|
||||
Assert.assertTrue(wallFilter.isThrowException());
|
||||
|
||||
wallFilter.clearProviderCache();
|
||||
wallFilter.getProviderWhiteList();
|
||||
Assert.assertTrue(wallFilter.isInited());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.execute("CREATE TABLE t (FID INTEGER, FNAME VARCHAR(50))");
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(1, wallFilter.getProvider().getTableStat("t").getCreateCount());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
String sql = "INSERT INTO t (FID, FNAME) VALUES (?, ?)";
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
PreparedStatement stmt = conn.prepareStatement(sql, Statement.NO_GENERATED_KEYS);
|
||||
stmt.setInt(1, i + 10);
|
||||
stmt.setString(2, "a" + (i + 10));
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
}
|
||||
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(10, wallFilter.getProvider().getTableStat("t").getInsertCount());
|
||||
Assert.assertEquals(10, wallFilter.getProvider().getTableStat("t").getInsertDataCount());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
String sql = "INSERT INTO t (FID, FNAME) VALUES (?, ?)";
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement(sql, Statement.NO_GENERATED_KEYS);
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
stmt.setInt(1, i + 20);
|
||||
stmt.setString(2, "a" + (i + 20));
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(11, wallFilter.getProvider().getTableStat("t").getInsertCount());
|
||||
Assert.assertEquals(20, wallFilter.getProvider().getTableStat("t").getInsertDataCount());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
stmt.addBatch("INSERT INTO t (FID, FNAME) VALUES (" + i + ", 'a" + i + "')");
|
||||
}
|
||||
stmt.executeBatch();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(21, wallFilter.getProvider().getTableStat("t").getInsertCount());
|
||||
Assert.assertEquals(0, wallFilter.getProvider().getTableStat("t").getUpdateDataCount());
|
||||
{
|
||||
String sql = "SELECT * FROM T";
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(30, wallFilter.getProvider().getTableStat("t").getFetchRowCount());
|
||||
|
||||
{
|
||||
String sql = "SELECT * FROM T";
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY,
|
||||
ResultSet.CONCUR_READ_ONLY,
|
||||
ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(60, wallFilter.getProvider().getTableStat("t").getFetchRowCount());
|
||||
|
||||
{
|
||||
String sql = "SELECT * FROM T LIMIT 10";
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql, new int[0]);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(70, wallFilter.getProvider().getTableStat("t").getFetchRowCount());
|
||||
|
||||
{
|
||||
String sql = "SELECT * FROM T LIMIT 10";
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql, new String[0]);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(80, wallFilter.getProvider().getTableStat("t").getFetchRowCount());
|
||||
|
||||
{
|
||||
String sql = "SELECT * FROM T LIMIT 10";
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareCall(sql);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(90, wallFilter.getProvider().getTableStat("t").getFetchRowCount());
|
||||
|
||||
{
|
||||
String sql = "SELECT * FROM T LIMIT 10";
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(100, wallFilter.getProvider().getTableStat("t").getFetchRowCount());
|
||||
|
||||
{
|
||||
String sql = "SELECT * FROM T";
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
|
||||
ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(130, wallFilter.getProvider().getTableStat("t").getFetchRowCount());
|
||||
|
||||
{
|
||||
String sql = "SELECT * FROM T LIMIT 10";
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
stmt.execute(sql, Statement.NO_GENERATED_KEYS);
|
||||
ResultSet rs = stmt.getResultSet();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(140, wallFilter.getProvider().getTableStat("t").getFetchRowCount());
|
||||
|
||||
{
|
||||
String sql = "SELECT * FROM T LIMIT 10";
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
|
||||
ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
stmt.execute(sql, new int[0]);
|
||||
ResultSet rs = stmt.getResultSet();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(150, wallFilter.getProvider().getTableStat("t").getFetchRowCount());
|
||||
|
||||
{
|
||||
String sql = "SELECT * FROM T LIMIT 10";
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
|
||||
ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
stmt.execute(sql, new String[0]);
|
||||
ResultSet rs = stmt.getResultSet();
|
||||
while (rs.next()) {
|
||||
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(160, wallFilter.getProvider().getTableStat("t").getFetchRowCount());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.executeUpdate("DELETE from t where FID = 0");
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(1, wallFilter.getProvider().getTableStat("t").getDeleteDataCount());
|
||||
Assert.assertEquals(0, wallFilter.getProvider().getTableStat("t").getUpdateDataCount());
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.executeUpdate("DELETE from t where FID = 1 OR FID = 2", Statement.NO_GENERATED_KEYS);
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(3, wallFilter.getProvider().getTableStat("t").getDeleteDataCount());
|
||||
Assert.assertEquals(0, wallFilter.getProvider().getTableStat("t").getUpdateDataCount());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.executeUpdate("DELETE from t where FID = 3", new int[0]);
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(4, wallFilter.getProvider().getTableStat("t").getDeleteDataCount());
|
||||
Assert.assertEquals(0, wallFilter.getProvider().getTableStat("t").getUpdateDataCount());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.executeUpdate("DELETE from t where FID = 4", new String[0]);
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(5, wallFilter.getProvider().getTableStat("t").getDeleteDataCount());
|
||||
Assert.assertEquals(0, wallFilter.getProvider().getTableStat("t").getUpdateDataCount());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement("DELETE from t where FID = ?");
|
||||
stmt.setInt(1, 5);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(6, wallFilter.getProvider().getTableStat("t").getDeleteDataCount());
|
||||
Assert.assertEquals(0, wallFilter.getProvider().getTableStat("t").getUpdateDataCount());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.execute("update t SET fname = 'xx' where FID = 13 OR FID = 14");
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(2, wallFilter.getProvider().getTableStat("t").getUpdateDataCount());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement("update t SET fname = 'xx' where FID = ? OR FID = ?");
|
||||
stmt.setInt(1, 13);
|
||||
stmt.setInt(2, 14);
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(4, wallFilter.getProvider().getTableStat("t").getUpdateDataCount());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement("update t SET fname = 'xx' where FID = ? OR FID = ?");
|
||||
stmt.setInt(1, 13);
|
||||
stmt.setInt(2, 14);
|
||||
stmt.execute();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(6, wallFilter.getProvider().getTableStat("t").getUpdateDataCount());
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement("update t SET fname = 'xx' where FID = ?");
|
||||
|
||||
stmt.setInt(1, 13);
|
||||
stmt.addBatch();
|
||||
|
||||
stmt.setInt(1, 14);
|
||||
stmt.addBatch();
|
||||
|
||||
stmt.executeBatch();
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(8, wallFilter.getProvider().getTableStat("t").getUpdateDataCount());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.execute("truncate table t");
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(1, wallFilter.getProvider().getTableStat("t").getTruncateCount());
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.execute("drop table t");
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
Assert.assertEquals(1, wallFilter.getProvider().getTableStat("t").getDropCount());
|
||||
|
||||
Assert.assertEquals(0, wallFilter.getViolationCount());
|
||||
wallFilter.resetViolationCount();
|
||||
wallFilter.checkValid("select 1");
|
||||
Assert.assertEquals(0, wallFilter.getViolationCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.alibaba.druid.bvt.filter.wall;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.wall.WallSQLException;
|
||||
|
||||
|
||||
public class WallSQLExceptionTest extends TestCase {
|
||||
public void test_wall() throws Exception {
|
||||
WallSQLException ex = new WallSQLException("", new RuntimeException());
|
||||
Assert.assertEquals("", ex.getMessage());
|
||||
Assert.assertNotNull(ex.getCause());
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,10 @@ package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
|
||||
@@ -46,7 +47,7 @@ public class TestActiveTrace extends TestCase {
|
||||
}
|
||||
|
||||
public void test_activeTrace() throws Exception {
|
||||
for (int i = 0; i < 1000 * 1000; ++i) {
|
||||
for (int i = 0; i < 1000 * 10; ++i) {
|
||||
dataSource.shrink();
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
@@ -21,7 +21,7 @@ public class SqlMapClientWrapperTest extends TestCase {
|
||||
private ClassPathXmlApplicationContext context = null;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
context = new ClassPathXmlApplicationContext("com/alibaba/druid/pool/ibatis/spring-config-ibatis.xml");
|
||||
context = new ClassPathXmlApplicationContext("com/alibaba/druid/pool/ibatis/spring-config-ibatis-1.xml");
|
||||
DataSource dataSource = (DataSource) context.getBean("dataSource");
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleTimestampExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_OracleTimestampExpr extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "TIMESTAMP '' AT TIME ZONE ''";
|
||||
String sql_c = "TIMESTAMP '' AT TIME ZONE 'a'";
|
||||
OracleTimestampExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (OracleTimestampExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (OracleTimestampExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (OracleTimestampExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new OracleTimestampExpr(), new OracleTimestampExpr());
|
||||
Assert.assertEquals(new OracleTimestampExpr().hashCode(), new OracleTimestampExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
|
||||
public class EqualTest_SQLSelectQueryBlock extends TestCase {
|
||||
|
||||
public void test_eq() throws Exception {
|
||||
SQLSelectQueryBlock exprA = new SQLSelectQueryBlock();
|
||||
SQLSelectQueryBlock exprB = new SQLSelectQueryBlock();
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_aggreate extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "count(*)";
|
||||
String sql_c = "count(id)";
|
||||
SQLAggregateExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (SQLAggregateExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (SQLAggregateExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (SQLAggregateExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLAggregateExpr(null), new SQLAggregateExpr(null));
|
||||
Assert.assertEquals(new SQLAggregateExpr(null).hashCode(), new SQLAggregateExpr(null).hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
|
||||
public class EqualTest_aggreate_over extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "count(*) OVER (ORDER BY f1)";
|
||||
String sql_c = "count(id) OVER (ORDER BY f2)";
|
||||
SQLAggregateExpr exprA, exprB, exprC;
|
||||
{
|
||||
SQLExprParser parser = new SQLExprParser(sql);
|
||||
exprA = (SQLAggregateExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new SQLExprParser(sql);
|
||||
exprB = (SQLAggregateExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new SQLExprParser(sql_c);
|
||||
exprC = (SQLAggregateExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLAggregateExpr(null), new SQLAggregateExpr(null));
|
||||
Assert.assertEquals(new SQLAggregateExpr(null).hashCode(), new SQLAggregateExpr(null).hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAnyExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_any extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "any(select id from t)";
|
||||
String sql_c = "any(select id from t1)";
|
||||
SQLAnyExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (SQLAnyExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (SQLAnyExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (SQLAnyExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLAnyExpr(), new SQLAnyExpr());
|
||||
Assert.assertEquals(new SQLAnyExpr().hashCode(), new SQLAnyExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlBinaryExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
|
||||
public class EqualTest_binary extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "b'01010'";
|
||||
String sql_c = "b'010101'";
|
||||
MySqlBinaryExpr exprA, exprB, exprC;
|
||||
{
|
||||
SQLExprParser parser = new MySqlExprParser(sql);
|
||||
exprA = (MySqlBinaryExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new MySqlExprParser(sql);
|
||||
exprB = (MySqlBinaryExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new MySqlExprParser(sql_c);
|
||||
exprC = (MySqlBinaryExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new MySqlBinaryExpr(), new MySqlBinaryExpr());
|
||||
Assert.assertEquals(new MySqlBinaryExpr().hashCode(), new MySqlBinaryExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_binaryOp extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "a > b";
|
||||
String sql_c = "a > 2";
|
||||
SQLBinaryOpExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (SQLBinaryOpExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (SQLBinaryOpExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (SQLBinaryOpExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLBinaryOpExpr(), new SQLBinaryOpExpr());
|
||||
Assert.assertEquals(new SQLBinaryOpExpr().hashCode(), new SQLBinaryOpExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlBooleanExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
|
||||
public class EqualTest_boolean extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "true";
|
||||
String sql_c = "false";
|
||||
MySqlBooleanExpr exprA, exprB, exprC;
|
||||
{
|
||||
SQLExprParser parser = new MySqlExprParser(sql);
|
||||
exprA = (MySqlBooleanExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new MySqlExprParser(sql);
|
||||
exprB = (MySqlBooleanExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new MySqlExprParser(sql_c);
|
||||
exprC = (MySqlBooleanExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new MySqlBooleanExpr(), new MySqlBooleanExpr());
|
||||
Assert.assertEquals(new MySqlBooleanExpr().hashCode(), new MySqlBooleanExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLDataTypeImpl;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCastExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_cast extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "cast(a as varchar(50))";
|
||||
String sql_c = "cast(b as varchar(50))";
|
||||
SQLCastExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (SQLCastExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (SQLCastExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (SQLCastExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLCastExpr(), new SQLCastExpr());
|
||||
Assert.assertEquals(new SQLCastExpr().hashCode(), new SQLCastExpr().hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLDataTypeImpl(), new SQLDataTypeImpl());
|
||||
Assert.assertEquals(new SQLDataTypeImpl().hashCode(), new SQLDataTypeImpl().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleCursorExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_cursor extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "CURSOR(select id from t)";
|
||||
String sql_c = "CURSOR(select id from t1)";
|
||||
OracleCursorExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (OracleCursorExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (OracleCursorExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (OracleCursorExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new OracleCursorExpr(), new OracleCursorExpr());
|
||||
Assert.assertEquals(new OracleCursorExpr().hashCode(), new OracleCursorExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleDbLinkExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_dbLink extends TestCase {
|
||||
|
||||
public void test_eq() throws Exception {
|
||||
String sql = "a@b";
|
||||
String sql_c = "a@c";
|
||||
OracleDbLinkExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (OracleDbLinkExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (OracleDbLinkExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (OracleDbLinkExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new OracleDbLinkExpr(), new OracleDbLinkExpr());
|
||||
Assert.assertEquals(new OracleDbLinkExpr().hashCode(), new OracleDbLinkExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLExistsExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_exists extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "exists (select 1)";
|
||||
String sql_c = "not exists (select 1)";
|
||||
SQLExistsExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (SQLExistsExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (SQLExistsExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (SQLExistsExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLExistsExpr(), new SQLExistsExpr());
|
||||
Assert.assertEquals(new SQLExistsExpr().hashCode(), new SQLExistsExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExtractExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser;
|
||||
|
||||
public class EqualTest_extract_mysql extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "EXTRACT (YEAR FROM x)";
|
||||
String sql_c = "EXTRACT (MONTH FROM y)";
|
||||
MySqlExtractExpr exprA, exprB, exprC;
|
||||
{
|
||||
MySqlExprParser parser = new MySqlExprParser(sql);
|
||||
exprA = (MySqlExtractExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
MySqlExprParser parser = new MySqlExprParser(sql);
|
||||
exprB = (MySqlExtractExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
MySqlExprParser parser = new MySqlExprParser(sql_c);
|
||||
exprC = (MySqlExtractExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new MySqlExtractExpr(), new MySqlExtractExpr());
|
||||
Assert.assertEquals(new MySqlExtractExpr().hashCode(), new MySqlExtractExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleExtractExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_extract_oracle extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "EXTRACT(MONTH FROM x)";
|
||||
String sql_c = "EXTRACT(MONTH FROM 7)";
|
||||
OracleExtractExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (OracleExtractExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (OracleExtractExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (OracleExtractExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new OracleExtractExpr(), new OracleExtractExpr());
|
||||
Assert.assertEquals(new OracleExtractExpr().hashCode(), new OracleExtractExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInListExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_inList extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "x in (1, 2, 3)";
|
||||
String sql_c = "x not in (1, 2, 3)";
|
||||
SQLInListExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (SQLInListExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (SQLInListExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (SQLInListExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLInListExpr(), new SQLInListExpr());
|
||||
Assert.assertEquals(new SQLInListExpr().hashCode(), new SQLInListExpr().hashCode());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ import org.junit.Assert;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser;
|
||||
|
||||
public class EqualTest extends TestCase {
|
||||
public class EqualTest_inquery extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "fstate in (select state from t_status)";
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
|
||||
public class EqualTest_inquery_mysql extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "fstate in (select state from t_status)";
|
||||
String sql_c = "fstate_c in (select state from t_status)";
|
||||
SQLInSubQueryExpr exprA, exprB, exprC;
|
||||
{
|
||||
SQLExprParser parser = new SQLExprParser(sql);
|
||||
exprA = (SQLInSubQueryExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new SQLExprParser(sql);
|
||||
exprB = (SQLInSubQueryExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new SQLExprParser(sql_c);
|
||||
exprC = (SQLInSubQueryExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLInSubQueryExpr(), new SQLInSubQueryExpr());
|
||||
Assert.assertEquals(new SQLInSubQueryExpr().hashCode(), new SQLInSubQueryExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
|
||||
public class EqualTest_inquery_oracle extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "fstate in (select state from t_status)";
|
||||
String sql_c = "fstate_c in (select state from t_status)";
|
||||
SQLInSubQueryExpr exprA, exprB, exprC;
|
||||
{
|
||||
SQLExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (SQLInSubQueryExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (SQLInSubQueryExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (SQLInSubQueryExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLInSubQueryExpr(), new SQLInSubQueryExpr());
|
||||
Assert.assertEquals(new SQLInSubQueryExpr().hashCode(), new SQLInSubQueryExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlIntervalExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
|
||||
public class EqualTest_interval_mysql extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "INTERVAL 3 YEAR";
|
||||
String sql_c = "INTERVAL 3 MONTH";
|
||||
MySqlIntervalExpr exprA, exprB, exprC;
|
||||
{
|
||||
SQLExprParser parser = new MySqlExprParser(sql);
|
||||
exprA = (MySqlIntervalExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new MySqlExprParser(sql);
|
||||
exprB = (MySqlIntervalExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new MySqlExprParser(sql_c);
|
||||
exprC = (MySqlIntervalExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new MySqlIntervalExpr(), new MySqlIntervalExpr());
|
||||
Assert.assertEquals(new MySqlIntervalExpr().hashCode(), new MySqlIntervalExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -33,5 +33,13 @@ public class EqualTest_mysqlMatch extends TestCase {
|
||||
|
||||
Assert.assertEquals(new MySqlMatchAgainstExpr(), new MySqlMatchAgainstExpr());
|
||||
Assert.assertEquals(new MySqlMatchAgainstExpr().hashCode(), new MySqlMatchAgainstExpr().hashCode());
|
||||
|
||||
exprA.setColumns(null);
|
||||
exprB.setColumns(null);
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNotExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_not extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "not f1 = f2";
|
||||
String sql_c = "not f1 = f3";
|
||||
SQLNotExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (SQLNotExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (SQLNotExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (SQLNotExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLNotExpr(), new SQLNotExpr());
|
||||
Assert.assertEquals(new SQLNotExpr().hashCode(), new SQLNotExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumberExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_number extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "3.5";
|
||||
String sql_c = "3.51";
|
||||
SQLNumberExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (SQLNumberExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (SQLNumberExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (SQLNumberExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLNumberExpr(), new SQLNumberExpr());
|
||||
Assert.assertEquals(new SQLNumberExpr().hashCode(), new SQLNumberExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
|
||||
public class EqualTest_orderBy extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "ORDER BY f1";
|
||||
String sql_c = "ORDER BY f2";
|
||||
SQLOrderBy exprA, exprB, exprC;
|
||||
{
|
||||
SQLExprParser parser = new SQLExprParser(sql);
|
||||
exprA = (SQLOrderBy) parser.parseOrderBy();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new SQLExprParser(sql);
|
||||
exprB = (SQLOrderBy) parser.parseOrderBy();
|
||||
}
|
||||
{
|
||||
SQLExprParser parser = new SQLExprParser(sql_c);
|
||||
exprC = (SQLOrderBy) parser.parseOrderBy();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLOrderBy(), new SQLOrderBy());
|
||||
Assert.assertEquals(new SQLOrderBy().hashCode(), new SQLOrderBy().hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLSelectOrderByItem(), new SQLSelectOrderByItem());
|
||||
Assert.assertEquals(new SQLSelectOrderByItem().hashCode(), new SQLSelectOrderByItem().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_query extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "(select id from t)";
|
||||
String sql_c = "(select id from t1)";
|
||||
SQLQueryExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (SQLQueryExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (SQLQueryExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (SQLQueryExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLQueryExpr(), new SQLQueryExpr());
|
||||
Assert.assertEquals(new SQLQueryExpr().hashCode(), new SQLQueryExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLSomeExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_some extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "some(select id from t)";
|
||||
String sql_c = "some(select id from t1)";
|
||||
SQLSomeExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (SQLSomeExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (SQLSomeExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (SQLSomeExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLSomeExpr(), new SQLSomeExpr());
|
||||
Assert.assertEquals(new SQLSomeExpr().hashCode(), new SQLSomeExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLUnaryExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleExprParser;
|
||||
|
||||
public class EqualTest_unary extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "-a";
|
||||
String sql_c = "-(a+1 + +(b+1))";
|
||||
SQLUnaryExpr exprA, exprB, exprC;
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprA = (SQLUnaryExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql);
|
||||
exprB = (SQLUnaryExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
OracleExprParser parser = new OracleExprParser(sql_c);
|
||||
exprC = (SQLUnaryExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLUnaryExpr(), new SQLUnaryExpr());
|
||||
Assert.assertEquals(new SQLUnaryExpr().hashCode(), new SQLUnaryExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLUnaryExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser;
|
||||
|
||||
public class EqualTest_unary_mysql extends TestCase {
|
||||
|
||||
public void test_exits() throws Exception {
|
||||
String sql = "-a";
|
||||
String sql_c = "-(a+1 + +(b+1))";
|
||||
SQLUnaryExpr exprA, exprB, exprC;
|
||||
{
|
||||
MySqlExprParser parser = new MySqlExprParser(sql);
|
||||
exprA = (SQLUnaryExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
MySqlExprParser parser = new MySqlExprParser(sql);
|
||||
exprB = (SQLUnaryExpr) parser.expr();
|
||||
}
|
||||
{
|
||||
MySqlExprParser parser = new MySqlExprParser(sql_c);
|
||||
exprC = (SQLUnaryExpr) parser.expr();
|
||||
}
|
||||
Assert.assertEquals(exprA, exprB);
|
||||
Assert.assertNotEquals(exprA, exprC);
|
||||
Assert.assertTrue(exprA.equals(exprA));
|
||||
Assert.assertFalse(exprA.equals(new Object()));
|
||||
Assert.assertEquals(exprA.hashCode(), exprB.hashCode());
|
||||
|
||||
Assert.assertEquals(new SQLUnaryExpr(), new SQLUnaryExpr());
|
||||
Assert.assertEquals(new SQLUnaryExpr().hashCode(), new SQLUnaryExpr().hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.alibaba.druid.bvt.sql;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.parser.SQLParseException;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SQLParseExceptionTest extends TestCase {
|
||||
|
||||
public void test_new() throws Exception {
|
||||
new SQLParseException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.alibaba.druid.bvt.stat;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.stat.JdbcTraceManager;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class JdbcTraceManagerTest extends TestCase {
|
||||
|
||||
public void test_instance() throws Exception {
|
||||
JdbcTraceManager.getInstance();
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,8 @@ public class IPRangeTest extends TestCase {
|
||||
assertTrue(rang.isIPAddressInRange(new IPAddress("128.242.127.2")));
|
||||
|
||||
assertFalse(rang.isIPAddressInRange(new IPAddress("128.242.126.2")));
|
||||
|
||||
|
||||
rang.toString();
|
||||
}
|
||||
|
||||
public void test_ipRange_1() throws Exception {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.alibaba.druid.bvt.support.monitor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.support.monitor.PushService;
|
||||
|
||||
public class PushServiceTest extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
PushService.getInstance();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.alibaba.druid.bvt.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.util.PGUtils;
|
||||
|
||||
public class PGUtilsTest extends TestCase {
|
||||
|
||||
public void test_error() throws Exception {
|
||||
new PGUtils();
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
PGUtils.createXAConnection(null);
|
||||
} catch (Exception e) {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.alibaba.druid.bvt.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.util.ThreadLocalRandom;
|
||||
|
||||
public class ThreadLocalRandomTest extends TestCase {
|
||||
public void test_random() throws Exception {
|
||||
ThreadLocalRandom.current().nextBoolean();
|
||||
ThreadLocalRandom.current().nextDouble();
|
||||
ThreadLocalRandom.current().nextFloat();
|
||||
ThreadLocalRandom.current().nextInt();
|
||||
ThreadLocalRandom.current().nextLong();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user