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 3ebfd5680ae Add more test cases on YamlPluginsConfigurationSwapper 
(#37664)
3ebfd5680ae is described below

commit 3ebfd5680ae2863bb2b6c3a749c2fb3544ec082a
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Jan 7 00:12:50 2026 +0800

    Add more test cases on YamlPluginsConfigurationSwapper (#37664)
    
    * Upgrade checkstyle version
    
    * Upgrade checkstyle version
    
    * Upgrade checkstyle version
    
    * Upgrade checkstyle version
    
    * Upgrade checkstyle version
    
    * Upgrade checkstyle version
    
    * Upgrade checkstyle version
    
    * Upgrade checkstyle version
    
    * Add more test cases on YamlPluginsConfigurationSwapper
---
 .../swapper/YamlPluginsConfigurationSwapper.java   |  3 +-
 .../YamlPluginsConfigurationSwapperTest.java       | 35 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapper.java
 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapper.java
index b63fae47313..378b232ae69 100644
--- 
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapper.java
+++ 
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapper.java
@@ -62,7 +62,8 @@ public final class YamlPluginsConfigurationSwapper {
     }
     
     private static PluginConfiguration swap(final YamlPluginConfiguration 
yamlConfig) {
-        return null == yamlConfig ? new PluginConfiguration(null, 0, null, new 
Properties())
+        return null == yamlConfig
+                ? new PluginConfiguration(null, 0, null, new Properties())
                 : new PluginConfiguration(yamlConfig.getHost(), 
yamlConfig.getPort(), yamlConfig.getPassword(), yamlConfig.getProps());
     }
 }
diff --git 
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java
 
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java
index c8289490e49..18a6b9b40e4 100644
--- 
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java
+++ 
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java
@@ -30,6 +30,7 @@ import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.nio.file.Files;
+import java.util.LinkedHashMap;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Objects;
@@ -44,6 +45,11 @@ class YamlPluginsConfigurationSwapperTest {
     
     private static final String CONFIG_PATH = "/conf/agent.yaml";
     
+    @Test
+    void assertSwapWithNullPluginCategory() {
+        assertTrue(YamlPluginsConfigurationSwapper.swap(new 
YamlAgentConfiguration()).isEmpty());
+    }
+    
     @Test
     void assertSwapWithNullPlugins() {
         YamlAgentConfiguration yamlAgentConfig = new YamlAgentConfiguration();
@@ -81,6 +87,35 @@ class YamlPluginsConfigurationSwapperTest {
         assertTracingPluginConfiguration(actual.get("tracing_fixture"));
     }
     
+    @Test
+    void assertSwapWithNullLoggingPlugins() {
+        YamlPluginCategoryConfiguration yamlPluginCategoryConfig = new 
YamlPluginCategoryConfiguration();
+        yamlPluginCategoryConfig.setLogging(null);
+        
yamlPluginCategoryConfig.setMetrics(Collections.singletonMap("metrics_fixture", 
createYamlPluginConfiguration("localhost", "random", 8081, 
createProperties())));
+        YamlAgentConfiguration yamlAgentConfig = new YamlAgentConfiguration();
+        yamlAgentConfig.setPlugins(yamlPluginCategoryConfig);
+        Map<String, PluginConfiguration> actual = 
YamlPluginsConfigurationSwapper.swap(yamlAgentConfig);
+        assertThat(actual.size(), is(1));
+        assertMetricsPluginConfiguration(actual.get("metrics_fixture"));
+    }
+    
+    @Test
+    void assertSwapWithNullPluginConfigurationValue() {
+        YamlPluginCategoryConfiguration yamlPluginCategoryConfig = new 
YamlPluginCategoryConfiguration();
+        Map<String, YamlPluginConfiguration> logging = new LinkedHashMap<>();
+        logging.put("log_fixture", null);
+        yamlPluginCategoryConfig.setLogging(logging);
+        YamlAgentConfiguration yamlAgentConfig = new YamlAgentConfiguration();
+        yamlAgentConfig.setPlugins(yamlPluginCategoryConfig);
+        Map<String, PluginConfiguration> actual = 
YamlPluginsConfigurationSwapper.swap(yamlAgentConfig);
+        assertThat(actual.size(), is(1));
+        PluginConfiguration actualLogFixtureConfig = actual.get("log_fixture");
+        assertNull(actualLogFixtureConfig.getHost());
+        assertNull(actualLogFixtureConfig.getPassword());
+        assertThat(actualLogFixtureConfig.getPort(), is(0));
+        assertTrue(actualLogFixtureConfig.getProps().isEmpty());
+    }
+    
     @Test
     void assertSwapWithFile() throws IOException {
         try (InputStream inputStream = Files.newInputStream(new 
File(getResourceURL(), CONFIG_PATH).toPath())) {

Reply via email to