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 2024/11/14 10:18:04 UTC

(shardingsphere) branch master updated: Add test cases on EncryptIndexReviser (#33663)

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 3c70a8c3000 Add test cases on EncryptIndexReviser (#33663)
3c70a8c3000 is described below

commit 3c70a8c300055e9ba1f312dcfbee17880e595d56
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Nov 14 18:17:58 2024 +0800

    Add test cases on EncryptIndexReviser (#33663)
    
    * Refactor IndexReviseEngineTest
    
    * Add test cases on EncryptIndexReviser
---
 .../reviser/index/EncryptIndexReviserTest.java     | 59 ++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/metadata/reviser/index/EncryptIndexReviserTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/metadata/reviser/index/EncryptIndexReviserTest.java
new file mode 100644
index 00000000000..696e5c89779
--- /dev/null
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/metadata/reviser/index/EncryptIndexReviserTest.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.encrypt.metadata.reviser.index;
+
+import org.apache.shardingsphere.encrypt.rule.EncryptRule;
+import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
+import org.apache.shardingsphere.infra.database.core.metadata.data.model.IndexMetaData;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+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;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class EncryptIndexReviserTest {
+    
+    @Test
+    void assertReviseWithEmptyColumn() {
+        assertFalse(new EncryptIndexReviser(mock(EncryptTable.class)).revise("foo_tbl", new IndexMetaData("name"), mock(EncryptRule.class)).isPresent());
+    }
+    
+    @Test
+    void assertReviseWithColumns() {
+        Optional<IndexMetaData> indexMetaData = new EncryptIndexReviser(mockEncryptTable())
+                .revise("foo_tbl", new IndexMetaData("name", Arrays.asList("cipher_col", "assisted_col", "other_col")), mock(EncryptRule.class));
+        assertTrue(indexMetaData.isPresent());
+        assertThat(indexMetaData.get().getColumns(), is(new LinkedHashSet<>(Arrays.asList("col_1", "col_2", "other_col"))));
+    }
+    
+    private EncryptTable mockEncryptTable() {
+        EncryptTable result = mock(EncryptTable.class);
+        when(result.isCipherColumn("cipher_col")).thenReturn(true);
+        when(result.getLogicColumnByCipherColumn("cipher_col")).thenReturn("col_1");
+        when(result.isAssistedQueryColumn("assisted_col")).thenReturn(true);
+        when(result.getLogicColumnByAssistedQueryColumn("assisted_col")).thenReturn("col_2");
+        return result;
+    }
+}