mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
重构测试并且删除多余代码
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@965 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -16,7 +16,7 @@ public class CursorTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals("SELECT department_name, CURSOR(SELECT salary, commission_pct\n"
|
||||
+ "\tFROM employees e\n" + "\tWHERE e.department_id = d.department_id)\n"
|
||||
|
||||
@@ -23,7 +23,7 @@ public class OracleAnyTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals(expect, text);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class OracleEXTRACTTest extends TestCase {
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser
|
||||
.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals(expect, text);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public class OracleFlashbackQueryTest extends TestCase {
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser
|
||||
.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals(expect, text);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class OracleFlashbackQueryTest2 extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals(expect, text);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class OracleFlashbackQueryTest3 extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals(expect, text);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class OracleIntervalTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals("SELECT INTERVAL '123-2' YEAR(3) TO MONTH\nFROM DUAL;\n", text);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class OracleIntervalTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals("SELECT INTERVAL '123' YEAR(3)\nFROM DUAL;\n", text);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class OracleIntervalTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals("SELECT INTERVAL '5-3' YEAR TO MONTH + INTERVAL '20' MONTH\nFROM DUAL;\n", text);
|
||||
|
||||
@@ -54,7 +54,7 @@ public class OracleIntervalTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals("SELECT INTERVAL '6-11' YEAR TO MONTH\nFROM DUAL;\n", text);
|
||||
|
||||
@@ -67,7 +67,7 @@ public class OracleIntervalTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals("SELECT INTERVAL '4 5:12:10.222' DAY TO SECOND(3)\nFROM DUAL;\n", text);
|
||||
|
||||
@@ -80,7 +80,7 @@ public class OracleIntervalTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals("SELECT INTERVAL '30.12345' SECOND(2, 4)\nFROM DUAL;\n", text);
|
||||
|
||||
@@ -93,7 +93,7 @@ public class OracleIntervalTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals("SELECT (SYSTIMESTAMP - order_date) DAY(9) TO SECOND\n" + "FROM orders\n"
|
||||
+ "WHERE order_id = 2458;\n", text);
|
||||
|
||||
@@ -15,7 +15,7 @@ public class OracleIsASetTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals("SELECT customer_id, cust_address_ntab\n" + "FROM customers_demo\n"
|
||||
+ "WHERE cust_address_ntab IS A SET;\n", text);
|
||||
|
||||
@@ -18,7 +18,7 @@ public class OracleIsEmptyTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals(expect, text);
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.alibaba.druid.bvt.sql.oracle;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.test.TestUtils;
|
||||
|
||||
public class OracleIsLiteralTest extends TestCase {
|
||||
|
||||
public void test_oracle() throws Exception {
|
||||
String sql = "SELECT FROM_TZ(TIMESTAMP '2007-11-20 08:00:00', '3:00') FROM DUAL;";
|
||||
|
||||
String expect = "SELECT FROM_TZ(TIMESTAMP '2007-11-20 08:00:00', '3:00')\n" + "FROM DUAL;\n";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals(expect, text);
|
||||
|
||||
System.out.println(text);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class OracleNumberLiteralTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals("SELECT 7, 255, 0.5, 6.34, 0.025\n\t, 6.34F, 0.5D, -1.0D\nFROM DUAL;\n", text);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class OracleNumberLiteralTest extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals("SELECT BINARY_FLOAT_INFINITY\nFROM DUAL;\n", text);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class OracleSQLParserResourceTest extends TestCase {
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
String text = TestUtils.output(statementList);
|
||||
String text = TestUtils.outputOracle(statementList);
|
||||
System.out.println(text);
|
||||
Assert.assertEquals(expect, text.trim());
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class OracleTest2 extends TestCase {
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
SQLSelectStatement stmt = (SQLSelectStatement) parser.parseStatementList().get(0);
|
||||
|
||||
String text = TestUtils.output(stmt);
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals(expect, text);
|
||||
|
||||
|
||||
@@ -5,11 +5,12 @@ import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
public static String output(List<SQLStatement> stmtList) {
|
||||
public static String outputOracle(List<SQLStatement> stmtList) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
OracleOutputVisitor visitor = new OracleOutputVisitor(out);
|
||||
|
||||
@@ -20,7 +21,22 @@ public class TestUtils {
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static String outputOracle(SQLStatement... stmtList) {
|
||||
return outputOracle(Arrays.asList(stmtList));
|
||||
}
|
||||
|
||||
public static String output(SQLStatement... stmtList) {
|
||||
return output(Arrays.asList(stmtList));
|
||||
}
|
||||
|
||||
public static String output(List<SQLStatement> stmtList) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
SQLASTOutputVisitor visitor = new SQLASTOutputVisitor(out);
|
||||
|
||||
for (SQLStatement stmt : stmtList) {
|
||||
stmt.accept(visitor);
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user