Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
697a2c73
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
697a2c73
编写于
5月 07, 2018
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
for #601: use sql case id to driven test case
上级
a51f3d0c
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
215 addition
and
79 deletion
+215
-79
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java
...-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java
+31
-69
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/asserts/AssertEngine.java
...est/java/io/shardingjdbc/dbtest/asserts/AssertEngine.java
+6
-7
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/asserts/DataSetAssertLoader.java
...a/io/shardingjdbc/dbtest/asserts/DataSetAssertLoader.java
+155
-0
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertDDLDefinition.java
.../shardingjdbc/dbtest/config/bean/AssertDDLDefinition.java
+5
-1
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertDMLDefinition.java
.../shardingjdbc/dbtest/config/bean/AssertDMLDefinition.java
+5
-1
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertDQLDefinition.java
.../shardingjdbc/dbtest/config/bean/AssertDQLDefinition.java
+5
-1
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertDefinition.java
.../io/shardingjdbc/dbtest/config/bean/AssertDefinition.java
+8
-0
未找到文件。
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java
浏览文件 @
697a2c73
...
...
@@ -17,14 +17,15 @@
package
io.shardingjdbc.dbtest
;
import
com.google.common.base.Strings
;
import
io.shardingjdbc.core.constant.DatabaseType
;
import
io.shardingjdbc.dbtest.asserts.AssertEngine
;
import
io.shardingjdbc.dbtest.asserts.DataSetAssertLoader
;
import
io.shardingjdbc.dbtest.config.bean.AssertDefinition
;
import
io.shardingjdbc.dbtest.config.bean.AssertsDefinition
;
import
io.shardingjdbc.dbtest.env.DatabaseTypeEnvironment
;
import
io.shardingjdbc.dbtest.env.IntegrateTestEnvironment
;
import
io.shardingjdbc.dbtest.env.schema.SchemaEnvironmentManager
;
import
io.shardingjdbc.test.sql.SQLCaseType
;
import
io.shardingjdbc.test.sql.SQLCasesLoader
;
import
lombok.RequiredArgsConstructor
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
...
...
@@ -34,37 +35,24 @@ import org.junit.runners.Parameterized;
import
org.junit.runners.Parameterized.Parameters
;
import
org.xml.sax.SAXException
;
import
javax.xml.bind.JAXBContext
;
import
javax.xml.bind.JAXBException
;
import
javax.xml.parsers.ParserConfigurationException
;
import
javax.xml.xpath.XPathExpressionException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.net.URISyntaxException
;
import
java.net.URL
;
import
java.nio.file.FileVisitResult
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.SimpleFileVisitor
;
import
java.nio.file.attribute.BasicFileAttributes
;
import
java.sql.SQLException
;
import
java.text.ParseException
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
java.util.LinkedList
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
@RunWith
(
Parameterized
.
class
)
@RequiredArgsConstructor
public
final
class
StartTest
{
private
static
final
String
INTEGRATION_RESOURCES_PATH
=
"asserts"
;
private
static
SQLCasesLoader
sqlCasesLoader
=
SQLCasesLoader
.
getInstance
()
;
private
static
final
Collection
<
String
>
SHARDING_RULE_TYPES
=
new
HashSet
<>
();
private
static
DataSetAssertLoader
dataSetAssertLoader
=
DataSetAssertLoader
.
getInstance
();
private
static
boolean
isInitialized
=
IntegrateTestEnvironment
.
getInstance
().
isInitialized
();
...
...
@@ -76,59 +64,33 @@ public final class StartTest {
private
final
DatabaseTypeEnvironment
databaseTypeEnvironment
;
private
final
S
tring
path
;
private
final
S
QLCaseType
caseType
;
@Parameters
(
name
=
"{0} -> Rule:{1} -> {2}"
)
public
static
Collection
<
Object
[]>
getParameters
()
throws
IOException
,
JAXBException
,
URISyntaxException
{
URL
integrateResources
=
StartTest
.
class
.
getClassLoader
().
getResource
(
INTEGRATION_RESOURCES_PATH
);
assertNotNull
(
integrateResources
);
List
<
Object
[]>
result
=
new
LinkedList
<>();
for
(
String
each
:
getAssertFiles
(
integrateResources
))
{
AssertsDefinition
assertsDefinition
=
unmarshal
(
each
);
Collection
<
String
>
shardingRuleTypes
=
Arrays
.
asList
(
assertsDefinition
.
getShardingRuleType
().
split
(
","
));
SHARDING_RULE_TYPES
.
addAll
(
shardingRuleTypes
);
Collection
<
DatabaseType
>
databaseTypes
=
getDatabaseTypes
(
assertsDefinition
.
getDatabaseConfig
());
result
.
addAll
(
getParameters
(
each
,
assertsDefinition
.
getAssertDQL
(),
shardingRuleTypes
,
databaseTypes
));
result
.
addAll
(
getParameters
(
each
,
assertsDefinition
.
getAssertDML
(),
shardingRuleTypes
,
databaseTypes
));
result
.
addAll
(
getParameters
(
each
,
assertsDefinition
.
getAssertDDL
(),
shardingRuleTypes
,
databaseTypes
));
}
return
result
;
}
private
static
Collection
<
Object
[]>
getParameters
(
final
String
path
,
final
List
<?
extends
AssertDefinition
>
assertDefinitions
,
final
Collection
<
String
>
defaultShardingRuleTypes
,
final
Collection
<
DatabaseType
>
defaultDatabaseTypes
)
{
public
static
Collection
<
Object
[]>
getParameters
()
{
Collection
<
Object
[]>
result
=
new
LinkedList
<>();
for
(
AssertDefinition
each
:
assertDefinitions
)
{
Collection
<
String
>
shardingRuleTypes
=
Strings
.
isNullOrEmpty
(
each
.
getShardingRuleType
())
?
defaultShardingRuleTypes
:
Arrays
.
asList
(
each
.
getShardingRuleType
().
split
(
","
)
);
for
(
String
shardingRuleType
:
shardingRuleTypes
)
{
Collection
<
DatabaseType
>
databaseTypes
=
Strings
.
isNullOrEmpty
(
each
.
getDatabaseConfig
())
?
defaultDatabaseTypes
:
getDatabaseTypes
(
each
.
getDatabaseConfig
())
;
for
(
DatabaseType
databaseType
:
databaseTypes
)
{
result
.
add
(
new
Object
[]
{
each
,
shardingRuleType
,
new
DatabaseTypeEnvironment
(
databaseType
,
IntegrateTestEnvironment
.
getInstance
().
getDatabaseTypes
().
contains
(
databaseType
)),
path
});
}
for
(
Object
[]
each
:
sqlCasesLoader
.
getSupportedSQLTestParameters
(
Arrays
.<
Enum
>
asList
(
DatabaseType
.
values
()),
DatabaseType
.
class
)
)
{
String
sqlCaseId
=
each
[
0
].
toString
(
);
DatabaseType
databaseType
=
(
DatabaseType
)
each
[
1
];
SQLCaseType
caseType
=
(
SQLCaseType
)
each
[
2
]
;
AssertDefinition
assertDefinition
=
dataSetAssertLoader
.
getDataSetAssert
(
sqlCaseId
);
// TODO remove when transfer finished
if
(
null
==
assertDefinition
)
{
continue
;
}
}
return
result
;
}
private
static
List
<
String
>
getAssertFiles
(
final
URL
integrateResources
)
throws
IOException
,
URISyntaxException
{
final
List
<
String
>
result
=
new
LinkedList
<>();
Files
.
walkFileTree
(
Paths
.
get
(
integrateResources
.
toURI
()),
new
SimpleFileVisitor
<
Path
>()
{
@Override
public
FileVisitResult
visitFile
(
final
Path
file
,
final
BasicFileAttributes
basicFileAttributes
)
{
if
(
file
.
getFileName
().
toString
().
startsWith
(
"assert-"
)
&&
file
.
getFileName
().
toString
().
endsWith
(
".xml"
))
{
result
.
add
(
file
.
toFile
().
getPath
());
}
return
FileVisitResult
.
CONTINUE
;
if
(!
getDatabaseTypes
(
assertDefinition
.
getDatabaseConfig
()).
contains
(
databaseType
))
{
continue
;
}
for
(
String
shardingRuleType
:
assertDefinition
.
getShardingRuleType
().
split
(
","
))
{
Object
[]
data
=
new
Object
[
4
];
data
[
0
]
=
assertDefinition
;
data
[
1
]
=
shardingRuleType
;
data
[
2
]
=
new
DatabaseTypeEnvironment
(
databaseType
,
IntegrateTestEnvironment
.
getInstance
().
getDatabaseTypes
().
contains
(
databaseType
));
data
[
3
]
=
caseType
;
result
.
add
(
data
);
}
});
return
result
;
}
private
static
AssertsDefinition
unmarshal
(
final
String
assertFilePath
)
throws
IOException
,
JAXBException
{
try
(
FileReader
reader
=
new
FileReader
(
assertFilePath
))
{
return
(
AssertsDefinition
)
JAXBContext
.
newInstance
(
AssertsDefinition
.
class
).
createUnmarshaller
().
unmarshal
(
reader
);
}
return
result
;
}
private
static
List
<
DatabaseType
>
getDatabaseTypes
(
final
String
databaseTypes
)
{
...
...
@@ -144,14 +106,14 @@ public final class StartTest {
if
(
isInitialized
)
{
isInitialized
=
false
;
}
else
{
for
(
String
each
:
SHARDING_RULE_TYPES
)
{
for
(
String
each
:
dataSetAssertLoader
.
getShardingRuleTypes
()
)
{
SchemaEnvironmentManager
.
dropDatabase
(
each
);
}
}
for
(
String
each
:
SHARDING_RULE_TYPES
)
{
for
(
String
each
:
dataSetAssertLoader
.
getShardingRuleTypes
()
)
{
SchemaEnvironmentManager
.
createDatabase
(
each
);
}
for
(
String
each
:
SHARDING_RULE_TYPES
)
{
for
(
String
each
:
dataSetAssertLoader
.
getShardingRuleTypes
()
)
{
SchemaEnvironmentManager
.
createTable
(
each
);
}
}
...
...
@@ -160,7 +122,7 @@ public final class StartTest {
// TODO add tearDown for temporary, will remove when original integrate test removed.
public
static
void
tearDown
()
throws
JAXBException
,
IOException
{
if
(
isCleaned
)
{
for
(
String
each
:
SHARDING_RULE_TYPES
)
{
for
(
String
each
:
dataSetAssertLoader
.
getShardingRuleTypes
()
)
{
SchemaEnvironmentManager
.
dropDatabase
(
each
);
}
isCleaned
=
false
;
...
...
@@ -169,6 +131,6 @@ public final class StartTest {
@Test
public
void
test
()
throws
JAXBException
,
SAXException
,
ParseException
,
IOException
,
XPathExpressionException
,
SQLException
,
ParserConfigurationException
{
AssertEngine
.
runAssert
(
assertDefinition
,
shardingRuleType
,
databaseTypeEnvironment
,
path
);
AssertEngine
.
runAssert
(
assertDefinition
,
shardingRuleType
,
databaseTypeEnvironment
);
}
}
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/asserts/AssertEngine.java
浏览文件 @
697a2c73
...
...
@@ -69,13 +69,12 @@ public final class AssertEngine {
* @param assertDefinition assert definition
* @param shardingRuleType sharding rule type
* @param databaseTypeEnvironment database type environment
* @param path Check the use case storage path
*/
public
static
void
runAssert
(
final
AssertDefinition
assertDefinition
,
final
String
shardingRuleType
,
final
DatabaseTypeEnvironment
databaseTypeEnvironment
,
final
String
path
)
throws
IOException
,
SQLException
,
SAXException
,
ParserConfigurationException
,
XPathExpressionException
,
ParseException
,
JAXBException
{
public
static
void
runAssert
(
final
AssertDefinition
assertDefinition
,
final
String
shardingRuleType
,
final
DatabaseTypeEnvironment
databaseTypeEnvironment
)
throws
IOException
,
SQLException
,
SAXException
,
ParserConfigurationException
,
XPathExpressionException
,
ParseException
,
JAXBException
{
if
(!
databaseTypeEnvironment
.
isEnabled
())
{
return
;
}
String
rootPath
=
path
.
substring
(
0
,
path
.
lastIndexOf
(
File
.
separator
)
+
1
);
String
rootPath
=
assertDefinition
.
getPath
().
substring
(
0
,
assertDefinition
.
getPath
()
.
lastIndexOf
(
File
.
separator
)
+
1
);
String
initDataPath
=
EnvironmentPath
.
getDataInitializeResourceFile
(
shardingRuleType
);
Collection
<
String
>
dataSourceNames
=
SchemaEnvironmentManager
.
getDataSourceNames
(
shardingRuleType
);
Map
<
String
,
DataSource
>
dataSourceMap
=
createDataSourceMap
(
dataSourceNames
,
databaseTypeEnvironment
.
getDatabaseType
());
...
...
@@ -170,7 +169,7 @@ public final class AssertEngine {
AssertDDLDefinition
anAssertSub
=
new
AssertDDLDefinition
(
anAssert
.
getId
(),
anAssert
.
getInitSql
(),
anAssert
.
getShardingRuleType
(),
anAssert
.
getDatabaseConfig
(),
anAssert
.
getCleanSql
(),
expectedDataFileSub
,
anAssert
.
getSql
(),
anAssert
.
getTable
(),
parameter
,
anAssert
.
getSubAsserts
());
parameter
,
anAssert
.
getSubAsserts
()
,
""
);
doUpdateUseStatementToExecuteUpdateDDL
(
shardingRuleType
,
databaseType
,
expectedDataFileTmp
,
dataSource
,
anAssertSub
,
rootsql
);
doUpdateUseStatementToExecuteDDL
(
shardingRuleType
,
databaseType
,
expectedDataFileTmp
,
dataSource
,
anAssertSub
,
rootsql
);
doUpdateUsePreparedStatementToExecuteUpdateDDL
(
shardingRuleType
,
databaseType
,
expectedDataFileTmp
,
dataSource
,
anAssertSub
,
rootsql
);
...
...
@@ -246,7 +245,7 @@ public final class AssertEngine {
}
AssertDMLDefinition
anAssertSub
=
new
AssertDMLDefinition
(
dmlDefinition
.
getId
(),
expectedDataFileSub
,
dmlDefinition
.
getShardingRuleType
(),
dmlDefinition
.
getDatabaseConfig
(),
subAssert
.
getExpectedUpdate
(),
dmlDefinition
.
getSql
(),
dmlDefinition
.
getExpectedSql
(),
parameter
,
expectedParameter
,
dmlDefinition
.
getSubAsserts
());
dmlDefinition
.
getExpectedSql
(),
parameter
,
expectedParameter
,
dmlDefinition
.
getSubAsserts
()
,
""
);
resultDoUpdateUseStatementToExecuteUpdate
=
resultDoUpdateUseStatementToExecuteUpdate
+
doUpdateUseStatementToExecuteUpdate
(
expectedDataFileTmp
,
dataSource
,
dataSourceMaps
,
anAssertSub
,
rootSQL
,
mapDatasetDefinition
,
sqls
);
resultDoUpdateUseStatementToExecute
=
resultDoUpdateUseStatementToExecute
+
doUpdateUseStatementToExecute
(
expectedDataFileTmp
,
dataSource
,
dataSourceMaps
,
anAssertSub
,
rootSQL
,
mapDatasetDefinition
,
sqls
);
resultDoUpdateUsePreparedStatementToExecuteUpdate
=
resultDoUpdateUsePreparedStatementToExecuteUpdate
+
doUpdateUsePreparedStatementToExecuteUpdate
(
expectedDataFileTmp
,
dataSource
,
dataSourceMaps
,
anAssertSub
,
rootSQL
,
mapDatasetDefinition
,
sqls
);
...
...
@@ -299,7 +298,7 @@ public final class AssertEngine {
}
AssertDMLDefinition
anAssertSub
=
new
AssertDMLDefinition
(
dmlDefinition
.
getId
(),
expectedDataFileSub
,
dmlDefinition
.
getShardingRuleType
(),
dmlDefinition
.
getDatabaseConfig
(),
subAssert
.
getExpectedUpdate
(),
dmlDefinition
.
getSql
(),
dmlDefinition
.
getExpectedSql
(),
parameter
,
expectedParameter
,
dmlDefinition
.
getSubAsserts
());
dmlDefinition
.
getExpectedSql
(),
parameter
,
expectedParameter
,
dmlDefinition
.
getSubAsserts
()
,
""
);
resultDoUpdateUseStatementToExecuteUpdate
=
resultDoUpdateUseStatementToExecuteUpdate
+
doUpdateUseStatementToExecuteUpdate
(
expectedDataFileTmp
,
dataSource
,
dataSourceMaps
,
anAssertSub
,
rootSQL
,
mapDatasetDefinition
,
sqls
);
resultDoUpdateUseStatementToExecute
=
resultDoUpdateUseStatementToExecute
+
doUpdateUseStatementToExecute
(
expectedDataFileTmp
,
dataSource
,
dataSourceMaps
,
anAssertSub
,
rootSQL
,
mapDatasetDefinition
,
sqls
);
resultDoUpdateUsePreparedStatementToExecuteUpdate
=
resultDoUpdateUsePreparedStatementToExecuteUpdate
+
doUpdateUsePreparedStatementToExecuteUpdate
(
expectedDataFileTmp
,
dataSource
,
dataSourceMaps
,
anAssertSub
,
rootSQL
,
mapDatasetDefinition
,
sqls
);
...
...
@@ -394,7 +393,7 @@ public final class AssertEngine {
}
AssertDQLDefinition
anAssertSub
=
new
AssertDQLDefinition
(
anAssert
.
getId
(),
expectedDataFileSub
,
anAssert
.
getShardingRuleType
(),
anAssert
.
getDatabaseConfig
(),
anAssert
.
getSql
(),
parameter
,
anAssert
.
getSubAsserts
());
parameter
,
anAssert
.
getSubAsserts
()
,
""
);
doSelectUsePreparedStatement
(
expectedDataFileTmp
,
dataSource
,
anAssertSub
,
rootSQL
);
doSelectUsePreparedStatementToExecuteSelect
(
expectedDataFileTmp
,
dataSource
,
anAssertSub
,
rootSQL
);
doSelectUseStatement
(
expectedDataFileTmp
,
dataSource
,
anAssertSub
,
rootSQL
);
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/asserts/DataSetAssertLoader.java
0 → 100644
浏览文件 @
697a2c73
/*
* 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
io.shardingjdbc.dbtest.asserts
;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Strings
;
import
io.shardingjdbc.dbtest.config.bean.AssertDefinition
;
import
io.shardingjdbc.dbtest.config.bean.AssertsDefinition
;
import
lombok.Getter
;
import
lombok.extern.slf4j.Slf4j
;
import
javax.xml.bind.JAXBContext
;
import
javax.xml.bind.JAXBException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.net.URISyntaxException
;
import
java.net.URL
;
import
java.nio.file.FileVisitResult
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.SimpleFileVisitor
;
import
java.nio.file.attribute.BasicFileAttributes
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
/**
* Data set assert loader.
*
* @author zhangliang
*/
@Slf4j
public
final
class
DataSetAssertLoader
{
private
static
final
DataSetAssertLoader
INSTANCE
=
new
DataSetAssertLoader
();
@Getter
private
final
Collection
<
String
>
shardingRuleTypes
;
private
final
Map
<
String
,
AssertDefinition
>
dataSetAssertMap
;
private
DataSetAssertLoader
()
{
shardingRuleTypes
=
new
HashSet
<>();
try
{
dataSetAssertMap
=
loadDataSetAssert
();
}
catch
(
final
IOException
|
URISyntaxException
|
JAXBException
ex
)
{
throw
new
RuntimeException
(
ex
);
}
}
/**
* Get singleton instance.
*
* @return singleton instance
*/
public
static
DataSetAssertLoader
getInstance
()
{
return
INSTANCE
;
}
private
Map
<
String
,
AssertDefinition
>
loadDataSetAssert
()
throws
IOException
,
URISyntaxException
,
JAXBException
{
URL
url
=
DataSetAssertLoader
.
class
.
getClassLoader
().
getResource
(
"asserts/"
);
Preconditions
.
checkNotNull
(
url
,
"Cannot found integrate test cases."
);
List
<
String
>
files
=
getFiles
(
url
);
Preconditions
.
checkNotNull
(
files
,
"Cannot found integrate test cases."
);
Map
<
String
,
AssertDefinition
>
result
=
new
HashMap
<>(
Short
.
MAX_VALUE
,
1
);
for
(
String
each
:
files
)
{
result
.
putAll
(
loadDataSetAssert
(
each
));
}
return
result
;
}
private
Map
<
String
,
AssertDefinition
>
loadDataSetAssert
(
final
String
file
)
throws
IOException
,
JAXBException
{
AssertsDefinition
assertsDefinition
=
unmarshal
(
file
);
Map
<
String
,
AssertDefinition
>
result
=
new
HashMap
<>(
assertsDefinition
.
getAssertDQL
().
size
()
+
assertsDefinition
.
getAssertDML
().
size
()
+
assertsDefinition
.
getAssertDDL
().
size
(),
1
);
shardingRuleTypes
.
addAll
(
Arrays
.
asList
(
assertsDefinition
.
getShardingRuleType
().
split
(
","
)));
result
.
putAll
(
loadDataSetAssert
(
file
,
assertsDefinition
.
getAssertDQL
(),
assertsDefinition
.
getShardingRuleType
(),
assertsDefinition
.
getDatabaseConfig
()));
result
.
putAll
(
loadDataSetAssert
(
file
,
assertsDefinition
.
getAssertDML
(),
assertsDefinition
.
getShardingRuleType
(),
assertsDefinition
.
getDatabaseConfig
()));
result
.
putAll
(
loadDataSetAssert
(
file
,
assertsDefinition
.
getAssertDDL
(),
assertsDefinition
.
getShardingRuleType
(),
assertsDefinition
.
getDatabaseConfig
()));
return
result
;
}
private
Map
<
String
,
AssertDefinition
>
loadDataSetAssert
(
final
String
file
,
final
List
<?
extends
AssertDefinition
>
assertDefinitions
,
final
String
defaultShardingRuleType
,
final
String
defaultDatabaseTypes
)
{
Map
<
String
,
AssertDefinition
>
result
=
new
HashMap
<>(
assertDefinitions
.
size
(),
1
);
for
(
AssertDefinition
each
:
assertDefinitions
)
{
result
.
put
(
each
.
getId
(),
each
);
each
.
setPath
(
file
);
if
(
Strings
.
isNullOrEmpty
(
each
.
getShardingRuleType
()))
{
each
.
setShardingRuleType
(
defaultShardingRuleType
);
}
else
{
shardingRuleTypes
.
addAll
(
Arrays
.
asList
(
each
.
getShardingRuleType
().
split
(
","
)));
}
if
(
Strings
.
isNullOrEmpty
(
each
.
getDatabaseConfig
()))
{
each
.
setDatabaseConfig
(
defaultDatabaseTypes
);
}
}
return
result
;
}
private
static
List
<
String
>
getFiles
(
final
URL
url
)
throws
IOException
,
URISyntaxException
{
final
List
<
String
>
result
=
new
LinkedList
<>();
Files
.
walkFileTree
(
Paths
.
get
(
url
.
toURI
()),
new
SimpleFileVisitor
<
Path
>()
{
@Override
public
FileVisitResult
visitFile
(
final
Path
file
,
final
BasicFileAttributes
basicFileAttributes
)
{
if
(
file
.
getFileName
().
toString
().
startsWith
(
"assert-"
)
&&
file
.
getFileName
().
toString
().
endsWith
(
".xml"
))
{
result
.
add
(
file
.
toFile
().
getPath
());
}
return
FileVisitResult
.
CONTINUE
;
}
});
return
result
;
}
private
static
AssertsDefinition
unmarshal
(
final
String
assertFilePath
)
throws
IOException
,
JAXBException
{
try
(
FileReader
reader
=
new
FileReader
(
assertFilePath
))
{
return
(
AssertsDefinition
)
JAXBContext
.
newInstance
(
AssertsDefinition
.
class
).
createUnmarshaller
().
unmarshal
(
reader
);
}
}
/**
* Get data set assert.
*
* @param sqlCaseId SQL case ID
* @return data set assert
*/
public
AssertDefinition
getDataSetAssert
(
final
String
sqlCaseId
)
{
// TODO resume when transfer finished
// Preconditions.checkState(dataSetAssertMap.containsKey(sqlCaseId), "Can't find SQL of id: " + sqlCaseId);
// TODO remove when transfer finished
if
(!
dataSetAssertMap
.
containsKey
(
sqlCaseId
))
{
log
.
warn
(
"Have not finish case `{}`"
,
sqlCaseId
);
}
return
dataSetAssertMap
.
get
(
sqlCaseId
);
}
}
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertDDLDefinition.java
浏览文件 @
697a2c73
...
...
@@ -20,6 +20,7 @@ package io.shardingjdbc.dbtest.config.bean;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
...
...
@@ -28,9 +29,10 @@ import javax.xml.bind.annotation.XmlElement;
import
java.util.ArrayList
;
import
java.util.List
;
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
AssertDDLDefinition
implements
AssertDefinition
{
...
...
@@ -64,6 +66,8 @@ public class AssertDDLDefinition implements AssertDefinition {
@XmlElement
(
name
=
"subAssert"
)
private
List
<
AssertSubDefinition
>
subAsserts
=
new
ArrayList
<>();
private
String
path
;
@Override
public
String
toString
()
{
return
id
;
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertDMLDefinition.java
浏览文件 @
697a2c73
...
...
@@ -20,6 +20,7 @@ package io.shardingjdbc.dbtest.config.bean;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
...
...
@@ -28,9 +29,10 @@ import javax.xml.bind.annotation.XmlElement;
import
java.util.ArrayList
;
import
java.util.List
;
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
AssertDMLDefinition
implements
AssertDefinition
{
...
...
@@ -64,6 +66,8 @@ public class AssertDMLDefinition implements AssertDefinition {
@XmlElement
(
name
=
"subAssert"
)
private
List
<
AssertSubDefinition
>
subAsserts
=
new
ArrayList
<>();
private
String
path
;
@Override
public
String
toString
()
{
return
id
;
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertDQLDefinition.java
浏览文件 @
697a2c73
...
...
@@ -20,6 +20,7 @@ package io.shardingjdbc.dbtest.config.bean;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
javax.xml.bind.annotation.XmlAccessType
;
import
javax.xml.bind.annotation.XmlAccessorType
;
...
...
@@ -28,9 +29,10 @@ import javax.xml.bind.annotation.XmlElement;
import
java.util.ArrayList
;
import
java.util.List
;
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@XmlAccessorType
(
XmlAccessType
.
FIELD
)
public
class
AssertDQLDefinition
implements
AssertDefinition
{
...
...
@@ -55,6 +57,8 @@ public class AssertDQLDefinition implements AssertDefinition {
@XmlElement
(
name
=
"subAssert"
)
private
List
<
AssertSubDefinition
>
subAsserts
=
new
ArrayList
<>();
private
String
path
;
@Override
public
String
toString
()
{
return
id
;
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/config/bean/AssertDefinition.java
浏览文件 @
697a2c73
...
...
@@ -23,7 +23,15 @@ public interface AssertDefinition {
String
getShardingRuleType
();
void
setShardingRuleType
(
String
shardingRuleTypes
);
String
getDatabaseConfig
();
void
setDatabaseConfig
(
String
databaseTypes
);
String
getSql
();
String
getPath
();
void
setPath
(
String
path
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录