From f1eb24a1dee85eb5c5b3471760928d57e79ac89b Mon Sep 17 00:00:00 2001 From: wenshao Date: Sun, 25 Sep 2016 07:18:21 +0800 Subject: [PATCH] add testcase for issue #1432 --- .../bvt/sql/MappingTest_createTable_2.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/test/java/com/alibaba/druid/bvt/sql/MappingTest_createTable_2.java diff --git a/src/test/java/com/alibaba/druid/bvt/sql/MappingTest_createTable_2.java b/src/test/java/com/alibaba/druid/bvt/sql/MappingTest_createTable_2.java new file mode 100644 index 0000000000..5655f13d23 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/MappingTest_createTable_2.java @@ -0,0 +1,75 @@ +package com.alibaba.druid.bvt.sql; + +import com.alibaba.druid.sql.SQLUtils; +import com.alibaba.druid.util.JdbcConstants; +import junit.framework.TestCase; + +import java.util.Collections; +import java.util.Map; + +/** + * Created by wenshao on 16/9/25. + */ +public class MappingTest_createTable_2 extends TestCase { + String sql = "create table database_source.table_source(\n" + + "source_key int,\n" + + "source_value varchar(32),\n" + + "primary key(source_key)\n" + + ");"; + + Map mapping = Collections.singletonMap("database_source.table_source", "database_target.table_target"); + + public void test_mapping_createTable() throws Exception { + String result = SQLUtils.refactor(sql, null, mapping); + assertEquals("CREATE TABLE database_target.table_target (\n" + + "\tsource_key int,\n" + + "\tsource_value varchar(32),\n" + + "\tPRIMARY KEY (source_key)\n" + + ")", result); + } + + public void test_mapping_createTable_mysql() throws Exception { + String result = SQLUtils.refactor(sql, JdbcConstants.MYSQL, mapping); + assertEquals("CREATE TABLE database_target.table_target (\n" + + "\tsource_key int, \n" + + "\tsource_value varchar(32), \n" + + "\tPRIMARY KEY (source_key)\n" + + ")", result); + } + + public void test_mapping_createTable_oracle() throws Exception { + String result = SQLUtils.refactor(sql, JdbcConstants.ORACLE, mapping); + assertEquals("CREATE TABLE database_target.table_target (\n" + + "\tsource_key int,\n" + + "\tsource_value varchar(32),\n" + + "\tPRIMARY KEY (source_key)\n" + + ")", result); + } + + public void test_mapping_createTable_pg() throws Exception { + String result = SQLUtils.refactor(sql, JdbcConstants.POSTGRESQL, mapping); + assertEquals("CREATE TABLE database_target.table_target (\n" + + "\tsource_key int,\n" + + "\tsource_value varchar(32),\n" + + "\tPRIMARY KEY (source_key)\n" + + ")", result); + } + + public void test_mapping_createTable_sqlserver() throws Exception { + String result = SQLUtils.refactor(sql, JdbcConstants.SQL_SERVER, mapping); + assertEquals("CREATE TABLE database_target.table_target (\n" + + "\tsource_key int,\n" + + "\tsource_value varchar(32),\n" + + "\tPRIMARY KEY (source_key)\n" + + ")", result); + } + + public void test_mapping_createTable_db2() throws Exception { + String result = SQLUtils.refactor(sql, JdbcConstants.DB2, mapping); + assertEquals("CREATE TABLE database_target.table_target (\n" + + "\tsource_key int,\n" + + "\tsource_value varchar(32),\n" + + "\tPRIMARY KEY (source_key)\n" + + ")", result); + } +}