You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/08/05 06:17:37 UTC

[shardingsphere] branch master updated: Add test case for Database type (#6619)

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 4924d76  Add test case for Database type (#6619)
4924d76 is described below

commit 4924d768356a1d1ad0fb5d4682b73d440542dfd5
Author: 孙念君 Sun Nianjun <su...@huobi.com>
AuthorDate: Wed Aug 5 14:17:28 2020 +0800

    Add test case for Database type (#6619)
    
    * Add: add test case for H2DatabaseTypeTest (#6590)
    
    * Add: add test case for MariaDBDatabaseType (#6590)
    
    * Add: add test case for OracleDatabaseType (#6590)
    
    * Format: format the code
    
    * Add: add test case for PostgreSQLDatabaseType (#6590)
    
    * Add: add test case for SQL92DatabaseType (#6590)
    
    * Add: add test case for SQLServerDatabaseType (#6590)
    
    * Refactor: refactor the default user name for test case (#6590)
    
    * Add: add final modifier for every database type test case (#6590)
---
 .../database/type/dialect/H2DatabaseTypeTest.java  | 52 ++++++++++++++++++++++
 .../type/dialect/MariaDBDatabaseTypeTest.java      | 51 +++++++++++++++++++++
 .../type/dialect/OracleDatabaseTypeTest.java       | 45 +++++++++++++++++++
 .../type/dialect/PostgreSQLDatabaseTypeTest.java   | 45 +++++++++++++++++++
 .../type/dialect/SQL92DatabaseTypeTest.java        | 50 +++++++++++++++++++++
 .../type/dialect/SQLServerDatabaseTypeTest.java    | 46 +++++++++++++++++++
 6 files changed, 289 insertions(+)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseTypeTest.java
new file mode 100644
index 0000000..6751053
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/H2DatabaseTypeTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.infra.database.type.dialect;
+
+import org.apache.shardingsphere.infra.database.metadata.dialect.H2DataSourceMetaData;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class H2DatabaseTypeTest {
+
+    @Test
+    public void assertGetName() {
+        assertThat(new H2DatabaseType().getName(), is("H2"));
+    }
+    
+    @Test
+    public void assertGetJdbcUrlPrefixes() {
+        assertThat(new H2DatabaseType().getJdbcUrlPrefixes(), is(Collections.singleton("jdbc:h2:")));
+    }
+    
+    @Test
+    public void assertGetDataSourceMetaData() {
+        assertThat(new H2DatabaseType().getDataSourceMetaData("jdbc:h2:~:master_ds_0", "sa"), instanceOf(H2DataSourceMetaData.class));
+        assertThat(new H2DatabaseType().getDataSourceMetaData("jdbc:h2:mem:master_ds_0", "sa"), instanceOf(H2DataSourceMetaData.class));
+    }
+    
+    @Test
+    public void assertGetTrunkDatabaseType() {
+        assertThat(new H2DatabaseType().getTrunkDatabaseType().getName(), is("MySQL"));
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseTypeTest.java
new file mode 100644
index 0000000..77ed10c
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/MariaDBDatabaseTypeTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.infra.database.type.dialect;
+
+import org.apache.shardingsphere.infra.database.metadata.dialect.MariaDBDataSourceMetaData;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class MariaDBDatabaseTypeTest {
+    
+    @Test
+    public void assertGetName() {
+        assertThat(new MariaDBDatabaseType().getName(), is("MariaDB"));
+    }
+    
+    @Test
+    public void assertGetJdbcUrlPrefixes() {
+        assertThat(new MariaDBDatabaseType().getJdbcUrlPrefixes(), is(Collections.singleton("jdbc:mariadb:")));
+    }
+    
+    @Test
+    public void assertGetDataSourceMetaData() {
+        assertThat(new MariaDBDatabaseType().getDataSourceMetaData("jdbc:mysql://localhost:3306/demo_ds_0", "root"), instanceOf(MariaDBDataSourceMetaData.class));
+        assertThat(new MariaDBDatabaseType().getDataSourceMetaData("jdbc:mariadb://localhost:3306/demo_ds_0", "root"), instanceOf(MariaDBDataSourceMetaData.class));
+    }
+    
+    @Test
+    public void assertGetTrunkDatabaseType() {
+        assertThat(new MariaDBDatabaseType().getTrunkDatabaseType().getName(), is("MySQL"));
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/OracleDatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/OracleDatabaseTypeTest.java
new file mode 100644
index 0000000..0ef5241
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/OracleDatabaseTypeTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.infra.database.type.dialect;
+
+import org.apache.shardingsphere.infra.database.metadata.dialect.OracleDataSourceMetaData;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class OracleDatabaseTypeTest {
+    
+    @Test
+    public void assertGetName() {
+        assertThat(new OracleDatabaseType().getName(), is("Oracle"));
+    }
+    
+    @Test
+    public void assertGetJdbcUrlPrefixes() {
+        assertThat(new OracleDatabaseType().getJdbcUrlPrefixes(), is(Collections.singleton("jdbc:oracle:")));
+    }
+    
+    @Test
+    public void assertOracleDataSourceMetaData() {
+        assertThat(new OracleDatabaseType().getDataSourceMetaData("jdbc:oracle:oci:@127.0.0.1/ds_0", "scott"), instanceOf(OracleDataSourceMetaData.class));
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
new file mode 100644
index 0000000..72d74ed
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/PostgreSQLDatabaseTypeTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.infra.database.type.dialect;
+
+import org.apache.shardingsphere.infra.database.metadata.dialect.PostgreSQLDataSourceMetaData;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class PostgreSQLDatabaseTypeTest {
+    
+    @Test
+    public void assertGetName() {
+        assertThat(new PostgreSQLDatabaseType().getName(), is("PostgreSQL"));
+    }
+    
+    @Test
+    public void assertGetJdbcUrlPrefixes() {
+        assertThat(new PostgreSQLDatabaseType().getJdbcUrlPrefixes(), is(Collections.singleton("jdbc:postgresql:")));
+    }
+    
+    @Test
+    public void assertGetDataSourceMetaData() {
+        assertThat(new PostgreSQLDatabaseType().getDataSourceMetaData("jdbc:postgresql://localhost:5432/demo_ds_0", "postgres"), instanceOf(PostgreSQLDataSourceMetaData.class));
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQL92DatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQL92DatabaseTypeTest.java
new file mode 100644
index 0000000..d4ecf2c
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQL92DatabaseTypeTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.infra.database.type.dialect;
+
+import org.apache.shardingsphere.infra.database.metadata.dialect.SQL92DataSourceMetaData;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class SQL92DatabaseTypeTest {
+    
+    @Test
+    public void assertGetName() {
+        assertThat(new SQL92DatabaseType().getName(), is("SQL92"));
+    }
+    
+    @Test
+    public void assertGetJdbcUrlPrefixes() {
+        assertThat(new SQL92DatabaseType().getJdbcUrlPrefixes(), is(Collections.emptyList()));
+    }
+    
+    @Test
+    public void assertGetDataSourceMetaData() {
+        assertThat(new SQL92DatabaseType().getDataSourceMetaData("jdbc:h2:mem:master_ds_0", "sa"), instanceOf(SQL92DataSourceMetaData.class));
+        assertThat(new SQL92DatabaseType().getDataSourceMetaData("jdbc:mariadb://localhost:3306/demo_ds_0", "sa"), instanceOf(SQL92DataSourceMetaData.class));
+        assertThat(new SQL92DatabaseType().getDataSourceMetaData("jdbc:mysql://127.0.0.1/demo_ds_0", "root"), instanceOf(SQL92DataSourceMetaData.class));
+        assertThat(new SQL92DatabaseType().getDataSourceMetaData("jdbc:postgresql://localhost:5432/demo_ds_0", "postgres"), instanceOf(SQL92DataSourceMetaData.class));
+        assertThat(new SQL92DatabaseType().getDataSourceMetaData("jdbc:oracle:oci:@127.0.0.1/demo_ds_0", "scott"), instanceOf(SQL92DataSourceMetaData.class));
+        assertThat(new SQL92DatabaseType().getDataSourceMetaData("jdbc:microsoft:sqlserver://127.0.0.1;DatabaseName=ds_0", "sa"), instanceOf(SQL92DataSourceMetaData.class));
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQLServerDatabaseTypeTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQLServerDatabaseTypeTest.java
new file mode 100644
index 0000000..aeeb0d7
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/database/type/dialect/SQLServerDatabaseTypeTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.infra.database.type.dialect;
+
+import org.apache.shardingsphere.infra.database.metadata.dialect.SQLServerDataSourceMetaData;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class SQLServerDatabaseTypeTest {
+    
+    @Test
+    public void assertGetName() {
+        assertThat(new SQLServerDatabaseType().getName(), is("SQLServer"));
+    }
+    
+    @Test
+    public void assertGetJdbcUrlPrefixes() {
+        assertThat(new SQLServerDatabaseType().getJdbcUrlPrefixes(), is(Collections.singletonList("jdbc:microsoft:sqlserver:")));
+    }
+    
+    @Test
+    public void assertGetDataSourceMetaData() {
+        assertThat(new SQLServerDatabaseType().getDataSourceMetaData("jdbc:sqlserver://127.0.0.1;DatabaseName=ds_0", "root"), instanceOf(SQLServerDataSourceMetaData.class));
+        assertThat(new SQLServerDatabaseType().getDataSourceMetaData("jdbc:microsoft:sqlserver://127.0.0.1;DatabaseName=ds_0", "sa"), instanceOf(SQLServerDataSourceMetaData.class));
+    }
+}