You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by yx...@apache.org on 2024/05/01 16:36:43 UTC

(shardingsphere) branch master updated: Add AuthorityRuleConfigurationRepositoryTupleSwapperIT (#31093)

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

yx9o 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 2d38ee23165 Add AuthorityRuleConfigurationRepositoryTupleSwapperIT (#31093)
2d38ee23165 is described below

commit 2d38ee231659bf90975aa3a1c6dba68ec959cc60
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu May 2 00:36:37 2024 +0800

    Add AuthorityRuleConfigurationRepositoryTupleSwapperIT (#31093)
    
    * Add AuthorityRuleConfigurationRepositoryTupleSwapperIT
    
    * Add AuthorityRuleConfigurationRepositoryTupleSwapperIT
---
 ...tRuleConfigurationRepositoryTupleSwapperIT.java |  4 +-
 .../BroadcastRuleConfigurationYamlIT.java          |  2 +-
 ...uleConfigurationRepositoryTupleSwapperTest.java | 64 ------------------
 kernel/authority/core/pom.xml                      |  6 ++
 ...yRuleConfigurationRepositoryTupleSwapperIT.java | 19 +++---
 .../it/AuthorityRuleConfigurationYamlIT.java       | 77 ++++++++++++++++++++++
 ...uleConfigurationRepositoryTupleSwapperTest.java | 57 ----------------
 .../src/test/resources/yaml/authority-rule.yaml    | 32 +++++++++
 .../test/it/yaml/RepositoryTupleSwapperIT.java     | 14 +++-
 9 files changed, 139 insertions(+), 136 deletions(-)

diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/BroadcastRuleConfigurationRepositoryTupleSwapperIT.java b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/it/BroadcastRuleConfigurationRepositoryTupleSwapperIT.java
similarity index 95%
copy from features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/BroadcastRuleConfigurationRepositoryTupleSwapperIT.java
copy to features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/it/BroadcastRuleConfigurationRepositoryTupleSwapperIT.java
index 75b17e6c6ca..1f8589faca1 100644
--- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/BroadcastRuleConfigurationRepositoryTupleSwapperIT.java
+++ b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/it/BroadcastRuleConfigurationRepositoryTupleSwapperIT.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.broadcast.yaml;
+package org.apache.shardingsphere.broadcast.it;
 
 import org.apache.shardingsphere.broadcast.yaml.swapper.BroadcastRuleConfigurationRepositoryTupleSwapper;
 import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
@@ -30,7 +30,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
 class BroadcastRuleConfigurationRepositoryTupleSwapperIT extends RepositoryTupleSwapperIT {
     
     BroadcastRuleConfigurationRepositoryTupleSwapperIT() {
-        super("yaml/broadcast-rule.yaml", new BroadcastRuleConfigurationRepositoryTupleSwapper());
+        super("yaml/broadcast-rule.yaml", new BroadcastRuleConfigurationRepositoryTupleSwapper(), false);
     }
     
     @Override
diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/BroadcastRuleConfigurationYamlIT.java b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/it/BroadcastRuleConfigurationYamlIT.java
similarity index 97%
rename from features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/BroadcastRuleConfigurationYamlIT.java
rename to features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/it/BroadcastRuleConfigurationYamlIT.java
index 6c983e5dc01..c262a8caa3f 100644
--- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/BroadcastRuleConfigurationYamlIT.java
+++ b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/it/BroadcastRuleConfigurationYamlIT.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.broadcast.yaml;
+package org.apache.shardingsphere.broadcast.it;
 
 import org.apache.shardingsphere.broadcast.yaml.config.YamlBroadcastRuleConfiguration;
 import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapperTest.java b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapperTest.java
deleted file mode 100644
index 4252ef09a37..00000000000
--- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapperTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.broadcast.yaml.swapper;
-
-import org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
-import org.apache.shardingsphere.broadcast.yaml.config.YamlBroadcastRuleConfiguration;
-import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
-import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class BroadcastRuleConfigurationRepositoryTupleSwapperTest {
-    
-    private final BroadcastRuleConfigurationRepositoryTupleSwapper swapper = new BroadcastRuleConfigurationRepositoryTupleSwapper();
-    
-    @Test
-    void assertSwapToRepositoryTuplesWithEmptyRule() {
-        assertTrue(swapper.swapToRepositoryTuples(new YamlBroadcastRuleConfiguration()).isEmpty());
-    }
-    
-    @Test
-    void assertSwapToRepositoryTuples() {
-        BroadcastRuleConfiguration ruleConfig = new BroadcastRuleConfiguration(Arrays.asList("foo_table", "foo_table2"));
-        Collection<RepositoryTuple> actual = swapper.swapToRepositoryTuples((YamlBroadcastRuleConfiguration) new YamlRuleConfigurationSwapperEngine().swapToYamlRuleConfiguration(ruleConfig));
-        assertThat(actual.size(), is(1));
-        Iterator<RepositoryTuple> iterator = actual.iterator();
-        assertThat(iterator.next().getKey(), is("tables"));
-    }
-    
-    @Test
-    void assertSwapToObject() {
-        RepositoryTuple repositoryTuple = new RepositoryTuple("/metadata/foo_db/rules/broadcast/tables/versions/0", "\n- foo_table\n- foo_table2\n");
-        Optional<YamlBroadcastRuleConfiguration> actual = swapper.swapToObject(Collections.singleton(repositoryTuple));
-        assertTrue(actual.isPresent());
-        assertThat(actual.get().getTables().size(), is(2));
-        Iterator<String> iterator = actual.get().getTables().iterator();
-        assertThat(iterator.next(), is("foo_table"));
-        assertThat(iterator.next(), is("foo_table2"));
-    }
-}
diff --git a/kernel/authority/core/pom.xml b/kernel/authority/core/pom.xml
index 2e835b78cf8..bfb1ecffef3 100644
--- a/kernel/authority/core/pom.xml
+++ b/kernel/authority/core/pom.xml
@@ -49,5 +49,11 @@
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-test-it-yaml</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/BroadcastRuleConfigurationRepositoryTupleSwapperIT.java b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/it/AuthorityRuleConfigurationRepositoryTupleSwapperIT.java
similarity index 62%
rename from features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/BroadcastRuleConfigurationRepositoryTupleSwapperIT.java
rename to kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/it/AuthorityRuleConfigurationRepositoryTupleSwapperIT.java
index 75b17e6c6ca..ed0bd76fe07 100644
--- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/BroadcastRuleConfigurationRepositoryTupleSwapperIT.java
+++ b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/it/AuthorityRuleConfigurationRepositoryTupleSwapperIT.java
@@ -15,9 +15,9 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.broadcast.yaml;
+package org.apache.shardingsphere.authority.it;
 
-import org.apache.shardingsphere.broadcast.yaml.swapper.BroadcastRuleConfigurationRepositoryTupleSwapper;
+import org.apache.shardingsphere.authority.yaml.swapper.AuthorityRuleConfigurationRepositoryTupleSwapper;
 import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
 import org.apache.shardingsphere.test.it.yaml.RepositoryTupleSwapperIT;
 
@@ -27,21 +27,22 @@ import java.util.Iterator;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 
-class BroadcastRuleConfigurationRepositoryTupleSwapperIT extends RepositoryTupleSwapperIT {
+class AuthorityRuleConfigurationRepositoryTupleSwapperIT extends RepositoryTupleSwapperIT {
     
-    BroadcastRuleConfigurationRepositoryTupleSwapperIT() {
-        super("yaml/broadcast-rule.yaml", new BroadcastRuleConfigurationRepositoryTupleSwapper());
+    AuthorityRuleConfigurationRepositoryTupleSwapperIT() {
+        super("yaml/authority-rule.yaml", new AuthorityRuleConfigurationRepositoryTupleSwapper(), true);
     }
     
     @Override
     protected void assertRepositoryTuples(final Collection<RepositoryTuple> actualRepositoryTuples) {
         assertThat(actualRepositoryTuples.size(), is(1));
         Iterator<RepositoryTuple> iterator = actualRepositoryTuples.iterator();
-        assertTables(iterator.next());
+        assertAuthority(iterator.next());
     }
     
-    private void assertTables(final RepositoryTuple actual) {
-        assertThat(actual.getKey(), is("tables"));
-        assertThat(actual.getValue(), is("- foo_tbl\n- bar_tbl\n"));
+    private void assertAuthority(final RepositoryTuple actual) {
+        assertThat(actual.getKey(), is("authority"));
+        assertThat(actual.getValue(), is("authenticators:\n  fixture:\n    type: FIXTURE\ndefaultAuthenticator: fixture\nprivilege:\n  type: ALL_PERMITTED\n"
+                + "users:\n- admin: true\n  password: root\n  user: root@%\n- admin: false\n  password: sharding\n  user: sharding@\n"));
     }
 }
diff --git a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/it/AuthorityRuleConfigurationYamlIT.java b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/it/AuthorityRuleConfigurationYamlIT.java
new file mode 100644
index 00000000000..4024890cc50
--- /dev/null
+++ b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/it/AuthorityRuleConfigurationYamlIT.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.authority.it;
+
+import org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration;
+import org.apache.shardingsphere.authority.yaml.config.YamlUserConfiguration;
+import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
+import org.apache.shardingsphere.test.it.yaml.YamlRuleConfigurationIT;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+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 AuthorityRuleConfigurationYamlIT extends YamlRuleConfigurationIT {
+    
+    AuthorityRuleConfigurationYamlIT() {
+        super("yaml/authority-rule.yaml");
+    }
+    
+    @Override
+    protected void assertYamlRootConfiguration(final YamlRootConfiguration actual) {
+        assertAuthorityRule((YamlAuthorityRuleConfiguration) actual.getRules().iterator().next());
+    }
+    
+    private void assertAuthorityRule(final YamlAuthorityRuleConfiguration actual) {
+        assertUsers(new ArrayList<>(actual.getUsers()));
+        assertPrivilege(actual.getPrivilege());
+        assertAuthenticators(actual.getAuthenticators());
+        assertDefaultAuthenticator(actual.getDefaultAuthenticator());
+    }
+    
+    private void assertUsers(final List<YamlUserConfiguration> actual) {
+        assertThat(actual.size(), is(2));
+        assertThat(actual.get(0).getUser(), is("root@%"));
+        assertThat(actual.get(0).getPassword(), is("root"));
+        assertTrue(actual.get(0).isAdmin());
+        assertThat(actual.get(1).getUser(), is("sharding@"));
+        assertThat(actual.get(1).getPassword(), is("sharding"));
+        assertFalse(actual.get(1).isAdmin());
+    }
+    
+    private void assertPrivilege(final YamlAlgorithmConfiguration actual) {
+        assertThat(actual.getType(), is("ALL_PERMITTED"));
+        assertTrue(actual.getProps().isEmpty());
+    }
+    
+    private void assertAuthenticators(final Map<String, YamlAlgorithmConfiguration> actual) {
+        assertThat(actual.size(), is(1));
+        assertThat(actual.get("fixture").getType(), is("FIXTURE"));
+        assertTrue(actual.get("fixture").getProps().isEmpty());
+    }
+    
+    private void assertDefaultAuthenticator(final String actual) {
+        assertThat(actual, is("fixture"));
+    }
+}
diff --git a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationRepositoryTupleSwapperTest.java b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationRepositoryTupleSwapperTest.java
deleted file mode 100644
index 802198f485f..00000000000
--- a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationRepositoryTupleSwapperTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.authority.yaml.swapper;
-
-import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
-import org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration;
-import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
-import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-class AuthorityRuleConfigurationRepositoryTupleSwapperTest {
-    
-    private final AuthorityRuleConfigurationRepositoryTupleSwapper swapper = new AuthorityRuleConfigurationRepositoryTupleSwapper();
-    
-    @Test
-    void assertSwapToRepositoryTuples() {
-        Collection<ShardingSphereUser> users = Collections.singleton(new ShardingSphereUser("root", "", "localhost"));
-        AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration(users, new AlgorithmConfiguration("ALL_PERMITTED", new Properties()),
-                Collections.singletonMap("md5", new AlgorithmConfiguration("MD5", PropertiesBuilder.build(new Property("proxy-frontend-database-protocol-type", "openGauss")))), "scram_sha256");
-        Collection<RepositoryTuple> actual = swapper.swapToRepositoryTuples((YamlAuthorityRuleConfiguration) new YamlRuleConfigurationSwapperEngine().swapToYamlRuleConfiguration(ruleConfig));
-        RepositoryTuple repositoryTuple = actual.iterator().next();
-        assertThat(repositoryTuple.getKey(), is("authority"));
-        assertThat(repositoryTuple.getValue(), containsString("user: root@localhost"));
-        assertThat(repositoryTuple.getValue(), containsString("password: ''"));
-        assertThat(repositoryTuple.getValue(), containsString("type: ALL_PERMITTED"));
-        assertThat(repositoryTuple.getValue(), containsString("defaultAuthenticator: scram_sha256"));
-        assertThat(repositoryTuple.getValue(), containsString("type: MD5"));
-        assertThat(repositoryTuple.getValue(), containsString("proxy-frontend-database-protocol-type: openGauss"));
-    }
-}
diff --git a/kernel/authority/core/src/test/resources/yaml/authority-rule.yaml b/kernel/authority/core/src/test/resources/yaml/authority-rule.yaml
new file mode 100644
index 00000000000..b77dd0324c5
--- /dev/null
+++ b/kernel/authority/core/src/test/resources/yaml/authority-rule.yaml
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+
+rules:
+- !AUTHORITY
+  authenticators:
+    fixture:
+      type: FIXTURE
+  defaultAuthenticator: fixture
+  privilege:
+    type: ALL_PERMITTED
+  users:
+  - admin: true
+    password: root
+    user: root@%
+  - admin: false
+    password: sharding
+    user: sharding@
diff --git a/test/it/yaml/src/main/java/org/apache/shardingsphere/test/it/yaml/RepositoryTupleSwapperIT.java b/test/it/yaml/src/main/java/org/apache/shardingsphere/test/it/yaml/RepositoryTupleSwapperIT.java
index bd37d7ad889..5ff294a59e3 100644
--- a/test/it/yaml/src/main/java/org/apache/shardingsphere/test/it/yaml/RepositoryTupleSwapperIT.java
+++ b/test/it/yaml/src/main/java/org/apache/shardingsphere/test/it/yaml/RepositoryTupleSwapperIT.java
@@ -45,12 +45,15 @@ public abstract class RepositoryTupleSwapperIT {
     @SuppressWarnings("rawtypes")
     private final RepositoryTupleSwapper swapper;
     
+    private final boolean isGlobalRule;
+    
     @SuppressWarnings("rawtypes")
-    public RepositoryTupleSwapperIT(final String yamlFileName, final RepositoryTupleSwapper swapper) {
+    public RepositoryTupleSwapperIT(final String yamlFileName, final RepositoryTupleSwapper swapper, final boolean isGlobalRule) {
         URL url = Thread.currentThread().getContextClassLoader().getResource(yamlFileName);
         assertNotNull(url);
         yamlFile = new File(url.getFile());
         this.swapper = swapper;
+        this.isGlobalRule = isGlobalRule;
     }
     
     @Test
@@ -74,8 +77,7 @@ public abstract class RepositoryTupleSwapperIT {
     
     @SuppressWarnings("unchecked")
     private String getActualYamlContent() throws IOException {
-        Collection<RepositoryTuple> repositoryTuples = getRepositoryTuples().stream()
-                .map(each -> new RepositoryTuple(String.format("/metadata/foo_db/rules/%s/%s/versions/0", swapper.getRuleTypeName(), each.getKey()), each.getValue())).collect(Collectors.toList());
+        Collection<RepositoryTuple> repositoryTuples = getRepositoryTuples().stream().map(each -> new RepositoryTuple(getRepositoryTupleKey(each), each.getValue())).collect(Collectors.toList());
         Optional<YamlRuleConfiguration> actualYamlRuleConfig = swapper.swapToObject(repositoryTuples);
         assertTrue(actualYamlRuleConfig.isPresent());
         YamlRootConfiguration yamlRootConfig = new YamlRootConfiguration();
@@ -83,6 +85,12 @@ public abstract class RepositoryTupleSwapperIT {
         return YamlEngine.marshal(yamlRootConfig);
     }
     
+    private String getRepositoryTupleKey(final RepositoryTuple tuple) {
+        return isGlobalRule
+                ? String.format("/metadata/rules/%s/versions/0", swapper.getRuleTypeName())
+                : String.format("/metadata/foo_db/rules/%s/%s/versions/0", swapper.getRuleTypeName(), tuple.getKey());
+    }
+    
     private String getExpectedYamlContent() throws IOException {
         return Files.readAllLines(yamlFile.toPath()).stream().filter(each -> !each.contains("#") && !each.isEmpty()).collect(Collectors.joining(System.lineSeparator())) + System.lineSeparator();
     }