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 869de07  Add more unit test for EncryptAlgorithmMetaData, EncryptRule 
and EncryptTable (#14630)
869de07 is described below

commit 869de0795a3641c27dc34565ac16627d559e00c2
Author: ZiSheng Zhou <[email protected]>
AuthorDate: Sun Jan 9 15:37:26 2022 +0800

    Add more unit test for EncryptAlgorithmMetaData, EncryptRule and 
EncryptTable (#14630)
    
    * Update EncryptAlgorithmMetaDataTest.java
    
    * Update EncryptRuleTest.java
    
    * Update EncryptTableTest.java
---
 .../encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java        | 10 ++++++++++
 .../apache/shardingsphere/encrypt/rule/EncryptRuleTest.java    | 10 ++++++++++
 .../apache/shardingsphere/encrypt/rule/EncryptTableTest.java   |  7 +++++++
 3 files changed, 27 insertions(+)

diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java
index 22fda95..bd84fc2 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptAlgorithmMetaDataTest.java
@@ -112,4 +112,14 @@ public final class EncryptAlgorithmMetaDataTest {
         Optional<EncryptAlgorithm> actualEncryptor = 
encryptAlgorithmMetaData.findEncryptor(1);
         assertFalse(actualEncryptor.isPresent());
     }
+    
+    @Test
+    public void assertIsQueryWithCipherColumn() {
+        Map<String, String> columnTableNames = new HashMap<>();
+        columnTableNames.put(columnProjection.getExpression(), "t_order");
+        
when(tablesContext.findTableName(Collections.singletonList(columnProjection), 
schema)).thenReturn(columnTableNames);
+        when(encryptRule.isQueryWithCipherColumn("t_order")).thenReturn(true);
+        EncryptAlgorithmMetaData encryptAlgorithmMetaData = new 
EncryptAlgorithmMetaData(schema, encryptRule, selectStatementContext);
+        assertTrue(encryptAlgorithmMetaData.isQueryWithCipherColumn(1));
+    }
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
index db94080..e11e634 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
@@ -141,6 +141,16 @@ public final class EncryptRuleTest {
     }
     
     @Test
+    public void assertIsQueryWithCipherColumn() {
+        EncryptColumnRuleConfiguration encryptColumnConfig = new 
EncryptColumnRuleConfiguration("encrypt_column", "encrypt_cipher", "", "", 
"test_encryptor");
+        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singletonList(encryptColumnConfig), true);
+        AlgorithmProvidedEncryptRuleConfiguration ruleConfig = new 
AlgorithmProvidedEncryptRuleConfiguration(
+                Collections.singleton(tableConfig), 
ImmutableMap.of("test_encryptor", new TestEncryptAlgorithm()), true);
+        EncryptRule actual = new EncryptRule(ruleConfig);
+        assertTrue(actual.isQueryWithCipherColumn("t_encrypt"));
+    }
+    
+    @Test
     public void assertGetTables() {
         assertThat(new 
EncryptRule(createEncryptRuleConfiguration()).getTables(), 
is(Collections.singleton("t_encrypt")));
     }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableTest.java
index 796363c..d97ff58 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableTest.java
@@ -121,4 +121,11 @@ public final class EncryptTableTest {
     public void assertGetLogicAndCipherColumns() {
         assertThat(encryptTable.getLogicAndCipherColumns(), 
is(ImmutableMap.of("logicColumn", "cipherColumn")));
     }
+    
+    @Test
+    public void assertGetQueryWithCipherColumn() {
+        encryptTable = new EncryptTable(new 
EncryptTableRuleConfiguration("t_encrypt",
+                Collections.singleton(new 
EncryptColumnRuleConfiguration("logicColumn", "cipherColumn", 
"assistedQueryColumn", "plainColumn", "myEncryptor")), true));
+        assertTrue(encryptTable.getQueryWithCipherColumn().get());
+    }
 }

Reply via email to