提交 24050a12 编写于 作者: H haocao

Add mssql test cases and test scope dependency.

上级 5b703313
......@@ -33,6 +33,7 @@
<mysql-connector-java.version>5.1.30</mysql-connector-java.version>
<h2.version>1.4.184</h2.version>
<postgresql.version>9.1-901-1.jdbc4</postgresql.version>
<mssql.version>6.1.7.jre7-preview</mssql.version>
<junit.version>4.12</junit.version>
<system-rules.version>1.16.0</system-rules.version>
<hamcrest.version>1.3</hamcrest.version>
......@@ -184,6 +185,12 @@
<version>${postgresql.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${mssql.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
......
......@@ -54,6 +54,10 @@
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
......
......@@ -21,6 +21,7 @@ import com.dangdang.ddframe.rdb.integrate.sql.DatabaseTestSQL;
import com.dangdang.ddframe.rdb.integrate.sql.mysql.MySQLTestSQL;
import com.dangdang.ddframe.rdb.integrate.sql.oracle.OracleSQLTestSQL;
import com.dangdang.ddframe.rdb.integrate.sql.postgresql.PostgreSQLTestSQL;
import com.dangdang.ddframe.rdb.integrate.sql.sqlserver.SQLServerSQLTestSQL;
import com.dangdang.ddframe.rdb.sharding.constant.DatabaseType;
import org.apache.commons.dbcp.BasicDataSource;
import org.dbunit.DatabaseUnitException;
......@@ -31,6 +32,7 @@ import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.ITable;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
import org.dbunit.ext.h2.H2Connection;
import org.dbunit.ext.mssql.MsSqlConnection;
import org.dbunit.ext.mysql.MySqlConnection;
import org.dbunit.ext.oracle.OracleConnection;
import org.dbunit.operation.DatabaseOperation;
......@@ -104,6 +106,8 @@ public abstract class AbstractDBUnitTest {
return new PostgreSQLTestSQL();
case Oracle:
return new OracleSQLTestSQL();
case SQLServer:
return new SQLServerSQLTestSQL();
default:
throw new UnsupportedOperationException(dbEnv.getDatabaseType().name());
}
......@@ -180,6 +184,8 @@ public abstract class AbstractDBUnitTest {
return new DatabaseConnection(connection);
case Oracle:
return new OracleConnection(connection, "JDBC");
case SQLServer:
return new MsSqlConnection(connection);
default:
throw new UnsupportedOperationException(dbEnv.getDatabaseType().name());
}
......
......@@ -69,6 +69,12 @@ public final class DataBaseEnvironment {
USERNAME.put(DatabaseType.Oracle, "jdbc");
PASSWORD.put(DatabaseType.Oracle, "jdbc");
SCHEMA.put(DatabaseType.Oracle, "JDBC");
DRIVER_CLASS_NAME.put(DatabaseType.SQLServer, com.microsoft.sqlserver.jdbc.SQLServerDriver.class.getName());
URL.put(DatabaseType.SQLServer, "jdbc:sqlserver://db.mssql:1433;DatabaseName=db_0");
USERNAME.put(DatabaseType.SQLServer, "sa");
PASSWORD.put(DatabaseType.SQLServer, "Jdbc1234");
SCHEMA.put(DatabaseType.SQLServer, null);
}
public String getDriverClassName() {
......
/*
* Copyright 1999-2015 dangdang.com.
* <p>
* 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.
* </p>
*/
package com.dangdang.ddframe.rdb.integrate.sql.sqlserver;
import com.dangdang.ddframe.rdb.integrate.sql.AbstractDatabaseTestSQL;
public final class SQLServerSQLTestSQL extends AbstractDatabaseTestSQL {
private static final String SELECT_LIMIT_WITH_BINDING_TABLE_SQL = "SELECT i.* FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id"
+ " WHERE o.user_id IN (%s, %s) AND o.order_id BETWEEN %s AND %s ORDER BY i.item_id DESC OFFSET %s LIMIT %s";
@Override
public String getSelectLimitWithBindingTableSql() {
return SELECT_LIMIT_WITH_BINDING_TABLE_SQL;
}
}
......@@ -28,6 +28,7 @@ import java.sql.SQLException;
import static com.dangdang.ddframe.rdb.integrate.SqlPlaceholderUtil.replacePreparedStatement;
import static com.dangdang.ddframe.rdb.sharding.constant.DatabaseType.Oracle;
import static com.dangdang.ddframe.rdb.sharding.constant.DatabaseType.PostgreSQL;
import static com.dangdang.ddframe.rdb.sharding.constant.DatabaseType.SQLServer;
public final class ShardingTablesOnlyForPreparedStatementWithSelectTest extends AbstractShardingTablesOnlyDBUnitTest {
......@@ -71,7 +72,7 @@ public final class ShardingTablesOnlyForPreparedStatementWithSelectTest extends
@Test
public void assertSelectLimitWithBindingTable() throws SQLException, DatabaseUnitException {
if (!Oracle.name().equalsIgnoreCase(currentDbType())) {
if (!Oracle.name().equalsIgnoreCase(currentDbType()) && !SQLServer.name().equalsIgnoreCase(currentDbType())) {
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) ? TABLE_ONLY_PREFIX + "/expect/select/postgresql/SelectLimitWithBindingTable.xml"
: TABLE_ONLY_PREFIX + "/expect/select/SelectLimitWithBindingTable.xml";
if (PostgreSQL.name().equalsIgnoreCase(currentDbType())) {
......@@ -88,7 +89,7 @@ public final class ShardingTablesOnlyForPreparedStatementWithSelectTest extends
@Test
public void assertSelectLimitWithBindingTableWithoutOffset() throws SQLException, DatabaseUnitException {
if (!Oracle.name().equalsIgnoreCase(currentDbType())) {
if (!Oracle.name().equalsIgnoreCase(currentDbType()) && !SQLServer.name().equalsIgnoreCase(currentDbType())) {
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) ? TABLE_ONLY_PREFIX + "/expect/select/postgresql/SelectLimitWithBindingTableWithoutOffset.xml"
: TABLE_ONLY_PREFIX + "/expect/select/SelectLimitWithBindingTableWithoutOffset.xml";
assertDataSet(expectedDataSetFile, getShardingDataSource().getConnection(), "t_order_item",
......@@ -107,7 +108,7 @@ public final class ShardingTablesOnlyForPreparedStatementWithSelectTest extends
@Test
public void assertSelectGroupByWithoutGroupedColumn() throws SQLException, DatabaseUnitException {
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) || Oracle.name().equalsIgnoreCase(currentDbType())
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) || Oracle.name().equalsIgnoreCase(currentDbType()) || SQLServer.name().equalsIgnoreCase(currentDbType())
? TABLE_ONLY_PREFIX + "/expect/select/postgresql/SelectGroupByWithoutGroupedColumn.xml"
: TABLE_ONLY_PREFIX + "/expect/select/SelectGroupByWithoutGroupedColumn.xml";
assertDataSet(expectedDataSetFile, getShardingDataSource().getConnection(),
......@@ -117,7 +118,7 @@ public final class ShardingTablesOnlyForPreparedStatementWithSelectTest extends
@Test
public void assertSelectNoShardingTable() throws SQLException, DatabaseUnitException {
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) || Oracle.name().equalsIgnoreCase(currentDbType())
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) || Oracle.name().equalsIgnoreCase(currentDbType()) || SQLServer.name().equalsIgnoreCase(currentDbType())
? TABLE_ONLY_PREFIX + "/expect/select/postgresql/SelectNoShardingTable.xml"
: TABLE_ONLY_PREFIX + "/expect/select/SelectNoShardingTable.xml";
assertDataSet(expectedDataSetFile, getShardingDataSource().getConnection(),
......@@ -126,7 +127,7 @@ public final class ShardingTablesOnlyForPreparedStatementWithSelectTest extends
@Test
public void assertSelectWithBindingTableAndConfigTable() throws SQLException, DatabaseUnitException {
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) || Oracle.name().equalsIgnoreCase(currentDbType())
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) || Oracle.name().equalsIgnoreCase(currentDbType()) || SQLServer.name().equalsIgnoreCase(currentDbType())
? TABLE_ONLY_PREFIX + "/expect/select/postgresql/SelectWithBindingTableAndConfigTable.xml"
: TABLE_ONLY_PREFIX + "/expect/select/SelectWithBindingTableAndConfigTable.xml";
assertDataSet(expectedDataSetFile, shardingDataSource.getConnection(),
......
......@@ -27,6 +27,7 @@ import java.sql.SQLException;
import static com.dangdang.ddframe.rdb.sharding.constant.DatabaseType.Oracle;
import static com.dangdang.ddframe.rdb.sharding.constant.DatabaseType.PostgreSQL;
import static com.dangdang.ddframe.rdb.sharding.constant.DatabaseType.SQLServer;
public final class ShardingTablesOnlyForStatementWithSelectTest extends AbstractShardingTablesOnlyDBUnitTest {
......@@ -66,7 +67,7 @@ public final class ShardingTablesOnlyForStatementWithSelectTest extends Abstract
@Test
public void assertSelectLimitWithBindingTable() throws SQLException, DatabaseUnitException {
if (!Oracle.name().equalsIgnoreCase(currentDbType())) {
if (!Oracle.name().equalsIgnoreCase(currentDbType()) && !SQLServer.name().equalsIgnoreCase(currentDbType())) {
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) ? "integrate/dataset/tbl/expect/select/postgresql/SelectLimitWithBindingTable.xml"
: "integrate/dataset/tbl/expect/select/SelectLimitWithBindingTable.xml";
assertDataSet(expectedDataSetFile, shardingDataSource.getConnection(),
......@@ -86,7 +87,7 @@ public final class ShardingTablesOnlyForStatementWithSelectTest extends Abstract
@Test
public void assertSelectGroupByWithoutGroupedColumn() throws SQLException, DatabaseUnitException {
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) || Oracle.name().equalsIgnoreCase(currentDbType())
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) || Oracle.name().equalsIgnoreCase(currentDbType()) || SQLServer.name().equalsIgnoreCase(currentDbType())
? "integrate/dataset/tbl/expect/select/postgresql/SelectGroupByWithoutGroupedColumn.xml"
: "integrate/dataset/tbl/expect/select/SelectGroupByWithoutGroupedColumn.xml";
assertDataSet(expectedDataSetFile, shardingDataSource.getConnection(),
......@@ -97,7 +98,7 @@ public final class ShardingTablesOnlyForStatementWithSelectTest extends Abstract
@Test
public void assertSelectWithBindingTableAndConfigTable() throws SQLException, DatabaseUnitException {
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) || Oracle.name().equalsIgnoreCase(currentDbType())
String expectedDataSetFile = PostgreSQL.name().equalsIgnoreCase(currentDbType()) || Oracle.name().equalsIgnoreCase(currentDbType()) || SQLServer.name().equalsIgnoreCase(currentDbType())
? "integrate/dataset/tbl/expect/select/postgresql/SelectWithBindingTableAndConfigTable.xml"
: "integrate/dataset/tbl/expect/select/SelectWithBindingTableAndConfigTable.xml";
assertDataSet(expectedDataSetFile, shardingDataSource.getConnection(),
......
CREATE TABLE t_order_0 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
CREATE TABLE t_order_1 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
CREATE TABLE t_order_2 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
CREATE TABLE t_order_3 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
CREATE TABLE t_order_4 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
CREATE TABLE t_order_5 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
CREATE TABLE t_order_6 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
CREATE TABLE t_order_7 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
CREATE TABLE t_order_8 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
CREATE TABLE t_order_9 (order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (order_id));
CREATE TABLE t_order_item_0 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
CREATE TABLE t_order_item_1 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
CREATE TABLE t_order_item_2 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
CREATE TABLE t_order_item_3 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
CREATE TABLE t_order_item_4 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
CREATE TABLE t_order_item_5 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
CREATE TABLE t_order_item_6 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
CREATE TABLE t_order_item_7 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
CREATE TABLE t_order_item_8 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
CREATE TABLE t_order_item_9 (item_id INT NOT NULL, order_id INT NOT NULL, user_id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (item_id));
CREATE TABLE t_config (id INT NOT NULL, status VARCHAR(45) NULL, PRIMARY KEY (id));
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册