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 73f08e0f3a3 Add more test cases on DialectDatabaseMetaDataTest (#38107)
73f08e0f3a3 is described below
commit 73f08e0f3a30b3a4619d01a6bf16429162083580
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Feb 20 11:36:29 2026 +0800
Add more test cases on DialectDatabaseMetaDataTest (#38107)
---
.codex/skills/gen-ut/SKILL.md | 2 +
.../metadata/DialectDatabaseMetaDataTest.java | 130 +++++++++++++++++++++
2 files changed, 132 insertions(+)
diff --git a/.codex/skills/gen-ut/SKILL.md b/.codex/skills/gen-ut/SKILL.md
index 14fc4e6bbd1..f4ebb0e68ef 100644
--- a/.codex/skills/gen-ut/SKILL.md
+++ b/.codex/skills/gen-ut/SKILL.md
@@ -78,9 +78,11 @@ Module resolution order:
- For parameterized tests, `Arguments` row count `MUST` be greater than or
equal to 3.
- Tests `MUST` exercise behavior through public methods only.
- Public production methods with business logic `MUST` be covered with
dedicated test methods.
+ - For interface targets, only `default` public methods are required test
targets by default, and non-`default` public methods `MUST NOT` be tested
unless the user explicitly requests them in the current turn.
- Dedicated test targets `MUST` follow the `R4` branch-mapping exclusion
scope.
- `R6`: SPI, Mock, and reflection
+ - For interface `default` methods, this rule overrides SPI instantiation
requirements in `R6`: tests `MUST` use Mockito `CALLS_REAL_METHODS` to invoke
real default implementations, and this path does not require SPI-bypass
justification.
- If the class under test can be obtained via SPI, `MUST` instantiate by
default with `TypedSPILoader`/`OrderedSPILoader` (or database-specific
loaders), and `MUST` keep the resolved instance as a test-class-level field
(global variable) by default.
- SPI metadata accessor methods `TypedSPI#getType`, `OrderedSPI#getOrder`,
and `getTypeClass` are default no-test-required targets.
- For these accessors, tests `MUST NOT` be added by default; they are
allowed only when the user explicitly requests tests for them in the current
turn.
diff --git
a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/database/metadata/DialectDatabaseMetaDataTest.java
b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/database/metadata/DialectDatabaseMetaDataTest.java
new file mode 100644
index 00000000000..e7fa7444486
--- /dev/null
+++
b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/database/metadata/DialectDatabaseMetaDataTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.database.connector.core.metadata.database.metadata;
+
+import
org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.connection.DialectConnectionOption;
+import
org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.datatype.DefaultDataTypeOption;
+import
org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.join.DialectJoinOption;
+import
org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.pagination.DialectPaginationOption;
+import
org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.schema.DialectSchemaOption;
+import
org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.transaction.DialectTransactionOption;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Connection;
+import java.util.Optional;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.isA;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
+import static org.mockito.Mockito.mock;
+
+class DialectDatabaseMetaDataTest {
+
+ private final DialectDatabaseMetaData dialectDatabaseMetaData =
mock(DialectDatabaseMetaData.class, CALLS_REAL_METHODS);
+
+ @Test
+ void assertIsCaseSensitive() {
+ assertFalse(dialectDatabaseMetaData.isCaseSensitive());
+ }
+
+ @Test
+ void assertGetDataTypeOption() {
+ assertThat(dialectDatabaseMetaData.getDataTypeOption(),
isA(DefaultDataTypeOption.class));
+ }
+
+ @Test
+ void assertGetDriverQuerySystemCatalogOption() {
+
assertThat(dialectDatabaseMetaData.getDriverQuerySystemCatalogOption(),
is(Optional.empty()));
+ }
+
+ @Test
+ void assertGetSchemaOption() {
+ DialectSchemaOption actual = dialectDatabaseMetaData.getSchemaOption();
+ assertFalse(actual.isSchemaAvailable());
+ assertThat(actual.getDefaultSchema(), is(Optional.empty()));
+ }
+
+ @Test
+ void assertGetColumnOption() {
+
assertTrue(dialectDatabaseMetaData.getColumnOption().isColumnNameEqualsLabelInColumnProjection());
+ }
+
+ @Test
+ void assertGetIndexOption() {
+
assertFalse(dialectDatabaseMetaData.getIndexOption().isSchemaUniquenessLevel());
+ }
+
+ @Test
+ void assertGetConnectionOption() {
+ DialectConnectionOption actual =
dialectDatabaseMetaData.getConnectionOption();
+ assertFalse(actual.isInstanceConnectionAvailable());
+ assertFalse(actual.isSupportThreeTierStorageStructure());
+ }
+
+ @Test
+ void assertGetTransactionOption() {
+ DialectTransactionOption actual =
dialectDatabaseMetaData.getTransactionOption();
+ assertFalse(actual.isSupportGlobalCSN());
+ assertFalse(actual.isDDLNeedImplicitCommit());
+ assertFalse(actual.isSupportAutoCommitInNestedTransaction());
+ assertFalse(actual.isSupportDDLInXATransaction());
+ assertTrue(actual.isSupportMetaDataRefreshInTransaction());
+ assertThat(actual.getDefaultIsolationLevel(),
is(Connection.TRANSACTION_READ_COMMITTED));
+ assertFalse(actual.isReturnRollbackStatementWhenCommitFailed());
+
assertFalse(actual.isAllowCommitAndRollbackOnlyWhenTransactionFailed());
+ assertTrue(actual.getXaDriverClassNames().isEmpty());
+ }
+
+ @Test
+ void assertGetJoinOption() {
+ DialectJoinOption actual = dialectDatabaseMetaData.getJoinOption();
+ assertFalse(actual.isUsingColumnsByProjectionOrder());
+ assertFalse(actual.isRightColumnsByFirstOrder());
+ }
+
+ @Test
+ void assertGetPaginationOption() {
+ DialectPaginationOption actual =
dialectDatabaseMetaData.getPaginationOption();
+ assertFalse(actual.isContainsRowNumber());
+ assertThat(actual.getRowNumberColumnName(), is(""));
+ assertFalse(actual.isContainsTop());
+ }
+
+ @Test
+ void assertGetGeneratedKeyOption() {
+ assertThat(dialectDatabaseMetaData.getGeneratedKeyOption(),
is(Optional.empty()));
+ }
+
+ @Test
+ void assertGetAlterTableOption() {
+ assertThat(dialectDatabaseMetaData.getAlterTableOption(),
is(Optional.empty()));
+ }
+
+ @Test
+ void assertGetSQLBatchOption() {
+
assertTrue(dialectDatabaseMetaData.getSQLBatchOption().isSupportSQLBatch());
+ }
+
+ @Test
+ void assertGetProtocolVersionOption() {
+
assertThat(dialectDatabaseMetaData.getProtocolVersionOption().getDefaultVersion(),
is(""));
+ }
+}