Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
e7cc1a77
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,发现更多精彩内容 >>
提交
e7cc1a77
编写于
6月 12, 2019
作者:
K
KomachiSion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add unit test for YamlOrchestrationEncryptDataSourceFactory
上级
16777afe
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
157 addition
and
1 deletion
+157
-1
sharding-jdbc/sharding-jdbc-orchestration/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/api/yaml/YamlOrchestrationEncryptDataSourceFactoryTest.java
...i/yaml/YamlOrchestrationEncryptDataSourceFactoryTest.java
+88
-0
sharding-jdbc/sharding-jdbc-orchestration/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationEncryptDataSourceTest.java
...ternal/datasource/OrchestrationEncryptDataSourceTest.java
+1
-1
sharding-jdbc/sharding-jdbc-orchestration/src/test/resources/yaml/unit/encryptWithRegistryCenter.yaml
...c/test/resources/yaml/unit/encryptWithRegistryCenter.yaml
+38
-0
sharding-jdbc/sharding-jdbc-orchestration/src/test/resources/yaml/unit/noRule.yaml
...bc-orchestration/src/test/resources/yaml/unit/noRule.yaml
+30
-0
未找到文件。
sharding-jdbc/sharding-jdbc-orchestration/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/api/yaml/YamlOrchestrationEncryptDataSourceFactoryTest.java
0 → 100644
浏览文件 @
e7cc1a77
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package
org.apache.shardingsphere.shardingjdbc.orchestration.api.yaml
;
import
lombok.SneakyThrows
;
import
org.apache.commons.dbcp2.BasicDataSource
;
import
org.apache.shardingsphere.shardingjdbc.orchestration.internal.datasource.OrchestrationEncryptDataSource
;
import
org.junit.Test
;
import
javax.sql.DataSource
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.URISyntaxException
;
import
static
org
.
hamcrest
.
CoreMatchers
.
instanceOf
;
import
static
org
.
junit
.
Assert
.
assertThat
;
public
class
YamlOrchestrationEncryptDataSourceFactoryTest
{
@Test
public
void
assertCreateDataSourceByYamlFile
()
throws
URISyntaxException
,
IOException
{
File
yamlFile
=
new
File
(
OrchestrationEncryptDataSource
.
class
.
getResource
(
"/yaml/unit/encryptWithRegistryCenter.yaml"
).
toURI
());
DataSource
dataSource
=
YamlOrchestrationEncryptDataSourceFactory
.
createDataSource
(
yamlFile
);
assertThat
(
dataSource
,
instanceOf
(
OrchestrationEncryptDataSource
.
class
));
}
@Test
public
void
assertCreateDataSourceByYamlFileWithDataSource
()
throws
URISyntaxException
,
IOException
{
File
yamlFile
=
new
File
(
OrchestrationEncryptDataSource
.
class
.
getResource
(
"/yaml/unit/encryptWithRegistryCenter.yaml"
).
toURI
());
DataSource
dataSource
=
YamlOrchestrationEncryptDataSourceFactory
.
createDataSource
(
getDataSource
(),
yamlFile
);
assertThat
(
dataSource
,
instanceOf
(
OrchestrationEncryptDataSource
.
class
));
}
@Test
public
void
assertCreateDataSourceByYamlFileWithoutRule
()
throws
URISyntaxException
,
IOException
{
File
yamlFile
=
new
File
(
OrchestrationEncryptDataSource
.
class
.
getResource
(
"/yaml/unit/noRule.yaml"
).
toURI
());
DataSource
dataSource
=
YamlOrchestrationEncryptDataSourceFactory
.
createDataSource
(
getDataSource
(),
yamlFile
);
assertThat
(
dataSource
,
instanceOf
(
OrchestrationEncryptDataSource
.
class
));
}
@Test
public
void
assertCreateDataSourceByYamlBytes
()
throws
IOException
{
DataSource
dataSource
=
YamlOrchestrationEncryptDataSourceFactory
.
createDataSource
(
readBytesFromYamlFile
());
assertThat
(
dataSource
,
instanceOf
(
OrchestrationEncryptDataSource
.
class
));
}
@Test
public
void
assertCreateDataSourceByYamlBytesWithDataSource
()
throws
IOException
{
DataSource
dataSource
=
YamlOrchestrationEncryptDataSourceFactory
.
createDataSource
(
getDataSource
()
,
readBytesFromYamlFile
());
assertThat
(
dataSource
,
instanceOf
(
OrchestrationEncryptDataSource
.
class
));
}
@SneakyThrows
private
byte
[]
readBytesFromYamlFile
()
{
File
yamlFile
=
new
File
(
OrchestrationEncryptDataSource
.
class
.
getResource
(
"/yaml/unit/encryptWithRegistryCenter.yaml"
).
toURI
());
byte
[]
result
=
new
byte
[(
int
)
yamlFile
.
length
()];
try
(
InputStream
inputStream
=
new
FileInputStream
(
yamlFile
))
{
inputStream
.
read
(
result
);
}
return
result
;
}
private
DataSource
getDataSource
()
{
BasicDataSource
result
=
new
BasicDataSource
();
result
.
setDriverClassName
(
"org.h2.Driver"
);
result
.
setUrl
(
"jdbc:h2:mem:ds_encrypt;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL"
);
result
.
setUsername
(
"sa"
);
result
.
setPassword
(
""
);
return
result
;
}
}
sharding-jdbc/sharding-jdbc-orchestration/src/test/java/org/apache/shardingsphere/shardingjdbc/orchestration/internal/datasource/OrchestrationEncryptDataSourceTest.java
浏览文件 @
e7cc1a77
...
...
@@ -61,7 +61,7 @@ public class OrchestrationEncryptDataSourceTest {
private
OrchestrationConfiguration
getOrchestrationConfiguration
()
{
RegistryCenterConfiguration
registryCenterConfiguration
=
new
RegistryCenterConfiguration
(
"TestRegistryCenter"
);
registryCenterConfiguration
.
setNamespace
(
"test_
ms
"
);
registryCenterConfiguration
.
setNamespace
(
"test_
encrypt
"
);
registryCenterConfiguration
.
setServerLists
(
"localhost:3181"
);
return
new
OrchestrationConfiguration
(
"test"
,
registryCenterConfiguration
,
true
);
}
...
...
sharding-jdbc/sharding-jdbc-orchestration/src/test/resources/yaml/unit/encryptWithRegistryCenter.yaml
0 → 100644
浏览文件 @
e7cc1a77
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#
orchestration
:
name
:
test
overwrite
:
true
registry
:
type
:
TestRegistryCenter
namespace
:
test_encrypt
serverLists
:
localhost:3181
dataSource
:
!!org.apache.commons.dbcp2.BasicDataSource
driverClassName
:
org.h2.Driver
url
:
jdbc:h2:mem:ds_encrypt;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
username
:
sa
password
:
encryptRule
:
encryptors
:
order_encryptor
:
type
:
aes
qualifiedColumns
:
t_order.user_id
props
:
aes.key.value
:
123456
sharding-jdbc/sharding-jdbc-orchestration/src/test/resources/yaml/unit/noRule.yaml
0 → 100644
浏览文件 @
e7cc1a77
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#
orchestration
:
name
:
test
overwrite
:
true
registry
:
type
:
TestRegistryCenter
namespace
:
test_encrypt
serverLists
:
localhost:3181
dataSource
:
!!org.apache.commons.dbcp2.BasicDataSource
driverClassName
:
org.h2.Driver
url
:
jdbc:h2:mem:ds_encrypt;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
username
:
sa
password
:
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录