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 431e08837a5 Add test coverage for second constructor of
DataSourceProvidedDatabaseConfiguration (#36921)
431e08837a5 is described below
commit 431e08837a53513f1ea823b3fc87d2005a11395f
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Oct 22 20:22:05 2025 +0800
Add test coverage for second constructor of
DataSourceProvidedDatabaseConfiguration (#36921)
- Add assertNewWithStorageNodeDataSources() test method to cover the second
constructor
- Follow existing test pattern and assertion structure
- Include proper DataSourcePoolProperties with required connection
properties
- Refactor createConnectionProps() as private method for code reuse
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude <[email protected]>
---
...ataSourceProvidedDatabaseConfigurationTest.java | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceProvidedDatabaseConfigurationTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceProvidedDatabaseConfigurationTest.java
index 9be39cb3d71..991ac47dbf3 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceProvidedDatabaseConfigurationTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/database/impl/DataSourceProvidedDatabaseConfigurationTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.infra.config.database.impl;
+import
org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
import org.apache.shardingsphere.infra.fixture.FixtureRuleConfiguration;
import
org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode;
import
org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit;
@@ -25,6 +26,7 @@ import org.junit.jupiter.api.Test;
import javax.sql.DataSource;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
@@ -35,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class DataSourceProvidedDatabaseConfigurationTest {
@Test
- void assertDataSourceProvidedDatabaseConfiguration() {
+ void assertNewWithDataSources() {
DataSourceProvidedDatabaseConfiguration actual = new
DataSourceProvidedDatabaseConfiguration(
Collections.singletonMap("foo_ds", new MockedDataSource()),
Collections.singleton(new FixtureRuleConfiguration("foo_rule")));
assertRuleConfigurations(actual);
@@ -48,6 +50,24 @@ class DataSourceProvidedDatabaseConfigurationTest {
assertThat(ruleConfig.getName(), is("foo_rule"));
}
+ @Test
+ void assertNewWithStorageNodeDataSources() {
+ Map<String, DataSourcePoolProperties> dataSourcePoolPropsMap =
Collections.singletonMap("foo_ds", new DataSourcePoolProperties("foo_ds",
createConnectionProps()));
+ DataSourceProvidedDatabaseConfiguration actual = new
DataSourceProvidedDatabaseConfiguration(
+ Collections.singletonMap(new StorageNode("foo_ds"), new
MockedDataSource()), Collections.singleton(new
FixtureRuleConfiguration("foo_rule")), dataSourcePoolPropsMap);
+ assertRuleConfigurations(actual);
+ assertStorageUnits(actual.getStorageUnits().get("foo_ds"));
+ assertDataSources((MockedDataSource) actual.getDataSources().get(new
StorageNode("foo_ds")));
+ }
+
+ private Map<String, Object> createConnectionProps() {
+ Map<String, Object> result = new HashMap<>(3, 1F);
+ result.put("url", "jdbc:mock://127.0.0.1/foo_ds");
+ result.put("username", "root");
+ result.put("password", "root");
+ return result;
+ }
+
private void assertStorageUnits(final StorageUnit actual) {
DataSource dataSource = actual.getDataSource();
assertThat(dataSource, isA(MockedDataSource.class));