This is an automated email from the ASF dual-hosted git repository.

chengzhang 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 1475d9d2a6a Add test cases on 
ClusterYamlPersistRepositoryConfigurationSwapper (#32864)
1475d9d2a6a is described below

commit 1475d9d2a6ad51c537ac110421034af24538fd3c
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Sep 14 15:46:17 2024 +0800

    Add test cases on ClusterYamlPersistRepositoryConfigurationSwapper (#32864)
    
    * Add test cases on ClusterWorkerIdGenerator
    
    * Add test cases on ClusterWorkerIdGenerator
    
    * Add test cases on ClusterYamlPersistRepositoryConfigurationSwapper
---
 ...lPersistRepositoryConfigurationSwapperTest.java | 59 ++++++++++++++++++++++
 ...lPersistRepositoryConfigurationSwapperTest.java | 13 +++--
 2 files changed, 68 insertions(+), 4 deletions(-)

diff --git 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/yaml/ClusterYamlPersistRepositoryConfigurationSwapperTest.java
 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/yaml/ClusterYamlPersistRepositoryConfigurationSwapperTest.java
new file mode 100644
index 00000000000..bf681eec6f0
--- /dev/null
+++ 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/yaml/ClusterYamlPersistRepositoryConfigurationSwapperTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.mode.manager.cluster.yaml;
+
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import 
org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlPersistRepositoryConfiguration;
+import 
org.apache.shardingsphere.infra.yaml.config.swapper.mode.YamlPersistRepositoryConfigurationSwapper;
+import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@SuppressWarnings({"unchecked", "rawtypes"})
+class ClusterYamlPersistRepositoryConfigurationSwapperTest {
+    
+    private final YamlPersistRepositoryConfigurationSwapper swapper = 
TypedSPILoader.getService(YamlPersistRepositoryConfigurationSwapper.class, 
"Cluster");
+    
+    @Test
+    void assertSwapToYamlConfiguration() {
+        YamlPersistRepositoryConfiguration actual = 
(YamlPersistRepositoryConfiguration) swapper.swapToYamlConfiguration(
+                new ClusterPersistRepositoryConfiguration("TEST", 
"foo_namespace", "localhost", PropertiesBuilder.build(new Property("key", 
"value"))));
+        assertThat(actual.getType(), is("TEST"));
+        assertThat(actual.getProps().getProperty("key"), is("value"));
+        assertThat(actual.getProps().getProperty("namespace"), 
is("foo_namespace"));
+        assertThat(actual.getProps().getProperty("server-lists"), 
is("localhost"));
+    }
+    
+    @Test
+    void assertSwapToObject() {
+        YamlPersistRepositoryConfiguration yamlConfig = new 
YamlPersistRepositoryConfiguration();
+        yamlConfig.setType("TEST");
+        yamlConfig.setProps(PropertiesBuilder.build(new Property("key", 
"value"), new Property("namespace", "foo_namespace"), new 
Property("server-lists", "localhost")));
+        ClusterPersistRepositoryConfiguration actual = 
(ClusterPersistRepositoryConfiguration) swapper.swapToObject(yamlConfig);
+        assertThat(actual.getType(), is("TEST"));
+        assertThat(actual.getNamespace(), is("foo_namespace"));
+        assertThat(actual.getServerLists(), is("localhost"));
+        assertThat(actual.getProps().getProperty("key"), is("value"));
+        assertThat(actual.getProps().getProperty("namespace"), 
is("foo_namespace"));
+        assertThat(actual.getProps().getProperty("server-lists"), 
is("localhost"));
+    }
+}
diff --git 
a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/yaml/StandaloneYamlPersistRepositoryConfigurationSwapperTest.java
 
b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/yaml/StandaloneYamlPersistRepositoryConfigurationSwapperTest.java
index 4fab0c0eb4e..1644ca139eb 100644
--- 
a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/yaml/StandaloneYamlPersistRepositoryConfigurationSwapperTest.java
+++ 
b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/yaml/StandaloneYamlPersistRepositoryConfigurationSwapperTest.java
@@ -17,7 +17,9 @@
 
 package org.apache.shardingsphere.mode.manager.standalone.yaml;
 
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.infra.yaml.config.pojo.mode.YamlPersistRepositoryConfiguration;
+import 
org.apache.shardingsphere.infra.yaml.config.swapper.mode.YamlPersistRepositoryConfigurationSwapper;
 import 
org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepositoryConfiguration;
 import org.junit.jupiter.api.Test;
 
@@ -26,22 +28,25 @@ import java.util.Properties;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 
+@SuppressWarnings({"unchecked", "rawtypes"})
 class StandaloneYamlPersistRepositoryConfigurationSwapperTest {
     
+    private final YamlPersistRepositoryConfigurationSwapper swapper = 
TypedSPILoader.getService(YamlPersistRepositoryConfigurationSwapper.class, 
"Standalone");
+    
     @Test
     void assertSwapToYamlConfiguration() {
         StandalonePersistRepositoryConfiguration 
standalonePersistRepositoryConfig = new 
StandalonePersistRepositoryConfiguration("TEST", new Properties());
-        YamlPersistRepositoryConfiguration actual = new 
StandaloneYamlPersistRepositoryConfigurationSwapper().swapToYamlConfiguration(standalonePersistRepositoryConfig);
-        assertThat(actual.getProps(), is(new Properties()));
+        YamlPersistRepositoryConfiguration actual = 
(YamlPersistRepositoryConfiguration) 
swapper.swapToYamlConfiguration(standalonePersistRepositoryConfig);
         assertThat(actual.getType(), is("TEST"));
+        assertThat(actual.getProps(), is(new Properties()));
     }
     
     @Test
     void assertSwapToObject() {
         YamlPersistRepositoryConfiguration yamlPersistRepositoryConfig = new 
YamlPersistRepositoryConfiguration();
         yamlPersistRepositoryConfig.setType("TEST");
-        StandalonePersistRepositoryConfiguration actual = new 
StandaloneYamlPersistRepositoryConfigurationSwapper().swapToObject(yamlPersistRepositoryConfig);
-        assertThat(actual.getProps(), is(new Properties()));
+        StandalonePersistRepositoryConfiguration actual = 
(StandalonePersistRepositoryConfiguration) 
swapper.swapToObject(yamlPersistRepositoryConfig);
         assertThat(actual.getType(), is("TEST"));
+        assertThat(actual.getProps(), is(new Properties()));
     }
 }

Reply via email to