You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/06/13 21:27:56 UTC

[GitHub] [shardingsphere] zengzhihong opened a new pull request #6027: Use YAML file instead of inline string in test cases #5428

zengzhihong opened a new pull request #6027:
URL: https://github.com/apache/shardingsphere/pull/6027


   Fixes #5428 for OrchestrationSpringBootRegistryEncryptTest.java.
   
   Changes proposed in this pull request:
   - create data-source.yaml and encrypt-rule.yaml on resources/yaml directory
   - added private static method readYAML in OrchestrationSpringBootRegistryEncryptTest.java to read these files into string
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu merged pull request #6027: Use YAML file instead of inline string in test cases #5428

Posted by GitBox <gi...@apache.org>.
terrymanu merged pull request #6027:
URL: https://github.com/apache/shardingsphere/pull/6027


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #6027: Use YAML file instead of inline string in test cases #5428

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #6027:
URL: https://github.com/apache/shardingsphere/pull/6027#discussion_r439807882



##########
File path: shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/orchestration/type/OrchestrationSpringBootRegistryEncryptTest.java
##########
@@ -46,46 +50,32 @@
 @SpringBootApplication
 @ActiveProfiles("registry")
 public class OrchestrationSpringBootRegistryEncryptTest {
-    
+
+    private static final String DATA_SOURCE_FILE = "yaml/data-source.yaml";
+
+    private static final String ENCRYPT_RULE_FILE = "yaml/encrypt-rule.yaml";
+
     @Resource
     private DataSource dataSource;
     
     @BeforeClass
     public static void init() {
         EmbedTestingServer.start();
+        String dataSource = readYAML(DATA_SOURCE_FILE);
+        String encryptRule = readYAML(ENCRYPT_RULE_FILE);
         TestCenterRepository testCenter = new TestCenterRepository();
-        testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/datasource", ""
-                + "dataSource: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" 
-                + "  dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n"
-                + "  props:\n"
-                + "    url: jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n"
-                + "    maxTotal: 100\n"
-                + "    password: ''\n"
-                + "    username: sa\n");
-        testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/rule", ""
-                + "rules:\n"
-                + "- !ENCRYPT\n"
-                + "  encryptors:\n"
-                + "    order_encrypt:\n"
-                + "      props:\n"
-                + "        aes.key.value: '123456'\n"
-                + "      type: AES\n"
-                + "  tables:\n" 
-                + "    t_order:\n" 
-                + "      columns:\n"
-                + "         user_id:\n"
-                + "           cipherColumn: user_id\n"
-                + "           encryptorName: order_encrypt\n");
+        testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/datasource", dataSource);
+        testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/rule", encryptRule);
         testCenter.persist("/demo_spring_boot_ds_center/config/props", "sql.show: 'true'\n");
         testCenter.persist("/demo_spring_boot_ds_center/registry/datasources", "");
     }
-    
+
     @Test
     public void assertWithEncryptDataSource() throws NoSuchFieldException, IllegalAccessException {
-        assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+        assertTrue(this.dataSource instanceof OrchestrationShardingSphereDataSource);
         Field field = OrchestrationShardingSphereDataSource.class.getDeclaredField("dataSource");
         field.setAccessible(true);
-        ShardingSphereDataSource encryptDataSource = (ShardingSphereDataSource) field.get(dataSource);
+        ShardingSphereDataSource encryptDataSource = (ShardingSphereDataSource) field.get(this.dataSource);

Review comment:
       Pease do not modify original code if you do not change anything

##########
File path: shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/orchestration/type/OrchestrationSpringBootRegistryEncryptTest.java
##########
@@ -46,46 +50,32 @@
 @SpringBootApplication
 @ActiveProfiles("registry")
 public class OrchestrationSpringBootRegistryEncryptTest {
-    
+
+    private static final String DATA_SOURCE_FILE = "yaml/data-source.yaml";
+
+    private static final String ENCRYPT_RULE_FILE = "yaml/encrypt-rule.yaml";
+
     @Resource
     private DataSource dataSource;
     
     @BeforeClass
     public static void init() {
         EmbedTestingServer.start();
+        String dataSource = readYAML(DATA_SOURCE_FILE);
+        String encryptRule = readYAML(ENCRYPT_RULE_FILE);
         TestCenterRepository testCenter = new TestCenterRepository();
-        testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/datasource", ""
-                + "dataSource: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" 
-                + "  dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n"
-                + "  props:\n"
-                + "    url: jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n"
-                + "    maxTotal: 100\n"
-                + "    password: ''\n"
-                + "    username: sa\n");
-        testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/rule", ""
-                + "rules:\n"
-                + "- !ENCRYPT\n"
-                + "  encryptors:\n"
-                + "    order_encrypt:\n"
-                + "      props:\n"
-                + "        aes.key.value: '123456'\n"
-                + "      type: AES\n"
-                + "  tables:\n" 
-                + "    t_order:\n" 
-                + "      columns:\n"
-                + "         user_id:\n"
-                + "           cipherColumn: user_id\n"
-                + "           encryptorName: order_encrypt\n");
+        testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/datasource", dataSource);
+        testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/rule", encryptRule);
         testCenter.persist("/demo_spring_boot_ds_center/config/props", "sql.show: 'true'\n");
         testCenter.persist("/demo_spring_boot_ds_center/registry/datasources", "");
     }
-    
+
     @Test
     public void assertWithEncryptDataSource() throws NoSuchFieldException, IllegalAccessException {
-        assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+        assertTrue(this.dataSource instanceof OrchestrationShardingSphereDataSource);

Review comment:
       Pease do not modify original code if you do not change anything

##########
File path: shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/orchestration/type/OrchestrationSpringBootRegistryEncryptTest.java
##########
@@ -46,46 +50,32 @@
 @SpringBootApplication
 @ActiveProfiles("registry")
 public class OrchestrationSpringBootRegistryEncryptTest {
-    
+
+    private static final String DATA_SOURCE_FILE = "yaml/data-source.yaml";
+
+    private static final String ENCRYPT_RULE_FILE = "yaml/encrypt-rule.yaml";
+
     @Resource
     private DataSource dataSource;
     
     @BeforeClass
     public static void init() {
         EmbedTestingServer.start();
+        String dataSource = readYAML(DATA_SOURCE_FILE);
+        String encryptRule = readYAML(ENCRYPT_RULE_FILE);
         TestCenterRepository testCenter = new TestCenterRepository();
-        testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/datasource", ""
-                + "dataSource: !!org.apache.shardingsphere.orchestration.core.configuration.YamlDataSourceConfiguration\n" 
-                + "  dataSourceClassName: org.apache.commons.dbcp2.BasicDataSource\n"
-                + "  props:\n"
-                + "    url: jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL\n"
-                + "    maxTotal: 100\n"
-                + "    password: ''\n"
-                + "    username: sa\n");
-        testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/rule", ""
-                + "rules:\n"
-                + "- !ENCRYPT\n"
-                + "  encryptors:\n"
-                + "    order_encrypt:\n"
-                + "      props:\n"
-                + "        aes.key.value: '123456'\n"
-                + "      type: AES\n"
-                + "  tables:\n" 
-                + "    t_order:\n" 
-                + "      columns:\n"
-                + "         user_id:\n"
-                + "           cipherColumn: user_id\n"
-                + "           encryptorName: order_encrypt\n");
+        testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/datasource", dataSource);
+        testCenter.persist("/demo_spring_boot_ds_center/config/schema/logic_db/rule", encryptRule);
         testCenter.persist("/demo_spring_boot_ds_center/config/props", "sql.show: 'true'\n");
         testCenter.persist("/demo_spring_boot_ds_center/registry/datasources", "");
     }
-    
+

Review comment:
       please keep the original indent

##########
File path: shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-orchestration-spring/shardingsphere-jdbc-orchestration-spring-boot-starter/src/test/resources/yaml/encrypt-rule.yaml
##########
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+
+rules:
+  - !ENCRYPT
+    encryptors:
+      order_encrypt:
+        props:
+          aes.key.value: '123456'
+        type: AES
+    tables:
+      t_order:
+        columns:
+          user_id:
+            cipherColumn: user_id
+            encryptorName: order_encrypt

Review comment:
       Please add a blank line in end of file




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] codecov-commenter commented on pull request #6027: Use YAML file instead of inline string in test cases #5428

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #6027:
URL: https://github.com/apache/shardingsphere/pull/6027#issuecomment-643683065


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/6027?src=pr&el=h1) Report
   > Merging [#6027](https://codecov.io/gh/apache/shardingsphere/pull/6027?src=pr&el=desc) into [master](https://codecov.io/gh/apache/shardingsphere/commit/8c79331f53a6f380450e91bc91acf01bd0fe5b08&el=desc) will **not change** coverage.
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/6027/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so)](https://codecov.io/gh/apache/shardingsphere/pull/6027?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff            @@
   ##             master    #6027   +/-   ##
   =========================================
     Coverage     53.11%   53.11%           
     Complexity      438      438           
   =========================================
     Files          1194     1194           
     Lines         20941    20941           
     Branches       3767     3767           
   =========================================
     Hits          11122    11122           
     Misses         9122     9122           
     Partials        697      697           
   ```
   
   
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/6027?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/6027?src=pr&el=footer). Last update [8c79331...9c216ac](https://codecov.io/gh/apache/shardingsphere/pull/6027?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org