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 a16be980376 Add global swapToYamlRuleConfiguration test cases on 
RepositoryTupleSwapperEngine (#32463)
a16be980376 is described below

commit a16be9803760c007d7b76c908b0e75ed572dd00d
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Aug 11 11:45:16 2024 +0800

    Add global swapToYamlRuleConfiguration test cases on 
RepositoryTupleSwapperEngine (#32463)
---
 .../tuple/RepositoryTupleSwapperEngineTest.java    | 24 +++++++++++++
 .../leaf/GlobalLeafYamlRuleConfiguration.java      | 41 ++++++++++++++++++++++
 2 files changed, 65 insertions(+)

diff --git 
a/mode/api/src/test/java/org/apache/shardingsphere/mode/tuple/RepositoryTupleSwapperEngineTest.java
 
b/mode/api/src/test/java/org/apache/shardingsphere/mode/tuple/RepositoryTupleSwapperEngineTest.java
index a8aa753b3e1..084141b558f 100644
--- 
a/mode/api/src/test/java/org/apache/shardingsphere/mode/tuple/RepositoryTupleSwapperEngineTest.java
+++ 
b/mode/api/src/test/java/org/apache/shardingsphere/mode/tuple/RepositoryTupleSwapperEngineTest.java
@@ -17,6 +17,8 @@
 
 package org.apache.shardingsphere.mode.tuple;
 
+import 
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
+import 
org.apache.shardingsphere.mode.tuple.fixture.leaf.GlobalLeafYamlRuleConfiguration;
 import 
org.apache.shardingsphere.mode.tuple.fixture.leaf.LeafYamlRuleConfiguration;
 import 
org.apache.shardingsphere.mode.tuple.fixture.node.NodeYamlRuleConfiguration;
 import 
org.apache.shardingsphere.mode.tuple.fixture.node.NodeYamlRuleConfigurationEnum;
@@ -27,9 +29,11 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Optional;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class RepositoryTupleSwapperEngineTest {
@@ -89,4 +93,24 @@ class RepositoryTupleSwapperEngineTest {
         assertThat(actual.get(8).getKey(), is("gens/gen: value"));
         assertThat(actual.get(8).getValue(), is("value"));
     }
+    
+    @Test
+    void 
assertSwapToYamlRuleConfigurationWithoutRepositoryTupleEntityAnnotation() {
+        assertFalse(new 
RepositoryTupleSwapperEngine().swapToYamlRuleConfiguration(Collections.emptyList(),
 NoneYamlRuleConfiguration.class).isPresent());
+    }
+    
+    @Test
+    void 
assertSwapToYamlRuleConfigurationWithoutGlobalLeafYamlRuleConfiguration() {
+        assertFalse(new 
RepositoryTupleSwapperEngine().swapToYamlRuleConfiguration(
+                Collections.singleton(new 
RepositoryTuple("/rules/invalid/versions/0", "value: foo" + 
System.lineSeparator())), GlobalLeafYamlRuleConfiguration.class).isPresent());
+    }
+    
+    @Test
+    void 
assertSwapToYamlRuleConfigurationWithGlobalLeafYamlRuleConfiguration() {
+        Optional<YamlRuleConfiguration> actual = new 
RepositoryTupleSwapperEngine().swapToYamlRuleConfiguration(
+                Collections.singleton(new 
RepositoryTuple("/rules/leaf/versions/0", "value: foo" + 
System.lineSeparator())), GlobalLeafYamlRuleConfiguration.class);
+        assertTrue(actual.isPresent());
+        GlobalLeafYamlRuleConfiguration actualYamlConfig = 
(GlobalLeafYamlRuleConfiguration) actual.get();
+        assertThat(actualYamlConfig.getValue(), is("foo"));
+    }
 }
diff --git 
a/mode/api/src/test/java/org/apache/shardingsphere/mode/tuple/fixture/leaf/GlobalLeafYamlRuleConfiguration.java
 
b/mode/api/src/test/java/org/apache/shardingsphere/mode/tuple/fixture/leaf/GlobalLeafYamlRuleConfiguration.java
new file mode 100644
index 00000000000..64c993e0c57
--- /dev/null
+++ 
b/mode/api/src/test/java/org/apache/shardingsphere/mode/tuple/fixture/leaf/GlobalLeafYamlRuleConfiguration.java
@@ -0,0 +1,41 @@
+/*
+ * 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.tuple.fixture.leaf;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import 
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlGlobalRuleConfiguration;
+import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleEntity;
+
+@RepositoryTupleEntity(value = "leaf", leaf = true)
+@AllArgsConstructor
+@NoArgsConstructor
+@Getter
+@Setter
+public final class GlobalLeafYamlRuleConfiguration implements 
YamlGlobalRuleConfiguration {
+    
+    private String value;
+    
+    @Override
+    public Class<? extends RuleConfiguration> getRuleConfigurationType() {
+        return RuleConfiguration.class;
+    }
+}

Reply via email to