Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
cf2e8b59
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,发现更多精彩内容 >>
提交
cf2e8b59
编写于
3月 28, 2018
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
For #673: add AbstractBaseSQLParsingEngineTest
上级
45a96d0d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
92 addition
and
97 deletion
+92
-97
sharding-core/src/test/java/io/shardingjdbc/core/parsing/AbstractBaseSQLParsingEngineTest.java
...ngjdbc/core/parsing/AbstractBaseSQLParsingEngineTest.java
+64
-0
sharding-core/src/test/java/io/shardingjdbc/core/parsing/ParsingEngineForUnsupportedSQLTest.java
...jdbc/core/parsing/ParsingEngineForUnsupportedSQLTest.java
+2
-38
sharding-core/src/test/java/io/shardingjdbc/core/parsing/SQLParsingEngineTest.java
...va/io/shardingjdbc/core/parsing/SQLParsingEngineTest.java
+5
-36
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/integrate/jaxb/helper/SQLAssertJAXBHelper.java
...gjdbc/core/integrate/jaxb/helper/SQLAssertJAXBHelper.java
+16
-14
sharding-sql-test/src/main/java/io/shardingjdbc/test/sql/SQLCasesLoader.java
...rc/main/java/io/shardingjdbc/test/sql/SQLCasesLoader.java
+5
-9
未找到文件。
sharding-core/src/test/java/io/shardingjdbc/core/parsing/AbstractBaseSQLParsingEngineTest.java
0 → 100644
浏览文件 @
cf2e8b59
/*
* 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.core.parsing
;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Strings
;
import
com.google.common.collect.Sets
;
import
io.shardingjdbc.core.constant.DatabaseType
;
import
io.shardingjdbc.core.rule.ShardingRule
;
import
io.shardingjdbc.core.yaml.sharding.YamlShardingConfiguration
;
import
lombok.AccessLevel
;
import
lombok.Getter
;
import
org.junit.BeforeClass
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
java.util.Set
;
public
abstract
class
AbstractBaseSQLParsingEngineTest
{
@Getter
(
AccessLevel
.
PROTECTED
)
private
static
ShardingRule
shardingRule
;
@BeforeClass
public
static
void
setUp
()
throws
IOException
{
shardingRule
=
buildShardingRule
();
}
private
static
ShardingRule
buildShardingRule
()
throws
IOException
{
URL
url
=
SQLParsingEngineTest
.
class
.
getClassLoader
().
getResource
(
"yaml/parser-rule.yaml"
);
Preconditions
.
checkNotNull
(
url
,
"Cannot found parser rule yaml configuration."
);
YamlShardingConfiguration
yamlShardingConfig
=
YamlShardingConfiguration
.
unmarshal
(
new
File
(
url
.
getFile
()));
return
yamlShardingConfig
.
getShardingRule
(
yamlShardingConfig
.
getDataSources
().
keySet
());
}
protected
static
Collection
<
DatabaseType
>
getDatabaseTypes
(
final
String
databaseTypes
)
{
if
(
Strings
.
isNullOrEmpty
(
databaseTypes
))
{
return
Sets
.
newHashSet
(
DatabaseType
.
values
());
}
Set
<
DatabaseType
>
result
=
new
HashSet
<>();
for
(
String
each
:
databaseTypes
.
split
(
","
))
{
result
.
add
(
DatabaseType
.
valueOf
(
each
));
}
return
result
;
}
}
sharding-core/src/test/java/io/shardingjdbc/core/parsing/ParsingEngineForUnsupportedSQLTest.java
浏览文件 @
cf2e8b59
...
...
@@ -17,53 +17,28 @@
package
io.shardingjdbc.core.parsing
;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Strings
;
import
com.google.common.collect.Sets
;
import
io.shardingjdbc.core.constant.DatabaseType
;
import
io.shardingjdbc.core.parsing.parser.exception.SQLParsingUnsupportedException
;
import
io.shardingjdbc.core.rule.ShardingRule
;
import
io.shardingjdbc.core.yaml.sharding.YamlShardingConfiguration
;
import
io.shardingjdbc.test.sql.SQLCase
;
import
io.shardingjdbc.test.sql.SQLCasesLoader
;
import
lombok.AllArgsConstructor
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Parameterized
;
import
org.junit.runners.Parameterized.Parameters
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
java.util.LinkedList
;
import
java.util.Set
;
@AllArgsConstructor
@RunWith
(
Parameterized
.
class
)
public
final
class
ParsingEngineForUnsupportedSQLTest
{
private
static
ShardingRule
shardingRule
;
public
final
class
ParsingEngineForUnsupportedSQLTest
extends
AbstractBaseSQLParsingEngineTest
{
private
String
testCaseName
;
private
DatabaseType
databaseType
;
@BeforeClass
public
static
void
setUp
()
throws
IOException
{
shardingRule
=
buildShardingRule
();
}
private
static
ShardingRule
buildShardingRule
()
throws
IOException
{
URL
url
=
SQLParsingEngineTest
.
class
.
getClassLoader
().
getResource
(
"yaml/parser-rule.yaml"
);
Preconditions
.
checkNotNull
(
url
,
"Cannot found parser rule yaml configuration."
);
YamlShardingConfiguration
yamlShardingConfig
=
YamlShardingConfiguration
.
unmarshal
(
new
File
(
url
.
getFile
()));
return
yamlShardingConfig
.
getShardingRule
(
yamlShardingConfig
.
getDataSources
().
keySet
());
}
@Parameters
(
name
=
"{0}In{1}"
)
public
static
Collection
<
Object
[]>
getTestParameters
()
{
Collection
<
Object
[]>
result
=
new
ArrayList
<>();
...
...
@@ -84,19 +59,8 @@ public final class ParsingEngineForUnsupportedSQLTest {
return
result
;
}
private
static
Set
<
DatabaseType
>
getDatabaseTypes
(
final
String
databaseTypes
)
{
if
(
Strings
.
isNullOrEmpty
(
databaseTypes
))
{
return
Sets
.
newHashSet
(
DatabaseType
.
values
());
}
Set
<
DatabaseType
>
result
=
new
HashSet
<>();
for
(
String
each
:
databaseTypes
.
split
(
","
))
{
result
.
add
(
DatabaseType
.
valueOf
(
each
));
}
return
result
;
}
@Test
(
expected
=
SQLParsingUnsupportedException
.
class
)
public
void
assertUnsupportedSQL
()
{
new
SQLParsingEngine
(
databaseType
,
SQLCasesLoader
.
getInstance
().
getUnsupportedSQL
(
testCaseName
),
shardingRule
).
parse
();
new
SQLParsingEngine
(
databaseType
,
SQLCasesLoader
.
getInstance
().
getUnsupportedSQL
(
testCaseName
),
getShardingRule
()
).
parse
();
}
}
sharding-core/src/test/java/io/shardingjdbc/core/parsing/SQLParsingEngineTest.java
浏览文件 @
cf2e8b59
...
...
@@ -25,12 +25,9 @@ import io.shardingjdbc.core.parsing.parser.jaxb.helper.ParserAssertHelper;
import
io.shardingjdbc.core.parsing.parser.jaxb.helper.ParserJAXBHelper
;
import
io.shardingjdbc.core.parsing.parser.sql.SQLStatement
;
import
io.shardingjdbc.core.parsing.parser.sql.dql.select.SelectStatement
;
import
io.shardingjdbc.core.rule.ShardingRule
;
import
io.shardingjdbc.core.util.SQLPlaceholderUtil
;
import
io.shardingjdbc.core.yaml.sharding.YamlShardingConfiguration
;
import
io.shardingjdbc.test.sql.SQLCasesLoader
;
import
lombok.RequiredArgsConstructor
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Parameterized
;
...
...
@@ -39,19 +36,14 @@ import org.junit.runners.Parameterized.Parameters;
import
javax.xml.bind.JAXBContext
;
import
javax.xml.bind.JAXBException
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.LinkedHashSet
;
import
java.util.LinkedList
;
import
java.util.List
;
@RequiredArgsConstructor
@RunWith
(
Parameterized
.
class
)
public
final
class
SQLParsingEngineTest
{
private
static
ShardingRule
shardingRule
;
public
final
class
SQLParsingEngineTest
extends
AbstractBaseSQLParsingEngineTest
{
private
final
String
testCaseName
;
...
...
@@ -59,18 +51,6 @@ public final class SQLParsingEngineTest {
private
final
Assert
assertObj
;
@BeforeClass
public
static
void
setUp
()
throws
IOException
{
shardingRule
=
buildShardingRule
();
}
private
static
ShardingRule
buildShardingRule
()
throws
IOException
{
URL
url
=
SQLParsingEngineTest
.
class
.
getClassLoader
().
getResource
(
"yaml/parser-rule.yaml"
);
Preconditions
.
checkNotNull
(
url
,
"Cannot found parser rule yaml configuration."
);
YamlShardingConfiguration
yamlShardingConfig
=
YamlShardingConfiguration
.
unmarshal
(
new
File
(
url
.
getFile
()));
return
yamlShardingConfig
.
getShardingRule
(
yamlShardingConfig
.
getDataSources
().
keySet
());
}
@Parameters
(
name
=
"{0}In{1}"
)
public
static
Collection
<
Object
[]>
getTestParameters
()
throws
JAXBException
{
Collection
<
Object
[]>
result
=
new
LinkedList
<>();
...
...
@@ -94,7 +74,7 @@ public final class SQLParsingEngineTest {
private
static
List
<
Object
[]>
getTestParameters
(
final
Assert
assertObj
)
{
List
<
Object
[]>
result
=
new
LinkedList
<>();
for
(
DatabaseType
each
:
getData
B
aseTypes
(
SQLCasesLoader
.
getInstance
().
getDatabaseTypes
(
assertObj
.
getId
())))
{
for
(
DatabaseType
each
:
getData
b
aseTypes
(
SQLCasesLoader
.
getInstance
().
getDatabaseTypes
(
assertObj
.
getId
())))
{
result
.
add
(
getTestParameters
(
assertObj
,
each
));
}
return
result
;
...
...
@@ -108,27 +88,16 @@ public final class SQLParsingEngineTest {
return
result
;
}
private
static
Collection
<
DatabaseType
>
getDataBaseTypes
(
final
Collection
<
String
>
databaseTypes
)
{
if
(
databaseTypes
.
isEmpty
())
{
return
Arrays
.
asList
(
DatabaseType
.
values
());
}
Collection
<
DatabaseType
>
result
=
new
LinkedHashSet
<>(
databaseTypes
.
size
());
for
(
String
each
:
databaseTypes
)
{
result
.
add
(
DatabaseType
.
valueOf
(
each
));
}
return
result
;
}
@Test
public
void
assertLiteralSQL
()
{
assertSQLStatement
(
new
SQLParsingEngine
(
databaseType
,
SQLPlaceholderUtil
.
replaceStatement
(
SQLCasesLoader
.
getInstance
().
getSQL
(
testCaseName
),
ParserJAXBHelper
.
getParameters
(
assertObj
.
getParameters
())),
shardingRule
).
parse
(),
false
);
SQLCasesLoader
.
getInstance
().
getSQL
(
testCaseName
),
ParserJAXBHelper
.
getParameters
(
assertObj
.
getParameters
())),
getShardingRule
()
).
parse
(),
false
);
}
@Test
public
void
assertPlaceholderSQL
()
{
for
(
DatabaseType
each
:
getData
B
aseTypes
(
SQLCasesLoader
.
getInstance
().
getDatabaseTypes
(
testCaseName
)))
{
assertSQLStatement
(
new
SQLParsingEngine
(
each
,
SQLPlaceholderUtil
.
replacePreparedStatement
(
SQLCasesLoader
.
getInstance
().
getSQL
(
testCaseName
)),
shardingRule
).
parse
(),
true
);
for
(
DatabaseType
each
:
getData
b
aseTypes
(
SQLCasesLoader
.
getInstance
().
getDatabaseTypes
(
testCaseName
)))
{
assertSQLStatement
(
new
SQLParsingEngine
(
each
,
SQLPlaceholderUtil
.
replacePreparedStatement
(
SQLCasesLoader
.
getInstance
().
getSQL
(
testCaseName
)),
getShardingRule
()
).
parse
(),
true
);
}
}
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/core/integrate/jaxb/helper/SQLAssertJAXBHelper.java
浏览文件 @
cf2e8b59
...
...
@@ -17,6 +17,8 @@
package
io.shardingjdbc.core.integrate.jaxb.helper
;
import
com.google.common.base.Strings
;
import
com.google.common.collect.Sets
;
import
io.shardingjdbc.core.constant.DatabaseType
;
import
io.shardingjdbc.core.constant.SQLType
;
import
io.shardingjdbc.core.integrate.jaxb.SQLAssert
;
...
...
@@ -28,11 +30,11 @@ import javax.xml.bind.JAXBException;
import
java.io.File
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.
Linked
HashSet
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
public
final
class
SQLAssertJAXBHelper
{
...
...
@@ -80,7 +82,7 @@ public final class SQLAssertJAXBHelper {
List
<
Object
[]>
result
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
asserts
.
getSqlAsserts
().
size
();
i
++)
{
SQLAssert
assertObj
=
asserts
.
getSqlAsserts
().
get
(
i
);
for
(
DatabaseType
each
:
getData
B
aseTypes
(
SQLCasesLoader
.
getInstance
().
getDatabaseTypes
(
assertObj
.
getId
())))
{
for
(
DatabaseType
each
:
getData
b
aseTypes
(
SQLCasesLoader
.
getInstance
().
getDatabaseTypes
(
assertObj
.
getId
())))
{
result
.
add
(
getDataParameter
(
assertObj
,
each
));
}
}
...
...
@@ -95,17 +97,6 @@ public final class SQLAssertJAXBHelper {
}
}
private
static
Collection
<
DatabaseType
>
getDataBaseTypes
(
final
Collection
<
String
>
databaseTypes
)
{
if
(
databaseTypes
.
isEmpty
())
{
return
Arrays
.
asList
(
DatabaseType
.
values
());
}
Collection
<
DatabaseType
>
result
=
new
LinkedHashSet
<>(
databaseTypes
.
size
());
for
(
String
each
:
databaseTypes
)
{
result
.
add
(
DatabaseType
.
valueOf
(
each
));
}
return
result
;
}
private
static
Object
[]
getDataParameter
(
final
SQLAssert
sqlAssert
,
final
DatabaseType
dbType
)
{
final
Object
[]
result
=
new
Object
[
4
];
result
[
0
]
=
sqlAssert
.
getId
();
...
...
@@ -126,4 +117,15 @@ public final class SQLAssertJAXBHelper {
default
:
return
false
;
}
}
private
static
Collection
<
DatabaseType
>
getDatabaseTypes
(
final
String
databaseTypes
)
{
if
(
Strings
.
isNullOrEmpty
(
databaseTypes
))
{
return
Sets
.
newHashSet
(
DatabaseType
.
values
());
}
Set
<
DatabaseType
>
result
=
new
HashSet
<>();
for
(
String
each
:
databaseTypes
.
split
(
","
))
{
result
.
add
(
DatabaseType
.
valueOf
(
each
));
}
return
result
;
}
}
sharding-sql-test/src/main/java/io/shardingjdbc/test/sql/SQLCasesLoader.java
浏览文件 @
cf2e8b59
...
...
@@ -18,8 +18,6 @@
package
io.shardingjdbc.test.sql
;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Splitter
;
import
com.google.common.base.Strings
;
import
javax.xml.bind.JAXBContext
;
import
javax.xml.bind.JAXBException
;
...
...
@@ -30,10 +28,9 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarFile
;
...
...
@@ -74,7 +71,7 @@ public final class SQLCasesLoader {
}
private
static
Map
<
String
,
SQLCase
>
loadSQLCasesFromJar
(
final
String
path
,
final
File
file
)
throws
IOException
,
JAXBException
{
Map
<
String
,
SQLCase
>
result
=
new
HashMap
<>(
65536
,
1
);
Map
<
String
,
SQLCase
>
result
=
new
TreeMap
<>(
);
try
(
JarFile
jar
=
new
JarFile
(
file
))
{
Enumeration
<
JarEntry
>
entries
=
jar
.
entries
();
while
(
entries
.
hasMoreElements
())
{
...
...
@@ -88,7 +85,7 @@ public final class SQLCasesLoader {
}
private
static
Map
<
String
,
SQLCase
>
loadSQLCasesFromTargetDirectory
(
final
String
path
)
throws
FileNotFoundException
,
JAXBException
{
Map
<
String
,
SQLCase
>
result
=
new
HashMap
<>(
65536
,
1
);
Map
<
String
,
SQLCase
>
result
=
new
TreeMap
<>(
);
URL
url
=
SQLCasesLoader
.
class
.
getClassLoader
().
getResource
(
path
);
if
(
null
==
url
)
{
return
result
;
...
...
@@ -176,9 +173,8 @@ public final class SQLCasesLoader {
* @param id SQL ID
* @return database types
*/
public
Collection
<
String
>
getDatabaseTypes
(
final
String
id
)
{
public
String
getDatabaseTypes
(
final
String
id
)
{
Preconditions
.
checkState
(
sqlCaseMap
.
containsKey
(
id
),
"Can't find SQL of id: "
+
id
);
String
databaseTypes
=
sqlCaseMap
.
get
(
id
).
getDatabaseTypes
();
return
Strings
.
isNullOrEmpty
(
databaseTypes
)
?
Collections
.<
String
>
emptyList
()
:
Splitter
.
on
(
','
).
trimResults
().
splitToList
(
databaseTypes
);
return
sqlCaseMap
.
get
(
id
).
getDatabaseTypes
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录