This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new f31ba1e639e Refactor ImportDatabaseConfigurationUpdaterTest (#24530)
f31ba1e639e is described below

commit f31ba1e639e281d4c021b27767e93a82e54baaf5
Author: yx9o <[email protected]>
AuthorDate: Fri Mar 10 00:32:35 2023 +0800

    Refactor ImportDatabaseConfigurationUpdaterTest (#24530)
---
 .../ImportDatabaseConfigurationUpdaterTest.java    | 55 ++++++----------------
 1 file changed, 15 insertions(+), 40 deletions(-)

diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java
index edfdb2a0ede..de98effa5a5 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java
@@ -55,85 +55,64 @@ public final class ImportDatabaseConfigurationUpdaterTest {
     
     @Test
     public void assertImportDatabaseExecutorForSharding() throws SQLException {
-        String databaseName = "sharding_db";
-        init(databaseName);
-        importDatabaseConfigUpdater.executeUpdate(databaseName, new 
ImportDatabaseConfigurationStatement(getDatabaseConfigurationFilePath("/conf/import/config-sharding.yaml")));
+        assertExecute("sharding_db", "/conf/import/config-sharding.yaml");
     }
     
     @Test
     public void assertImportDatabaseExecutorForReadwriteSplitting() throws 
SQLException {
-        String databaseName = "readwrite_splitting_db";
-        init(databaseName);
-        importDatabaseConfigUpdater.executeUpdate(databaseName, new 
ImportDatabaseConfigurationStatement(getDatabaseConfigurationFilePath("/conf/import/config-readwrite-splitting.yaml")));
+        assertExecute("readwrite_splitting_db", 
"/conf/import/config-readwrite-splitting.yaml");
     }
     
     @Test
     public void assertImportDatabaseExecutorForDatabaseDiscovery() throws 
SQLException {
-        String databaseName = "database_discovery_db";
-        init(databaseName);
-        importDatabaseConfigUpdater.executeUpdate(databaseName, new 
ImportDatabaseConfigurationStatement(getDatabaseConfigurationFilePath("/conf/import/config-database-discovery.yaml")));
+        assertExecute("database_discovery_db", 
"/conf/import/config-database-discovery.yaml");
     }
     
     @Test
     public void assertImportDatabaseExecutorForEncrypt() throws SQLException {
-        String databaseName = "encrypt_db";
-        init(databaseName);
-        importDatabaseConfigUpdater.executeUpdate(databaseName, new 
ImportDatabaseConfigurationStatement(getDatabaseConfigurationFilePath("/conf/import/config-encrypt.yaml")));
+        assertExecute("encrypt_db", "/conf/import/config-encrypt.yaml");
     }
     
     @Test
     public void assertImportDatabaseExecutorForShadow() throws SQLException {
-        String databaseName = "shadow_db";
-        init(databaseName);
-        importDatabaseConfigUpdater.executeUpdate(databaseName, new 
ImportDatabaseConfigurationStatement(getDatabaseConfigurationFilePath("/conf/import/config-shadow.yaml")));
+        assertExecute("shadow_db", "/conf/import/config-shadow.yaml");
     }
     
     @Test
     public void assertImportDatabaseExecutorForMask() throws SQLException {
-        String databaseName = "mask_db";
-        init(databaseName);
-        importDatabaseConfigUpdater.executeUpdate(databaseName, new 
ImportDatabaseConfigurationStatement(getDatabaseConfigurationFilePath("/conf/import/config-mask.yaml")));
+        assertExecute("mask_db", "/conf/import/config-mask.yaml");
     }
     
     @Test
     public void assertImportExistedDatabase() {
         String databaseName = "sharding_db";
-        init(databaseName);
         
when(ProxyContext.getInstance().databaseExists(databaseName)).thenReturn(true);
-        assertThrows(IllegalStateException.class, () -> 
importDatabaseConfigUpdater.executeUpdate(databaseName,
-                new 
ImportDatabaseConfigurationStatement(getDatabaseConfigurationFilePath("/conf/import/config-sharding.yaml"))));
+        assertThrows(IllegalStateException.class, () -> 
assertExecute(databaseName, "/conf/import/config-sharding.yaml"));
     }
     
     @Test
     public void assertImportEmptyDatabaseName() {
-        String databaseName = "sharding_db";
-        init(databaseName);
-        assertThrows(NullPointerException.class, () -> 
importDatabaseConfigUpdater.executeUpdate(databaseName,
-                new 
ImportDatabaseConfigurationStatement(getDatabaseConfigurationFilePath("/conf/import/config-empty-database-name.yaml"))));
+        assertThrows(NullPointerException.class, () -> 
assertExecute("sharding_db", "/conf/import/config-empty-database-name.yaml"));
     }
     
     @Test
     public void assertImportEmptyDataSource() {
-        String databaseName = "sharding_db";
-        init(databaseName);
-        assertThrows(IllegalStateException.class, () -> 
importDatabaseConfigUpdater.executeUpdate(databaseName,
-                new 
ImportDatabaseConfigurationStatement(getDatabaseConfigurationFilePath("/conf/import/config-empty-data-source.yaml"))));
+        assertThrows(IllegalStateException.class, () -> 
assertExecute("sharding_db", "/conf/import/config-empty-data-source.yaml"));
     }
     
     @Test
     public void assertImportDuplicatedLogicTable() {
-        String databaseName = "sharding_db";
-        init(databaseName);
-        assertThrows(DuplicateRuleException.class, () -> 
importDatabaseConfigUpdater.executeUpdate(databaseName,
-                new 
ImportDatabaseConfigurationStatement(getDatabaseConfigurationFilePath("/conf/import/config-duplicated-logic-table.yaml"))));
+        assertThrows(DuplicateRuleException.class, () -> 
assertExecute("sharding_db", 
"/conf/import/config-duplicated-logic-table.yaml"));
     }
     
     @Test
     public void assertImportInvalidAlgorithm() {
-        String databaseName = "sharding_db";
+        assertThrows(InvalidAlgorithmConfigurationException.class, () -> 
assertExecute("sharding_db", "/conf/import/config-invalid-algorithm.yaml"));
+    }
+    
+    private void assertExecute(final String databaseName, final String 
filePath) throws SQLException {
         init(databaseName);
-        assertThrows(InvalidAlgorithmConfigurationException.class, () -> 
importDatabaseConfigUpdater.executeUpdate(databaseName,
-                new 
ImportDatabaseConfigurationStatement(getDatabaseConfigurationFilePath("/conf/import/config-invalid-algorithm.yaml"))));
+        importDatabaseConfigUpdater.executeUpdate(databaseName, new 
ImportDatabaseConfigurationStatement(ImportDatabaseConfigurationUpdaterTest.class.getResource(filePath).getPath()));
     }
     
     @SneakyThrows({IllegalAccessException.class, NoSuchFieldException.class})
@@ -166,8 +145,4 @@ public final class ImportDatabaseConfigurationUpdaterTest {
         
result.setProperty(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(),
 "MySQL");
         return result;
     }
-    
-    private String getDatabaseConfigurationFilePath(final String filePath) {
-        return 
ImportDatabaseConfigurationUpdaterTest.class.getResource(filePath).getPath();
-    }
 }

Reply via email to