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 202371b7cc0 [Issue#18169] add unit test for DatabaseTypeEngine (#18250)
202371b7cc0 is described below

commit 202371b7cc0da3583165913010a2d4e100998b72
Author: windWheel <1817802...@qq.com>
AuthorDate: Sat Jun 11 11:02:39 2022 +0800

    [Issue#18169] add unit test for DatabaseTypeEngine (#18250)
    
    * fix unit test
---
 .../database/type/DatabaseTypeEngineTest.java      | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
index 469034e3e4c..195ebadb1b7 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/DatabaseTypeEngineTest.java
@@ -17,8 +17,16 @@
 
 package org.apache.shardingsphere.infra.database.type;
 
+import java.util.Properties;
+import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration;
+import 
org.apache.shardingsphere.infra.config.database.impl.DataSourceProvidedDatabaseConfiguration;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
 import 
org.apache.shardingsphere.infra.database.type.dialect.MariaDBDatabaseType;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import 
org.apache.shardingsphere.infra.database.type.dialect.OracleDatabaseType;
+import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration;
+import static org.hamcrest.CoreMatchers.instanceOf;
 import org.junit.Test;
 
 import javax.sql.DataSource;
@@ -181,4 +189,30 @@ public final class DatabaseTypeEngineTest {
     public void assertGetTrunkDatabaseTypeNameWithBranchDatabaseType() {
         assertThat(DatabaseTypeEngine.getTrunkDatabaseTypeName(new 
MariaDBDatabaseType()), is("MySQL"));
     }
+    
+    @Test
+    public void assertGetProtocolType() {
+        Properties trunkDatabaseProps = new Properties();
+        
trunkDatabaseProps.setProperty(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(),
 "H2");
+        DatabaseConfiguration databaseConfig = new 
DataSourceProvidedDatabaseConfiguration(Collections.emptyMap(), 
Collections.singletonList(new FixtureRuleConfiguration()));
+        
assertThat(DatabaseTypeEngine.getProtocolType(Collections.singletonMap("logic_db",
 databaseConfig), new ConfigurationProperties(trunkDatabaseProps)), 
instanceOf(MySQLDatabaseType.class));
+        Properties noTrunkDatabaseProps = new Properties();
+        
noTrunkDatabaseProps.setProperty(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE.getKey(),
 "Oracle");
+        
assertThat(DatabaseTypeEngine.getProtocolType(Collections.singletonMap("logic_db",
 databaseConfig), new ConfigurationProperties(noTrunkDatabaseProps)), 
instanceOf(OracleDatabaseType.class));
+    }
+    
+    @Test
+    public void assertGetStorageType() throws SQLException {
+        DataSource datasource = 
mockDataSource(DatabaseTypeFactory.getInstance("MySQL"));
+        DatabaseConfiguration databaseConfig = new 
DataSourceProvidedDatabaseConfiguration(Collections.singletonMap("", 
datasource), Collections.singletonList(new FixtureRuleConfiguration()));
+        
assertThat(DatabaseTypeEngine.getStorageType(Collections.singletonMap("logic_db",
 databaseConfig)), instanceOf(MySQLDatabaseType.class));
+    }
+    
+    @Test
+    public void assertGetDefaultSchemaName() {
+        DatabaseType schemaSupportDatabaseType = 
DatabaseTypeFactory.getInstance("openGauss");
+        
assertThat(DatabaseTypeEngine.getDefaultSchemaName(schemaSupportDatabaseType, 
""), is("public"));
+        DatabaseType schemaNoSupportDatabaseType = 
DatabaseTypeFactory.getInstance("MySQL");
+        
assertThat(DatabaseTypeEngine.getDefaultSchemaName(schemaNoSupportDatabaseType, 
"MySQL"), is("MySQL"));
+    }
 }

Reply via email to