You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2020/08/13 08:29:06 UTC

[shardingsphere] branch master updated: Add test case for EncryptMetaDataDecorator (#6818)

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

panjuan 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 8dac26a  Add test case for EncryptMetaDataDecorator (#6818)
8dac26a is described below

commit 8dac26aff8efcc641b04097263b82f7de41d6d09
Author: Liang Zhang <te...@163.com>
AuthorDate: Thu Aug 13 16:28:43 2020 +0800

    Add test case for EncryptMetaDataDecorator (#6818)
---
 .../metadata/EncryptMetaDataDecoratorTest.java     | 67 ++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataDecoratorTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataDecoratorTest.java
new file mode 100644
index 0000000..9a61774
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataDecoratorTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+import org.apache.shardingsphere.encrypt.rule.EncryptRule;
+import org.apache.shardingsphere.infra.metadata.schema.spi.RuleMetaDataDecorator;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.order.OrderedSPIRegistry;
+import org.apache.shardingsphere.sql.parser.binder.metadata.column.ColumnMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class EncryptMetaDataDecoratorTest {
+    
+    static {
+        ShardingSphereServiceLoader.register(RuleMetaDataDecorator.class);
+    }
+    
+    @Test
+    public void assertDecorate() {
+        EncryptRule rule = createEncryptRule();
+        EncryptMetaDataDecorator decorator = (EncryptMetaDataDecorator) OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(rule), RuleMetaDataDecorator.class).get(rule);
+        TableMetaData actual = decorator.decorate("t_encrypt", createTableMetaData(), rule);
+        assertThat(actual.getColumns().size(), is(2));
+        assertTrue(actual.getColumns().containsKey("id"));
+        assertTrue(actual.getColumns().containsKey("pwd"));
+    }
+    
+    private EncryptRule createEncryptRule() {
+        EncryptRule result = mock(EncryptRule.class);
+        when(result.getLogicColumnOfCipher("t_encrypt", "pwd_cipher")).thenReturn("pwd");
+        when(result.isCipherColumn("t_encrypt", "pwd_cipher")).thenReturn(true);
+        when(result.getAssistedQueryAndPlainColumns("t_encrypt")).thenReturn(Collections.singletonList("pwd_plain"));
+        return result;
+    }
+    
+    private TableMetaData createTableMetaData() {
+        Collection<ColumnMetaData> columns = Arrays.asList(new ColumnMetaData("id", 1, "int", true, true, true), 
+                new ColumnMetaData("pwd_cipher", 2, "varchar", false, false, true), new ColumnMetaData("pwd_plain", 2, "varchar", false, false, true));
+        return new TableMetaData(columns, Collections.emptyList());
+    }
+}