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 0cac776  Add more test case for EncryptRule (#6829)
0cac776 is described below

commit 0cac7762f763ca1a2fb18ef9841ed4a246598b83
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Aug 13 20:46:23 2020 +0800

    Add more test case for EncryptRule (#6829)
    
    * Unify rule builder's package
    
    * Remove useless EncryptRule.getLogicAndPlainColumns
    
    * Add more test case for EncryptRule
    
    * Add more test case for EncryptRule
    
    * Refactor EncryptRuleTest
---
 .../shardingsphere/encrypt/rule/EncryptRule.java   | 159 ++++++++++-----------
 .../encrypt/fixture/TestEncryptAlgorithm.java      |   2 +-
 .../fixture/TestQueryAssistedEncryptAlgorithm.java |   2 +-
 .../encrypt/rule/EncryptRuleTest.java              | 122 +++++++++-------
 4 files changed, 148 insertions(+), 137 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
index b5d9c98..4bcb8da 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java
@@ -107,6 +107,15 @@ public final class EncryptRule implements 
ShardingSphereRule {
     }
     
     /**
+     * Get encrypt table names.
+     *
+     * @return encrypt table names
+     */
+    public Collection<String> getEncryptTableNames() {
+        return tables.keySet();
+    }
+    
+    /**
      * Find encrypt table.
      * 
      * @param logicTable logic table
@@ -117,46 +126,28 @@ public final class EncryptRule implements 
ShardingSphereRule {
     }
     
     /**
-     * Get logic column of cipher column.
-     *
-     * @param logicTable logic table
-     * @param cipherColumn cipher column
-     * @return logic column
-     */
-    public String getLogicColumnOfCipher(final String logicTable, final String 
cipherColumn) {
-        return tables.get(logicTable).getLogicColumnOfCipher(cipherColumn);
-    }
-    
-    /**
-     * Find plain column.
+     * Find encryptor.
      *
      * @param logicTable logic table name
      * @param logicColumn logic column name
-     * @return plain column
+     * @return encryptor
      */
-    public Optional<String> findPlainColumn(final String logicTable, final 
String logicColumn) {
-        Optional<String> originColumnName = findOriginColumnName(logicTable, 
logicColumn);
-        return originColumnName.isPresent() && tables.containsKey(logicTable) 
? tables.get(logicTable).findPlainColumn(originColumnName.get()) : 
Optional.empty();
-    }
-
-    private Optional<String> findOriginColumnName(final String logicTable, 
final String logicColumn) {
-        for (String each : tables.get(logicTable).getLogicColumns()) {
-            if (logicColumn.equalsIgnoreCase(each)) {
-                return Optional.of(each);
-            }
-        }
-        return Optional.empty();
+    public Optional<EncryptAlgorithm> findEncryptor(final String logicTable, 
final String logicColumn) {
+        return tables.containsKey(logicTable) ? 
tables.get(logicTable).findEncryptorName(logicColumn).map(encryptors::get) : 
Optional.empty();
     }
     
     /**
-     * Get cipher column.
+     * get encrypt values.
      *
-     * @param logicTable logic table name
-     * @param logicColumn logic column name
-     * @return cipher column
+     * @param logicTable logic table
+     * @param logicColumn logic column
+     * @param originalValues original values
+     * @return encrypt values
      */
-    public String getCipherColumn(final String logicTable, final String 
logicColumn) {
-        return tables.get(logicTable).getCipherColumn(logicColumn);
+    public List<Object> getEncryptValues(final String logicTable, final String 
logicColumn, final List<Object> originalValues) {
+        Optional<EncryptAlgorithm> encryptor = findEncryptor(logicTable, 
logicColumn);
+        Preconditions.checkArgument(encryptor.isPresent(), String.format("Can 
not find QueryAssistedEncryptAlgorithm by %s.%s.", logicTable, logicColumn));
+        return originalValues.stream().map(input -> null == input ? null : 
String.valueOf(encryptor.get().encrypt(input.toString()))).collect(Collectors.toList());
     }
     
     /**
@@ -171,41 +162,25 @@ public final class EncryptRule implements 
ShardingSphereRule {
     }
     
     /**
-     * Find assisted query column.
+     * Get cipher column.
      *
      * @param logicTable logic table name
-     * @param logicColumn column name
-     * @return assisted query column
-     */
-    public Optional<String> findAssistedQueryColumn(final String logicTable, 
final String logicColumn) {
-        return tables.containsKey(logicTable) ? 
tables.get(logicTable).findAssistedQueryColumn(logicColumn) : Optional.empty();
-    }
-    
-    /**
-     * Get assisted query columns.
-     * 
-     * @param logicTable logic table
-     * @return assisted query columns
+     * @param logicColumn logic column name
+     * @return cipher column
      */
-    public Collection<String> getAssistedQueryColumns(final String logicTable) 
{
-        return tables.containsKey(logicTable) ? 
tables.get(logicTable).getAssistedQueryColumns() : Collections.emptyList();
+    public String getCipherColumn(final String logicTable, final String 
logicColumn) {
+        return tables.get(logicTable).getCipherColumn(logicColumn);
     }
     
     /**
-     * Get assisted query and plain columns.
+     * Get logic column of cipher column.
      *
-     * @param logicTable logic table name
-     * @return assisted query and plain columns
+     * @param logicTable logic table
+     * @param cipherColumn cipher column
+     * @return logic column
      */
-    public Collection<String> getAssistedQueryAndPlainColumns(final String 
logicTable) {
-        Collection<String> result = new LinkedList<>();
-        result.addAll(getAssistedQueryColumns(logicTable));
-        result.addAll(getPlainColumns(logicTable));
-        return result;
-    }
-    
-    private Collection<String> getPlainColumns(final String logicTable) {
-        return tables.containsKey(logicTable) ? 
tables.get(logicTable).getPlainColumns() : Collections.emptyList();
+    public String getLogicColumnOfCipher(final String logicTable, final String 
cipherColumn) {
+        return tables.get(logicTable).getLogicColumnOfCipher(cipherColumn);
     }
     
     /**
@@ -219,13 +194,24 @@ public final class EncryptRule implements 
ShardingSphereRule {
     }
     
     /**
-     * Get logic and plain columns.
+     * Find assisted query column.
      *
-     * @param logicTable logic table 
-     * @return logic and plain columns
+     * @param logicTable logic table name
+     * @param logicColumn column name
+     * @return assisted query column
      */
-    public Map<String, String> getLogicAndPlainColumns(final String 
logicTable) {
-        return tables.containsKey(logicTable) ? 
tables.get(logicTable).getLogicAndPlainColumns() : Collections.emptyMap();
+    public Optional<String> findAssistedQueryColumn(final String logicTable, 
final String logicColumn) {
+        return tables.containsKey(logicTable) ? 
tables.get(logicTable).findAssistedQueryColumn(logicColumn) : Optional.empty();
+    }
+    
+    /**
+     * Get assisted query columns.
+     * 
+     * @param logicTable logic table
+     * @return assisted query columns
+     */
+    public Collection<String> getAssistedQueryColumns(final String logicTable) 
{
+        return tables.containsKey(logicTable) ? 
tables.get(logicTable).getAssistedQueryColumns() : Collections.emptyList();
     }
     
     /**
@@ -245,39 +231,40 @@ public final class EncryptRule implements 
ShardingSphereRule {
     }
     
     /**
-     * get encrypt values.
+     * Get assisted query and plain columns.
      *
-     * @param logicTable logic table
-     * @param logicColumn logic column
-     * @param originalValues original values
-     * @return encrypt values
+     * @param logicTable logic table name
+     * @return assisted query and plain columns
      */
-    public List<Object> getEncryptValues(final String logicTable, final String 
logicColumn, final List<Object> originalValues) {
-        Optional<EncryptAlgorithm> encryptor = findEncryptor(logicTable, 
logicColumn);
-        Preconditions.checkArgument(encryptor.isPresent(), String.format("Can 
not find QueryAssistedEncryptAlgorithm by %s.%s.", logicTable, logicColumn));
-        return originalValues.stream().map(input -> null == input ? null : 
String.valueOf(encryptor.get().encrypt(input.toString()))).collect(Collectors.toList());
+    public Collection<String> getAssistedQueryAndPlainColumns(final String 
logicTable) {
+        Collection<String> result = new LinkedList<>();
+        result.addAll(getAssistedQueryColumns(logicTable));
+        result.addAll(getPlainColumns(logicTable));
+        return result;
+    }
+    
+    private Collection<String> getPlainColumns(final String logicTable) {
+        return tables.containsKey(logicTable) ? 
tables.get(logicTable).getPlainColumns() : Collections.emptyList();
     }
     
     /**
-     * Find encryptor.
+     * Find plain column.
      *
      * @param logicTable logic table name
      * @param logicColumn logic column name
-     * @return encryptor
+     * @return plain column
      */
-    public Optional<EncryptAlgorithm> findEncryptor(final String logicTable, 
final String logicColumn) {
-        if (!tables.containsKey(logicTable)) {
-            return Optional.empty();
-        }
-        return 
tables.get(logicTable).findEncryptorName(logicColumn).map(encryptors::get);
+    public Optional<String> findPlainColumn(final String logicTable, final 
String logicColumn) {
+        Optional<String> originColumnName = findOriginColumnName(logicTable, 
logicColumn);
+        return originColumnName.isPresent() && tables.containsKey(logicTable) 
? tables.get(logicTable).findPlainColumn(originColumnName.get()) : 
Optional.empty();
     }
     
-    /**
-     * Get encrypt table names.
-     *
-     * @return encrypt table names
-     */
-    public Collection<String> getEncryptTableNames() {
-        return tables.keySet();
+    private Optional<String> findOriginColumnName(final String logicTable, 
final String logicColumn) {
+        for (String each : tables.get(logicTable).getLogicColumns()) {
+            if (logicColumn.equalsIgnoreCase(each)) {
+                return Optional.of(each);
+            }
+        }
+        return Optional.empty();
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestEncryptAlgorithm.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestEncryptAlgorithm.java
index 6edaf1a..401eb11 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestEncryptAlgorithm.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestEncryptAlgorithm.java
@@ -45,6 +45,6 @@ public final class TestEncryptAlgorithm implements 
EncryptAlgorithm {
     
     @Override
     public String getType() {
-        return "test";
+        return "TEST";
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestQueryAssistedEncryptAlgorithm.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestQueryAssistedEncryptAlgorithm.java
index 92c74ae..964e382 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestQueryAssistedEncryptAlgorithm.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestQueryAssistedEncryptAlgorithm.java
@@ -50,6 +50,6 @@ public final class TestQueryAssistedEncryptAlgorithm 
implements QueryAssistedEnc
     
     @Override
     public String getType() {
-        return "assistedTest";
+        return "QUERY_ASSISTED_TEST";
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
index ff534c4..5ce9197 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptRuleTest.java
@@ -18,11 +18,12 @@
 package org.apache.shardingsphere.encrypt.rule;
 
 import com.google.common.collect.ImmutableMap;
+import 
org.apache.shardingsphere.encrypt.algorithm.config.AlgorithmProvidedEncryptRuleConfiguration;
 import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
+import org.apache.shardingsphere.encrypt.fixture.TestEncryptAlgorithm;
 import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
-import org.junit.Before;
 import org.junit.Test;
 
 import java.util.Arrays;
@@ -38,99 +39,122 @@ import static org.junit.Assert.assertTrue;
 
 public final class EncryptRuleTest {
     
-    private final String table = "table";
+    @Test
+    public void 
assertNewInstanceWithAlgorithmProvidedEncryptRuleConfiguration() {
+        EncryptColumnRuleConfiguration encryptColumnConfig = new 
EncryptColumnRuleConfiguration("encrypt_column", "encrypt_cipher", "", "", 
"test_encryptor");
+        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singletonList(encryptColumnConfig));
+        AlgorithmProvidedEncryptRuleConfiguration ruleConfig = new 
AlgorithmProvidedEncryptRuleConfiguration(
+                Collections.singleton(tableConfig), 
ImmutableMap.of("test_encryptor", new TestEncryptAlgorithm()));
+        EncryptRule actual = new EncryptRule(ruleConfig);
+        assertThat(actual.getEncryptTableNames(), 
is(Collections.singleton("t_encrypt")));
+    }
     
-    private final String column = "column";
-
-    private final String idNumber = "idNumber";
-
-    private EncryptRuleConfiguration encryptRuleConfig;
+    @Test(expected = IllegalArgumentException.class)
+    public void assertNewInstanceWithInvalidConfiguration() {
+        ShardingSphereAlgorithmConfiguration encryptAlgorithmConfig = new 
ShardingSphereAlgorithmConfiguration("TEST", new Properties());
+        EncryptColumnRuleConfiguration encryptColumnConfig = new 
EncryptColumnRuleConfiguration("encrypt_column", "encrypt_cipher", "", "", 
"test_encryptor");
+        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singletonList(encryptColumnConfig));
+        EncryptRuleConfiguration ruleConfig = new 
EncryptRuleConfiguration(Collections.singleton(tableConfig), 
ImmutableMap.of("invalid_encryptor", encryptAlgorithmConfig));
+        new EncryptRule(ruleConfig);
+    }
     
-    @Before
-    public void setUp() {
-        Properties props = new Properties();
-        EncryptColumnRuleConfiguration columnConfig = new 
EncryptColumnRuleConfiguration(column, "cipher_pwd", "", "plain_pwd", "aes");
-        EncryptColumnRuleConfiguration idNumberConfig = new 
EncryptColumnRuleConfiguration(idNumber, "cipher_id_number", "", 
"plain_id_number", "aes");
-        ShardingSphereAlgorithmConfiguration encryptAlgorithmConfiguration = 
new ShardingSphereAlgorithmConfiguration("assistedTest", props);
-        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration(table, Arrays.asList(columnConfig, 
idNumberConfig));
-        encryptRuleConfig = new 
EncryptRuleConfiguration(Collections.singleton(tableConfig), 
ImmutableMap.of("aes", encryptAlgorithmConfiguration));
+    @Test(expected = IllegalArgumentException.class)
+    public void 
assertNewInstanceWithInvalidAlgorithmProvidedEncryptRuleConfiguration() {
+        EncryptColumnRuleConfiguration encryptColumnConfig = new 
EncryptColumnRuleConfiguration("encrypt_column", "encrypt_cipher", "", "", 
"test_encryptor");
+        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", 
Collections.singletonList(encryptColumnConfig));
+        AlgorithmProvidedEncryptRuleConfiguration ruleConfig = new 
AlgorithmProvidedEncryptRuleConfiguration(
+                Collections.singleton(tableConfig), 
ImmutableMap.of("invalid_encryptor", new TestEncryptAlgorithm()));
+        new EncryptRule(ruleConfig);
     }
     
     @Test
-    public void assertGetEncryptAssistedQueryValues() {
-        List<Object> encryptAssistedQueryValues = new 
EncryptRule(encryptRuleConfig).getEncryptAssistedQueryValues(table, column, 
Collections.singletonList(null));
-        for (final Object value : encryptAssistedQueryValues) {
-            assertNull(value);
-        }
+    public void assertGetEncryptTableNames() {
+        assertFalse(new 
EncryptRule(createEncryptRuleConfiguration()).getEncryptTableNames().isEmpty());
+    }
+    
+    @Test
+    public void assertFindEncryptTable() {
+        assertTrue(new 
EncryptRule(createEncryptRuleConfiguration()).findEncryptTable("t_encrypt").isPresent());
+    }
+    
+    @Test
+    public void assertFindEncryptor() {
+        assertTrue(new 
EncryptRule(createEncryptRuleConfiguration()).findEncryptor("t_encrypt", 
"pwd").isPresent());
+    }
+    
+    @Test
+    public void assertNotFindEncryptor() {
+        assertFalse(new 
EncryptRule(createEncryptRuleConfiguration()).findEncryptor("t_encrypt", 
"other_column").isPresent());
     }
     
     @Test
     public void assertGetEncryptValues() {
-        List<Object> encryptAssistedQueryValues = new 
EncryptRule(encryptRuleConfig).getEncryptValues(table, column, 
Collections.singletonList(null));
+        List<Object> encryptAssistedQueryValues = new 
EncryptRule(createEncryptRuleConfiguration()).getEncryptValues("t_encrypt", 
"pwd", Collections.singletonList(null));
         for (final Object value : encryptAssistedQueryValues) {
             assertNull(value);
         }
     }
     
     @Test
-    public void assertFindEncryptTable() {
-        assertTrue(new 
EncryptRule(encryptRuleConfig).findEncryptTable(table).isPresent());
-    }
-    
-    @Test
-    public void assertGetLogicColumnOfCipher() {
-        assertThat(new 
EncryptRule(encryptRuleConfig).getLogicColumnOfCipher(table, "cipher_pwd"), 
is(column));
+    public void assertIsCipherColumn() {
+        assertTrue(new 
EncryptRule(createEncryptRuleConfiguration()).isCipherColumn("t_encrypt", 
"pwd_cipher"));
     }
     
     @Test
-    public void assertFindPlainColumn() {
-        assertTrue(new EncryptRule(encryptRuleConfig).findPlainColumn(table, 
column).isPresent());
-        assertTrue(new EncryptRule(encryptRuleConfig).findPlainColumn(table, 
idNumber.toLowerCase()).isPresent());
-        assertFalse(new EncryptRule(encryptRuleConfig).findPlainColumn(table, 
"notExistLogicColumn").isPresent());
+    public void assertGetCipherColumnWhenEncryptColumnExist() {
+        assertThat(new 
EncryptRule(createEncryptRuleConfiguration()).getCipherColumn("t_encrypt", 
"pwd"), is("pwd_cipher"));
     }
     
     @Test(expected = NullPointerException.class)
     public void assertGetCipherColumnWhenNoEncryptColumn() {
-        new EncryptRule(encryptRuleConfig).getCipherColumn(table, 
"cipher_pwd");
+        new 
EncryptRule(createEncryptRuleConfiguration()).getCipherColumn("t_encrypt", 
"pwd_cipher");
     }
     
     @Test
-    public void assertGetCipherColumnWhenEncryptColumnExist() {
-        assertThat(new EncryptRule(encryptRuleConfig).getCipherColumn(table, 
column), is("cipher_pwd"));
+    public void assertGetLogicColumnOfCipher() {
+        assertThat(new 
EncryptRule(createEncryptRuleConfiguration()).getLogicColumnOfCipher("t_encrypt",
 "pwd_cipher"), is("pwd"));
     }
     
     @Test
-    public void assertIsCipherColumn() {
-        assertTrue(new EncryptRule(encryptRuleConfig).isCipherColumn(table, 
"cipher_pwd"));
+    public void assertGetLogicAndCipherColumns() {
+        assertFalse(new 
EncryptRule(createEncryptRuleConfiguration()).getLogicAndCipherColumns("t_encrypt").isEmpty());
     }
     
     @Test
     public void assertFindAssistedQueryColumn() {
-        assertFalse(new 
EncryptRule(encryptRuleConfig).findAssistedQueryColumn(table, 
"cipher_pwd").isPresent());
+        assertFalse(new 
EncryptRule(createEncryptRuleConfiguration()).findAssistedQueryColumn("t_encrypt",
 "pwd_cipher").isPresent());
     }
     
     @Test
-    public void assertGetAssistedQueryColumns() {
-        assertTrue(new 
EncryptRule(encryptRuleConfig).getAssistedQueryColumns(table).isEmpty());
+    public void assertGetEncryptAssistedQueryValues() {
+        List<Object> encryptAssistedQueryValues = new 
EncryptRule(createEncryptRuleConfiguration()).getEncryptAssistedQueryValues("t_encrypt",
 "pwd", Collections.singletonList(null));
+        for (final Object value : encryptAssistedQueryValues) {
+            assertNull(value);
+        }
     }
     
     @Test
-    public void assertGetAssistedQueryAndPlainColumns() {
-        assertFalse(new 
EncryptRule(encryptRuleConfig).getAssistedQueryAndPlainColumns(table).isEmpty());
+    public void assertGetAssistedQueryColumns() {
+        assertTrue(new 
EncryptRule(createEncryptRuleConfiguration()).getAssistedQueryColumns("t_encrypt").isEmpty());
     }
     
     @Test
-    public void assertGetLogicAndCipherColumns() {
-        assertFalse(new 
EncryptRule(encryptRuleConfig).getLogicAndCipherColumns(table).isEmpty());
+    public void assertGetAssistedQueryAndPlainColumns() {
+        assertFalse(new 
EncryptRule(createEncryptRuleConfiguration()).getAssistedQueryAndPlainColumns("t_encrypt").isEmpty());
     }
     
     @Test
-    public void assertGetLogicAndPlainColumns() {
-        assertFalse(new 
EncryptRule(encryptRuleConfig).getLogicAndPlainColumns(table).isEmpty());
+    public void assertFindPlainColumn() {
+        assertTrue(new 
EncryptRule(createEncryptRuleConfiguration()).findPlainColumn("t_encrypt", 
"pwd").isPresent());
+        assertTrue(new 
EncryptRule(createEncryptRuleConfiguration()).findPlainColumn("t_encrypt", 
"credit_card".toLowerCase()).isPresent());
+        assertFalse(new 
EncryptRule(createEncryptRuleConfiguration()).findPlainColumn("t_encrypt", 
"notExistLogicColumn").isPresent());
     }
     
-    @Test
-    public void assertGetEncryptTableNames() {
-        assertFalse(new 
EncryptRule(encryptRuleConfig).getEncryptTableNames().isEmpty());
+    private EncryptRuleConfiguration createEncryptRuleConfiguration() {
+        ShardingSphereAlgorithmConfiguration encryptAlgorithmConfig = new 
ShardingSphereAlgorithmConfiguration("QUERY_ASSISTED_TEST", new Properties());
+        EncryptColumnRuleConfiguration pwdColumnConfig = new 
EncryptColumnRuleConfiguration("pwd", "pwd_cipher", "", "pwd_plain", 
"test_encryptor");
+        EncryptColumnRuleConfiguration creditCardColumnConfig = new 
EncryptColumnRuleConfiguration("credit_card", "credit_card_cipher", "", 
"credit_card_plain", "test_encryptor");
+        EncryptTableRuleConfiguration tableConfig = new 
EncryptTableRuleConfiguration("t_encrypt", Arrays.asList(pwdColumnConfig, 
creditCardColumnConfig));
+        return new 
EncryptRuleConfiguration(Collections.singleton(tableConfig), 
ImmutableMap.of("test_encryptor", encryptAlgorithmConfig));
     }
 }

Reply via email to