You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2021/07/28 07:35:36 UTC

[shardingsphere] branch master updated: Add unit test for DistMetaDataPersistRuleConfigurationYamlSwapper (#11548)

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

duanzhengqiang 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 9835def  Add unit test for DistMetaDataPersistRuleConfigurationYamlSwapper (#11548)
9835def is described below

commit 9835deff2f44aec33efec127ed128d8c74af282d
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Wed Jul 28 15:35:05 2021 +0800

    Add unit test for DistMetaDataPersistRuleConfigurationYamlSwapper (#11548)
---
 ...etaDataPersistRuleConfigurationYamlSwapper.java |  1 -
 ...ataPersistRuleConfigurationYamlSwapperTest.java | 77 ++++++++++++++++++++++
 2 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/persist/DistMetaDataPersistRuleConfigurationYamlSwapper.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/persist/DistMetaDataPersistRuleConfigurationYamlSwapper.java
index f4aedc5..65641f2 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/persist/DistMetaDataPersistRuleConfigurationYamlSwapper.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/persist/DistMetaDataPersistRuleConfigurationYamlSwapper.java
@@ -25,7 +25,6 @@ import org.apache.shardingsphere.infra.yaml.config.swapper.YamlRuleConfiguration
 /**
  * Dist meta data persist rule configuration YAML swapper.
  */
-// TODO add unit test for me
 public final class DistMetaDataPersistRuleConfigurationYamlSwapper implements 
         YamlRuleConfigurationSwapper<YamlDistMetaDataPersistRuleConfiguration, DistMetaDataPersistRuleConfiguration> {
     
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/persist/DistMetaDataPersistRuleConfigurationYamlSwapperTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/persist/DistMetaDataPersistRuleConfigurationYamlSwapperTest.java
new file mode 100644
index 0000000..b7fe033
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/persist/DistMetaDataPersistRuleConfigurationYamlSwapperTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.yaml.config.swapper.persist;
+
+import org.apache.shardingsphere.infra.constant.DistMetaDataPersistOrder;
+import org.apache.shardingsphere.infra.rule.persist.DistMetaDataPersistRuleConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.pojo.persist.YamlDistMetaDataPersistRuleConfiguration;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+public final class DistMetaDataPersistRuleConfigurationYamlSwapperTest {
+    
+    private final DistMetaDataPersistRuleConfigurationYamlSwapper swapper = new DistMetaDataPersistRuleConfigurationYamlSwapper();
+    
+    @Test
+    public void assertGetOrder() {
+        assertThat(swapper.getOrder(), is(DistMetaDataPersistOrder.ORDER));
+    }
+    
+    @Test
+    public void assertGetTypeClass() {
+        assertThat(swapper.getTypeClass(), equalTo(DistMetaDataPersistRuleConfiguration.class));
+    }
+    
+    @Test
+    public void assertSwapToYamlConfiguration() {
+        DistMetaDataPersistRuleConfiguration distMetaDataPersistRuleConfiguration = 
+                new DistMetaDataPersistRuleConfiguration("Local", buildProperties());
+        YamlDistMetaDataPersistRuleConfiguration actual = swapper.swapToYamlConfiguration(distMetaDataPersistRuleConfiguration);
+        assertNotNull(actual);
+        assertThat(actual.getType(), is("Local"));
+        assertThat(actual.getProps().get("path"), is("test"));
+    }
+    
+    @Test
+    public void assertSwapToObject() {
+        YamlDistMetaDataPersistRuleConfiguration yamlConfig = new YamlDistMetaDataPersistRuleConfiguration();
+        yamlConfig.setType("Local");
+        yamlConfig.setProps(buildProperties());
+        DistMetaDataPersistRuleConfiguration actual = swapper.swapToObject(yamlConfig);
+        assertNotNull(actual);
+        assertThat(actual.getType(), is("Local"));
+        assertThat(actual.getProps().get("path"), is("test"));
+    }
+    
+    @Test
+    public void assertGetRuleTagName() {
+        assertThat(swapper.getRuleTagName(), is("DIST_METADATA_PERSIST"));
+    }
+    
+    private Properties buildProperties() {
+        Properties result = new Properties();
+        result.setProperty("path", "test");
+        return result;
+    }
+}