Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
a084e43f
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,发现更多精彩内容 >>
提交
a084e43f
编写于
4月 02, 2018
作者:
T
tuohai666
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test cases for ShowOtherMergedResult and ShowTablesMergedResult
上级
f3fd211f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
477 addition
and
0 deletion
+477
-0
sharding-core/src/test/java/io/shardingjdbc/core/merger/dal/show/ShowOtherMergedResultTest.java
...gjdbc/core/merger/dal/show/ShowOtherMergedResultTest.java
+400
-0
sharding-core/src/test/java/io/shardingjdbc/core/merger/dal/show/ShowTablesMergedResultTest.java
...jdbc/core/merger/dal/show/ShowTablesMergedResultTest.java
+77
-0
未找到文件。
sharding-core/src/test/java/io/shardingjdbc/core/merger/dal/show/ShowOtherMergedResultTest.java
0 → 100644
浏览文件 @
a084e43f
package
io.shardingjdbc.core.merger.dal.show
;
import
io.shardingjdbc.core.merger.fixture.TestQueryResult
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
java.io.InputStream
;
import
java.io.Reader
;
import
java.math.BigDecimal
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.sql.Blob
;
import
java.sql.Clob
;
import
java.sql.Date
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLFeatureNotSupportedException
;
import
java.sql.SQLXML
;
import
java.sql.Time
;
import
java.sql.Timestamp
;
import
java.util.Calendar
;
import
java.util.Collection
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
final
class
ShowOtherMergedResultTest
{
@Mock
private
ResultSet
resultSet
;
private
ShowOtherMergedResult
showOtherMergedResult
;
@Before
public
void
setUp
()
{
showOtherMergedResult
=
new
ShowOtherMergedResult
(
new
TestQueryResult
(
resultSet
));
}
@Test
public
void
assertNext
()
throws
SQLException
{
when
(
resultSet
.
next
()).
thenReturn
(
true
,
false
);
assertThat
(
showOtherMergedResult
.
next
(),
is
(
true
));
assertThat
(
showOtherMergedResult
.
next
(),
is
(
false
));
}
@Test
public
void
assertGetValueWithColumnIndexWithObject
()
throws
SQLException
{
when
(
resultSet
.
getObject
(
1
)).
thenReturn
(
"1"
);
assertThat
(
showOtherMergedResult
.
getValue
(
1
,
Object
.
class
).
toString
(),
is
(
"1"
));
}
@Test
public
void
assertGetValueWithColumnIndexWithBoolean
()
throws
SQLException
{
when
(
resultSet
.
getBoolean
(
1
)).
thenReturn
(
true
);
assertTrue
((
Boolean
)
showOtherMergedResult
.
getValue
(
1
,
boolean
.
class
));
}
@Test
public
void
assertGetValueWithColumnIndexWithByte
()
throws
SQLException
{
when
(
resultSet
.
getByte
(
1
)).
thenReturn
((
byte
)
1
);
assertThat
((
byte
)
showOtherMergedResult
.
getValue
(
1
,
byte
.
class
),
is
((
byte
)
1
));
}
@Test
public
void
assertGetValueWithColumnIndexWithShort
()
throws
SQLException
{
when
(
resultSet
.
getShort
(
1
)).
thenReturn
((
short
)
1
);
assertThat
((
short
)
showOtherMergedResult
.
getValue
(
1
,
short
.
class
),
is
((
short
)
1
));
}
@Test
public
void
assertGetValueWithColumnIndexWithInt
()
throws
SQLException
{
when
(
resultSet
.
getInt
(
1
)).
thenReturn
(
1
);
assertThat
((
int
)
showOtherMergedResult
.
getValue
(
1
,
int
.
class
),
is
(
1
));
}
@Test
public
void
assertGetValueWithColumnIndexWithLong
()
throws
SQLException
{
when
(
resultSet
.
getLong
(
1
)).
thenReturn
(
1L
);
assertThat
((
long
)
showOtherMergedResult
.
getValue
(
1
,
long
.
class
),
is
(
1L
));
}
@Test
public
void
assertGetValueWithColumnIndexWithFloat
()
throws
SQLException
{
when
(
resultSet
.
getFloat
(
1
)).
thenReturn
(
1
F
);
assertThat
((
float
)
showOtherMergedResult
.
getValue
(
1
,
float
.
class
),
is
(
1
F
));
}
@Test
public
void
assertGetValueWithColumnIndexWithDouble
()
throws
SQLException
{
when
(
resultSet
.
getDouble
(
1
)).
thenReturn
(
1
D
);
assertThat
((
double
)
showOtherMergedResult
.
getValue
(
1
,
double
.
class
),
is
(
1
D
));
}
@Test
public
void
assertGetValueWithColumnIndexWithString
()
throws
SQLException
{
when
(
resultSet
.
getString
(
1
)).
thenReturn
(
"1"
);
assertThat
((
String
)
showOtherMergedResult
.
getValue
(
1
,
String
.
class
),
is
(
"1"
));
}
@Test
public
void
assertGetValueWithColumnIndexWithBigDecimal
()
throws
SQLException
{
when
(
resultSet
.
getBigDecimal
(
1
)).
thenReturn
(
new
BigDecimal
(
"1"
));
assertThat
((
BigDecimal
)
showOtherMergedResult
.
getValue
(
1
,
BigDecimal
.
class
),
is
(
new
BigDecimal
(
"1"
)));
}
@Test
public
void
assertGetValueWithColumnIndexWithByteArray
()
throws
SQLException
{
when
(
resultSet
.
getBytes
(
1
)).
thenReturn
(
new
byte
[]
{(
byte
)
1
});
assertThat
((
byte
[])
showOtherMergedResult
.
getValue
(
1
,
byte
[].
class
),
is
(
new
byte
[]
{(
byte
)
1
}));
}
@Test
public
void
assertGetValueWithColumnIndexWithDate
()
throws
SQLException
{
when
(
resultSet
.
getDate
(
1
)).
thenReturn
(
new
Date
(
0L
));
assertThat
((
Date
)
showOtherMergedResult
.
getValue
(
1
,
Date
.
class
),
is
(
new
Date
(
0L
)));
}
@Test
public
void
assertGetValueWithColumnIndexWithTime
()
throws
SQLException
{
when
(
resultSet
.
getTime
(
1
)).
thenReturn
(
new
Time
(
0L
));
assertThat
((
Time
)
showOtherMergedResult
.
getValue
(
1
,
Time
.
class
),
is
(
new
Time
(
0L
)));
}
@Test
public
void
assertGetValueWithColumnIndexWithTimestamp
()
throws
SQLException
{
when
(
resultSet
.
getTimestamp
(
1
)).
thenReturn
(
new
Timestamp
(
0L
));
assertThat
((
Timestamp
)
showOtherMergedResult
.
getValue
(
1
,
Timestamp
.
class
),
is
(
new
Timestamp
(
0L
)));
}
@Test
public
void
assertGetValueWithColumnIndexWithURL
()
throws
SQLException
,
MalformedURLException
{
when
(
resultSet
.
getURL
(
1
)).
thenReturn
(
new
URL
(
"http://xxx.xxx"
));
assertThat
((
URL
)
showOtherMergedResult
.
getValue
(
1
,
URL
.
class
),
is
(
new
URL
(
"http://xxx.xxx"
)));
}
@Test
public
void
assertGetValueWithColumnIndexWithBlob
()
throws
SQLException
{
Blob
blob
=
mock
(
Blob
.
class
);
when
(
resultSet
.
getBlob
(
1
)).
thenReturn
(
blob
);
assertThat
((
Blob
)
showOtherMergedResult
.
getValue
(
1
,
Blob
.
class
),
is
(
blob
));
}
@Test
public
void
assertGetValueWithColumnIndexWithClob
()
throws
SQLException
{
Clob
clob
=
mock
(
Clob
.
class
);
when
(
resultSet
.
getClob
(
1
)).
thenReturn
(
clob
);
assertThat
((
Clob
)
showOtherMergedResult
.
getValue
(
1
,
Clob
.
class
),
is
(
clob
));
}
@Test
public
void
assertGetValueWithColumnIndexWithSQLXML
()
throws
SQLException
{
SQLXML
sqlxml
=
mock
(
SQLXML
.
class
);
when
(
resultSet
.
getSQLXML
(
1
)).
thenReturn
(
sqlxml
);
assertThat
((
SQLXML
)
showOtherMergedResult
.
getValue
(
1
,
SQLXML
.
class
),
is
(
sqlxml
));
}
@Test
public
void
assertGetValueWithColumnIndexWithReader
()
throws
SQLException
{
Reader
reader
=
mock
(
Reader
.
class
);
when
(
resultSet
.
getCharacterStream
(
1
)).
thenReturn
(
reader
);
assertThat
((
Reader
)
showOtherMergedResult
.
getValue
(
1
,
Reader
.
class
),
is
(
reader
));
}
@Test
public
void
assertGetValueWithColumnIndexWithOtherObject
()
throws
SQLException
{
when
(
resultSet
.
getObject
(
1
)).
thenReturn
(
"1"
);
assertThat
((
String
)
showOtherMergedResult
.
getValue
(
1
,
Collection
.
class
),
is
(
"1"
));
}
@Test
public
void
assertGetValueWithColumnLabelWithObject
()
throws
SQLException
{
when
(
resultSet
.
getObject
(
"label"
)).
thenReturn
(
"1"
);
assertThat
(
showOtherMergedResult
.
getValue
(
"label"
,
Object
.
class
).
toString
(),
is
(
"1"
));
}
@Test
public
void
assertGetValueWithColumnLabelWithBoolean
()
throws
SQLException
{
when
(
resultSet
.
getBoolean
(
"label"
)).
thenReturn
(
true
);
assertTrue
((
Boolean
)
showOtherMergedResult
.
getValue
(
"label"
,
boolean
.
class
));
}
@Test
public
void
assertGetValueWithColumnLabelWithByte
()
throws
SQLException
{
when
(
resultSet
.
getByte
(
"label"
)).
thenReturn
((
byte
)
1
);
assertThat
((
byte
)
showOtherMergedResult
.
getValue
(
"label"
,
byte
.
class
),
is
((
byte
)
1
));
}
@Test
public
void
assertGetValueWithColumnLabelWithShort
()
throws
SQLException
{
when
(
resultSet
.
getShort
(
"label"
)).
thenReturn
((
short
)
1
);
assertThat
((
short
)
showOtherMergedResult
.
getValue
(
"label"
,
short
.
class
),
is
((
short
)
1
));
}
@Test
public
void
assertGetValueWithColumnLabelWithInt
()
throws
SQLException
{
when
(
resultSet
.
getInt
(
"label"
)).
thenReturn
(
1
);
assertThat
((
int
)
showOtherMergedResult
.
getValue
(
"label"
,
int
.
class
),
is
(
1
));
}
@Test
public
void
assertGetValueWithColumnLabelWithLong
()
throws
SQLException
{
when
(
resultSet
.
getLong
(
"label"
)).
thenReturn
(
1L
);
assertThat
((
long
)
showOtherMergedResult
.
getValue
(
"label"
,
long
.
class
),
is
(
1L
));
}
@Test
public
void
assertGetValueWithColumnLabelWithFloat
()
throws
SQLException
{
when
(
resultSet
.
getFloat
(
"label"
)).
thenReturn
(
1
F
);
assertThat
((
float
)
showOtherMergedResult
.
getValue
(
"label"
,
float
.
class
),
is
(
1
F
));
}
@Test
public
void
assertGetValueWithColumnLabelWithDouble
()
throws
SQLException
{
when
(
resultSet
.
getDouble
(
"label"
)).
thenReturn
(
1
D
);
assertThat
((
double
)
showOtherMergedResult
.
getValue
(
"label"
,
double
.
class
),
is
(
1
D
));
}
@Test
public
void
assertGetValueWithColumnLabelWithString
()
throws
SQLException
{
when
(
resultSet
.
getString
(
"label"
)).
thenReturn
(
"1"
);
assertThat
((
String
)
showOtherMergedResult
.
getValue
(
"label"
,
String
.
class
),
is
(
"1"
));
}
@Test
public
void
assertGetValueWithColumnLabelWithBigDecimal
()
throws
SQLException
{
when
(
resultSet
.
getBigDecimal
(
"label"
)).
thenReturn
(
new
BigDecimal
(
"1"
));
assertThat
((
BigDecimal
)
showOtherMergedResult
.
getValue
(
"label"
,
BigDecimal
.
class
),
is
(
new
BigDecimal
(
"1"
)));
}
@Test
public
void
assertGetValueWithColumnLabelWithByteArray
()
throws
SQLException
{
when
(
resultSet
.
getBytes
(
"label"
)).
thenReturn
(
new
byte
[]
{(
byte
)
1
});
assertThat
((
byte
[])
showOtherMergedResult
.
getValue
(
"label"
,
byte
[].
class
),
is
(
new
byte
[]
{(
byte
)
1
}));
}
@Test
public
void
assertGetValueWithColumnLabelWithDate
()
throws
SQLException
{
when
(
resultSet
.
getDate
(
"label"
)).
thenReturn
(
new
Date
(
0L
));
assertThat
((
Date
)
showOtherMergedResult
.
getValue
(
"label"
,
Date
.
class
),
is
(
new
Date
(
0L
)));
}
@Test
public
void
assertGetValueWithColumnLabelWithTime
()
throws
SQLException
{
when
(
resultSet
.
getTime
(
"label"
)).
thenReturn
(
new
Time
(
0L
));
assertThat
((
Time
)
showOtherMergedResult
.
getValue
(
"label"
,
Time
.
class
),
is
(
new
Time
(
0L
)));
}
@Test
public
void
assertGetValueWithColumnLabelWithTimestamp
()
throws
SQLException
{
when
(
resultSet
.
getTimestamp
(
"label"
)).
thenReturn
(
new
Timestamp
(
0L
));
assertThat
((
Timestamp
)
showOtherMergedResult
.
getValue
(
"label"
,
Timestamp
.
class
),
is
(
new
Timestamp
(
0L
)));
}
@Test
public
void
assertGetValueWithColumnLabelWithURL
()
throws
SQLException
,
MalformedURLException
{
when
(
resultSet
.
getURL
(
"label"
)).
thenReturn
(
new
URL
(
"http://xxx.xxx"
));
assertThat
((
URL
)
showOtherMergedResult
.
getValue
(
"label"
,
URL
.
class
),
is
(
new
URL
(
"http://xxx.xxx"
)));
}
@Test
public
void
assertGetValueWithColumnLabelWithBlob
()
throws
SQLException
{
Blob
blob
=
mock
(
Blob
.
class
);
when
(
resultSet
.
getBlob
(
"label"
)).
thenReturn
(
blob
);
assertThat
((
Blob
)
showOtherMergedResult
.
getValue
(
"label"
,
Blob
.
class
),
is
(
blob
));
}
@Test
public
void
assertGetValueWithColumnLabelWithClob
()
throws
SQLException
{
Clob
clob
=
mock
(
Clob
.
class
);
when
(
resultSet
.
getClob
(
"label"
)).
thenReturn
(
clob
);
assertThat
((
Clob
)
showOtherMergedResult
.
getValue
(
"label"
,
Clob
.
class
),
is
(
clob
));
}
@Test
public
void
assertGetValueWithColumnLabelWithSQLXML
()
throws
SQLException
{
SQLXML
sqlxml
=
mock
(
SQLXML
.
class
);
when
(
resultSet
.
getSQLXML
(
"label"
)).
thenReturn
(
sqlxml
);
assertThat
((
SQLXML
)
showOtherMergedResult
.
getValue
(
"label"
,
SQLXML
.
class
),
is
(
sqlxml
));
}
@Test
public
void
assertGetValueWithColumnLabelWithReader
()
throws
SQLException
{
Reader
reader
=
mock
(
Reader
.
class
);
when
(
resultSet
.
getCharacterStream
(
"label"
)).
thenReturn
(
reader
);
assertThat
((
Reader
)
showOtherMergedResult
.
getValue
(
"label"
,
Reader
.
class
),
is
(
reader
));
}
@Test
public
void
assertGetValueWithColumnLabelWithOtherObject
()
throws
SQLException
{
when
(
resultSet
.
getObject
(
"label"
)).
thenReturn
(
"1"
);
assertThat
((
String
)
showOtherMergedResult
.
getValue
(
"label"
,
Collection
.
class
),
is
(
"1"
));
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
assertGetCalendarValueWithColumnIndexWithDate
()
throws
SQLException
{
Calendar
calendar
=
Calendar
.
getInstance
();
assertThat
((
Date
)
showOtherMergedResult
.
getCalendarValue
(
1
,
Date
.
class
,
calendar
),
is
(
new
Date
(
0L
)));
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
assertGetCalendarValueWithColumnIndexWithTime
()
throws
SQLException
{
Calendar
calendar
=
Calendar
.
getInstance
();
assertThat
((
Time
)
showOtherMergedResult
.
getCalendarValue
(
1
,
Time
.
class
,
calendar
),
is
(
new
Time
(
0L
)));
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
assertGetCalendarValueWithColumnIndexWithTimestamp
()
throws
SQLException
{
Calendar
calendar
=
Calendar
.
getInstance
();
assertThat
((
Timestamp
)
showOtherMergedResult
.
getCalendarValue
(
1
,
Timestamp
.
class
,
calendar
),
is
(
new
Timestamp
(
0L
)));
}
@Test
(
expected
=
SQLException
.
class
)
public
void
assertGetCalendarValueWithColumnIndexWithInvalidType
()
throws
SQLException
{
showOtherMergedResult
.
getCalendarValue
(
1
,
Object
.
class
,
Calendar
.
getInstance
());
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
assertGetCalendarValueWithColumnLabelWithDate
()
throws
SQLException
{
Calendar
calendar
=
Calendar
.
getInstance
();
assertThat
((
Date
)
showOtherMergedResult
.
getCalendarValue
(
"label"
,
Date
.
class
,
calendar
),
is
(
new
Date
(
0L
)));
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
assertGetCalendarValueWithColumnLabelWithTime
()
throws
SQLException
{
Calendar
calendar
=
Calendar
.
getInstance
();
assertThat
((
Time
)
showOtherMergedResult
.
getCalendarValue
(
"label"
,
Time
.
class
,
calendar
),
is
(
new
Time
(
0L
)));
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
assertGetCalendarValueWithColumnLabelWithTimestamp
()
throws
SQLException
{
Calendar
calendar
=
Calendar
.
getInstance
();
assertThat
((
Timestamp
)
showOtherMergedResult
.
getCalendarValue
(
"label"
,
Timestamp
.
class
,
calendar
),
is
(
new
Timestamp
(
0L
)));
}
@Test
(
expected
=
SQLException
.
class
)
public
void
assertGetCalendarValueWithColumnLabelWithInvalidType
()
throws
SQLException
{
showOtherMergedResult
.
getCalendarValue
(
"label"
,
Object
.
class
,
Calendar
.
getInstance
());
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
assertGetInputStreamWithColumnIndexWithAscii
()
throws
SQLException
{
InputStream
inputStream
=
mock
(
InputStream
.
class
);
assertThat
(
showOtherMergedResult
.
getInputStream
(
1
,
"Ascii"
),
is
(
inputStream
));
}
@SuppressWarnings
(
"deprecation"
)
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
assertGetInputStreamWithColumnIndexWithUnicode
()
throws
SQLException
{
InputStream
inputStream
=
mock
(
InputStream
.
class
);
assertThat
(
showOtherMergedResult
.
getInputStream
(
1
,
"Unicode"
),
is
(
inputStream
));
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
assertGetInputStreamWithColumnIndexWithBinary
()
throws
SQLException
{
InputStream
inputStream
=
mock
(
InputStream
.
class
);
assertThat
(
showOtherMergedResult
.
getInputStream
(
1
,
"Binary"
),
is
(
inputStream
));
}
@Test
(
expected
=
SQLException
.
class
)
public
void
assertGetInputStreamWithColumnIndexWithInvalidType
()
throws
SQLException
{
showOtherMergedResult
.
getInputStream
(
1
,
"Invalid"
);
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
assertGetInputStreamWithColumnLabelWithAscii
()
throws
SQLException
{
InputStream
inputStream
=
mock
(
InputStream
.
class
);
assertThat
(
showOtherMergedResult
.
getInputStream
(
"label"
,
"Ascii"
),
is
(
inputStream
));
}
@SuppressWarnings
(
"deprecation"
)
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
assertGetInputStreamWithColumnLabelWithUnicode
()
throws
SQLException
{
InputStream
inputStream
=
mock
(
InputStream
.
class
);
assertThat
(
showOtherMergedResult
.
getInputStream
(
"label"
,
"Unicode"
),
is
(
inputStream
));
}
@Test
(
expected
=
SQLFeatureNotSupportedException
.
class
)
public
void
assertGetInputStreamWithColumnLabelWithBinary
()
throws
SQLException
{
InputStream
inputStream
=
mock
(
InputStream
.
class
);
assertThat
(
showOtherMergedResult
.
getInputStream
(
"label"
,
"Binary"
),
is
(
inputStream
));
}
@Test
(
expected
=
SQLException
.
class
)
public
void
assertGetInputStreamWithColumnLabelWithInvalidType
()
throws
SQLException
{
showOtherMergedResult
.
getInputStream
(
"label"
,
"Invalid"
);
}
@Test
public
void
assertWasNull
()
{
assertFalse
(
showOtherMergedResult
.
wasNull
());
}
}
\ No newline at end of file
sharding-core/src/test/java/io/shardingjdbc/core/merger/dal/show/ShowTablesMergedResultTest.java
0 → 100644
浏览文件 @
a084e43f
package
io.shardingjdbc.core.merger.dal.show
;
import
com.google.common.collect.Lists
;
import
io.shardingjdbc.core.api.algorithm.fixture.TestComplexKeysShardingAlgorithm
;
import
io.shardingjdbc.core.api.config.ShardingRuleConfiguration
;
import
io.shardingjdbc.core.api.config.TableRuleConfiguration
;
import
io.shardingjdbc.core.api.config.strategy.ComplexShardingStrategyConfiguration
;
import
io.shardingjdbc.core.merger.QueryResult
;
import
io.shardingjdbc.core.merger.fixture.TestQueryResult
;
import
io.shardingjdbc.core.rule.ShardingRule
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
final
class
ShowTablesMergedResultTest
{
private
ShardingRule
shardingRule
;
private
List
<
QueryResult
>
queryResults
;
private
ResultSet
resultSet
;
@Before
public
void
setUp
()
throws
SQLException
{
TableRuleConfiguration
tableRuleConfig
=
new
TableRuleConfiguration
();
tableRuleConfig
.
setLogicTable
(
"table"
);
tableRuleConfig
.
setActualDataNodes
(
"ds.table_${0..2}"
);
tableRuleConfig
.
setTableShardingStrategyConfig
(
new
ComplexShardingStrategyConfiguration
(
"field1, field2, field3"
,
new
TestComplexKeysShardingAlgorithm
()));
ShardingRuleConfiguration
shardingRuleConfig
=
new
ShardingRuleConfiguration
();
shardingRuleConfig
.
getTableRuleConfigs
().
add
(
tableRuleConfig
);
shardingRule
=
new
ShardingRule
(
shardingRuleConfig
,
Lists
.
newArrayList
(
"ds"
));
resultSet
=
mock
(
ResultSet
.
class
);
ResultSetMetaData
resultSetMetaData
=
mock
(
ResultSetMetaData
.
class
);
when
(
resultSet
.
getMetaData
()).
thenReturn
(
resultSetMetaData
);
when
(
resultSetMetaData
.
getColumnCount
()).
thenReturn
(
1
);
List
<
ResultSet
>
resultSets
=
Lists
.
newArrayList
(
resultSet
);
when
(
resultSets
.
get
(
0
).
next
()).
thenReturn
(
true
);
for
(
ResultSet
each
:
resultSets
)
{
when
(
each
.
next
()).
thenReturn
(
true
,
false
);
}
queryResults
=
new
ArrayList
<>(
resultSets
.
size
());
for
(
ResultSet
each
:
resultSets
)
{
queryResults
.
add
(
new
TestQueryResult
(
each
));
}
}
@Test
public
void
assertNextForEmptyQueryResult
()
throws
SQLException
{
ShowTablesMergedResult
showTablesMergedResult
=
new
ShowTablesMergedResult
(
shardingRule
,
new
ArrayList
<
QueryResult
>());
assertFalse
(
showTablesMergedResult
.
next
());
}
@Test
public
void
assertNextForActualTableNameInTableRule
()
throws
SQLException
{
when
(
resultSet
.
getObject
(
1
)).
thenReturn
(
"table_0"
);
ShowTablesMergedResult
showTablesMergedResult
=
new
ShowTablesMergedResult
(
shardingRule
,
queryResults
);
assertTrue
(
showTablesMergedResult
.
next
());
}
@Test
public
void
assertNextForActualTableNameNotInTableRule
()
throws
SQLException
{
when
(
resultSet
.
getObject
(
1
)).
thenReturn
(
"table_3"
);
ShowTablesMergedResult
showTablesMergedResult
=
new
ShowTablesMergedResult
(
shardingRule
,
queryResults
);
assertTrue
(
showTablesMergedResult
.
next
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录