You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ki...@apache.org on 2020/08/12 16:30:21 UTC
[shardingsphere] branch master updated: Add test case for
EncryptMetaDataLoader (#6810)
This is an automated email from the ASF dual-hosted git repository.
kimmking 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 613e4a8 Add test case for EncryptMetaDataLoader (#6810)
613e4a8 is described below
commit 613e4a8ab3e7b2ebd378503996f222f8c913f367
Author: Liang Zhang <te...@163.com>
AuthorDate: Thu Aug 13 00:30:03 2020 +0800
Add test case for EncryptMetaDataLoader (#6810)
* Remove useless EncryptAlgorithmConfigurationTest
* Add more test case for AESEncryptAlgorithmTest
* Add more test case for MD5EncryptAlgorithmTest
* Add more test case for RC4EncryptAlgorithm
* Update encrypt algorithm test cases
* Add test case for EncryptMetaDataLoader
* Update test case for EncryptMetaDataLoader
---
.../config/EncryptAlgorithmConfigurationTest.java | 50 --------
.../encrypt/metadata/EncryptMetaDataLoader.java | 3 +-
.../encrypt/algorithm/AESEncryptAlgorithmTest.java | 36 +++---
.../encrypt/algorithm/MD5EncryptAlgorithmTest.java | 23 +++-
.../encrypt/algorithm/RC4EncryptAlgorithmTest.java | 23 ++--
.../fixture/TestEncryptAlgorithm.java | 2 +-
.../fixture/TestQueryAssistedEncryptAlgorithm.java | 2 +-
.../metadata/EncryptMetaDataLoaderTest.java | 127 +++++++++++++++++++++
...che.shardingsphere.encrypt.spi.EncryptAlgorithm | 4 +-
.../metadata/column/ColumnMetaDataLoader.java | 2 +-
10 files changed, 186 insertions(+), 86 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/test/java/org/apache/shardingsphere/encrypt/api/config/EncryptAlgorithmConfigurationTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/test/java/org/apache/shardingsphere/encrypt/api/config/EncryptAlgorithmConfigurationTest.java
deleted file mode 100644
index 4706bd3..0000000
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-api/src/test/java/org/apache/shardingsphere/encrypt/api/config/EncryptAlgorithmConfigurationTest.java
+++ /dev/null
@@ -1,50 +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.encrypt.api.config;
-
-import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
-import org.junit.Test;
-
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public final class EncryptAlgorithmConfigurationTest {
-
- @Test(expected = IllegalArgumentException.class)
- public void assertConstructorWithoutType() {
- new ShardingSphereAlgorithmConfiguration(null, new Properties());
- }
-
- @Test
- public void assertConstructorWithoutProperties() {
- ShardingSphereAlgorithmConfiguration actual = new ShardingSphereAlgorithmConfiguration("TEST", new Properties());
- assertThat(actual.getType(), is("TEST"));
- assertThat(actual.getProps(), is(new Properties()));
- }
-
- @Test
- public void assertConstructorWithProperties() {
- Properties props = new Properties();
- props.setProperty("key", "value");
- ShardingSphereAlgorithmConfiguration actual = new ShardingSphereAlgorithmConfiguration("TEST", props);
- assertThat(actual.getType(), is("TEST"));
- assertThat(actual.getProps(), is(props));
- }
-}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoader.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoader.java
index b35d2ab..f33e4db 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoader.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/main/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoader.java
@@ -56,8 +56,7 @@ public final class EncryptMetaDataLoader implements RuleMetaDataLoader<EncryptRu
@Override
public Optional<TableMetaData> load(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap, final DataNodes dataNodes,
final String tableName, final EncryptRule encryptRule, final ConfigurationProperties props) throws SQLException {
- return encryptRule.findEncryptTable(tableName).isPresent()
- ? TableMetaDataLoader.load(dataSourceMap.values().iterator().next(), tableName, databaseType.getName()) : Optional.empty();
+ return encryptRule.findEncryptTable(tableName).isPresent() ? TableMetaDataLoader.load(dataSourceMap.values().iterator().next(), tableName, databaseType.getName()) : Optional.empty();
}
@Override
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/AESEncryptAlgorithmTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/AESEncryptAlgorithmTest.java
index fc71272..f1c26f9 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/AESEncryptAlgorithmTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/AESEncryptAlgorithmTest.java
@@ -17,6 +17,10 @@
package org.apache.shardingsphere.encrypt.algorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.junit.Before;
import org.junit.Test;
@@ -28,28 +32,26 @@ import static org.junit.Assert.assertThat;
public final class AESEncryptAlgorithmTest {
- private final AESEncryptAlgorithm encryptAlgorithm = new AESEncryptAlgorithm();
+ static {
+ ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
+ }
+
+ private EncryptAlgorithm encryptAlgorithm;
@Before
public void setUp() {
Properties props = new Properties();
props.setProperty("aes.key.value", "test");
- encryptAlgorithm.setProps(props);
- encryptAlgorithm.init();
+ encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new ShardingSphereAlgorithmConfiguration("AES", props), EncryptAlgorithm.class);
}
@Test
- public void assertGetType() {
- assertThat(encryptAlgorithm.getType(), is("AES"));
- }
-
- @Test
- public void assertEncode() {
+ public void assertEncrypt() {
assertThat(encryptAlgorithm.encrypt("test"), is("dSpPiyENQGDUXMKFMJPGWA=="));
}
@Test(expected = IllegalArgumentException.class)
- public void assertEncodeWithoutKey() {
+ public void assertEncryptWithoutKey() {
Properties props = new Properties();
encryptAlgorithm.setProps(props);
encryptAlgorithm.init();
@@ -57,17 +59,17 @@ public final class AESEncryptAlgorithmTest {
}
@Test
- public void assertDecode() {
- assertThat(encryptAlgorithm.decrypt("dSpPiyENQGDUXMKFMJPGWA==").toString(), is("test"));
+ public void assertEncryptWithNullPlaintext() {
+ assertNull(encryptAlgorithm.encrypt(null));
}
@Test
- public void assertDecodeWithNull() {
- assertNull(encryptAlgorithm.decrypt(null));
+ public void assertDecrypt() {
+ assertThat(encryptAlgorithm.decrypt("dSpPiyENQGDUXMKFMJPGWA==").toString(), is("test"));
}
@Test(expected = IllegalArgumentException.class)
- public void assertDecodeWithoutKey() {
+ public void assertDecryptWithoutKey() {
Properties props = new Properties();
encryptAlgorithm.setProps(props);
encryptAlgorithm.init();
@@ -75,7 +77,7 @@ public final class AESEncryptAlgorithmTest {
}
@Test
- public void assertGetProperties() {
- assertThat(encryptAlgorithm.getProps().getProperty("aes.key.value"), is("test"));
+ public void assertDecryptWithNullCiphertext() {
+ assertNull(encryptAlgorithm.decrypt(null));
}
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/MD5EncryptAlgorithmTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/MD5EncryptAlgorithmTest.java
index 56330af..ce6ba67 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/MD5EncryptAlgorithmTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/MD5EncryptAlgorithmTest.java
@@ -17,20 +17,30 @@
package org.apache.shardingsphere.encrypt.algorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.junit.Before;
import org.junit.Test;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
public final class MD5EncryptAlgorithmTest {
- private final MD5EncryptAlgorithm encryptAlgorithm = new MD5EncryptAlgorithm();
+ static {
+ ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
+ }
- @Test
- public void assertGetType() {
- assertThat(encryptAlgorithm.getType(), is("MD5"));
+ private EncryptAlgorithm encryptAlgorithm;
+
+ @Before
+ public void setUp() {
+ encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new ShardingSphereAlgorithmConfiguration("Md5", new Properties()), EncryptAlgorithm.class);
}
@Test
@@ -39,6 +49,11 @@ public final class MD5EncryptAlgorithmTest {
}
@Test
+ public void assertEncryptWithNullPlaintext() {
+ assertNull(encryptAlgorithm.encrypt(null));
+ }
+
+ @Test
public void assertDecode() {
assertThat(encryptAlgorithm.decrypt("test").toString(), is("test"));
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/RC4EncryptAlgorithmTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/RC4EncryptAlgorithmTest.java
index ec0c9de..5b46811 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/RC4EncryptAlgorithmTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/RC4EncryptAlgorithmTest.java
@@ -17,7 +17,11 @@
package org.apache.shardingsphere.encrypt.algorithm;
+import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.junit.Before;
import org.junit.Test;
@@ -29,24 +33,27 @@ import static org.junit.Assert.assertThat;
public final class RC4EncryptAlgorithmTest {
- private final RC4EncryptAlgorithm encryptAlgorithm = new RC4EncryptAlgorithm();
+ static {
+ ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
+ }
+
+ private EncryptAlgorithm encryptAlgorithm;
@Before
public void setUp() {
Properties props = new Properties();
props.setProperty("rc4.key.value", "test-sharding");
- encryptAlgorithm.setProps(props);
- encryptAlgorithm.init();
+ encryptAlgorithm = ShardingSphereAlgorithmFactory.createAlgorithm(new ShardingSphereAlgorithmConfiguration("Rc4", props), EncryptAlgorithm.class);
}
@Test
- public void assertGetType() {
- assertThat(encryptAlgorithm.getType(), is("RC4"));
+ public void assertEncode() {
+ assertThat(encryptAlgorithm.encrypt("test"), is("qn36NQ=="));
}
@Test
- public void assertEncode() {
- assertThat(encryptAlgorithm.encrypt("test"), is("qn36NQ=="));
+ public void assertEncryptWithNullPlaintext() {
+ assertNull(encryptAlgorithm.encrypt(null));
}
@Test(expected = ShardingSphereException.class)
@@ -67,7 +74,7 @@ public final class RC4EncryptAlgorithmTest {
}
@Test
- public void assertDecodeWithNull() {
+ public void assertDecryptWithNullCiphertext() {
assertNull(encryptAlgorithm.decrypt(null));
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/fixture/TestEncryptAlgorithm.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestEncryptAlgorithm.java
similarity index 95%
rename from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/fixture/TestEncryptAlgorithm.java
rename to shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestEncryptAlgorithm.java
index 82e9551..6edaf1a 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/fixture/TestEncryptAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestEncryptAlgorithm.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.algorithm.fixture;
+package org.apache.shardingsphere.encrypt.fixture;
import lombok.Getter;
import lombok.Setter;
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/fixture/TestQueryAssistedEncryptAlgorithm.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestQueryAssistedEncryptAlgorithm.java
similarity index 96%
rename from shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/fixture/TestQueryAssistedEncryptAlgorithm.java
rename to shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestQueryAssistedEncryptAlgorithm.java
index 9a1b321..92c74ae 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/algorithm/fixture/TestQueryAssistedEncryptAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/fixture/TestQueryAssistedEncryptAlgorithm.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.encrypt.algorithm.fixture;
+package org.apache.shardingsphere.encrypt.fixture;
import lombok.Getter;
import lombok.Setter;
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoaderTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoaderTest.java
new file mode 100644
index 0000000..1cf035f
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/java/org/apache/shardingsphere/encrypt/metadata/EncryptMetaDataLoaderTest.java
@@ -0,0 +1,127 @@
+/*
+ * 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.encrypt.rule.EncryptTable;
+import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.datanode.DataNodes;
+import org.apache.shardingsphere.infra.metadata.schema.spi.RuleMetaDataLoader;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.order.OrderedSPIRegistry;
+import org.apache.shardingsphere.sql.parser.binder.metadata.schema.SchemaMetaData;
+import org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class EncryptMetaDataLoaderTest {
+
+ static {
+ ShardingSphereServiceLoader.register(RuleMetaDataLoader.class);
+ }
+
+ @Mock
+ private DatabaseType databaseType;
+
+ @Mock
+ private DataSource dataSource;
+
+ @Mock
+ private ConfigurationProperties props;
+
+ @Before
+ public void setUp() throws SQLException {
+ ResultSet tableResultSet = createTableResultSet();
+ ResultSet columnResultSet = createColumnResultSet();
+ Connection connection = mock(Connection.class, Mockito.RETURNS_DEEP_STUBS);
+ when(connection.getMetaData().getTables(any(), any(), any(), eq(null))).thenReturn(tableResultSet);
+ when(connection.getMetaData().getColumns(any(), any(), any(), eq("%"))).thenReturn(columnResultSet);
+ when(dataSource.getConnection()).thenReturn(connection);
+ }
+
+ private ResultSet createTableResultSet() throws SQLException {
+ ResultSet result = mock(ResultSet.class);
+ when(result.next()).thenReturn(true, false);
+ return result;
+ }
+
+ private ResultSet createColumnResultSet() throws SQLException {
+ ResultSet result = mock(ResultSet.class);
+ when(result.next()).thenReturn(true, true, true, false);
+ when(result.getString("COLUMN_NAME")).thenReturn("id", "pwd_cipher", "pwd_plain");
+ return result;
+ }
+
+ @Test
+ public void assertLoad() throws SQLException {
+ EncryptRule rule = createEncryptRule();
+ EncryptMetaDataLoader loader = (EncryptMetaDataLoader) OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(rule), RuleMetaDataLoader.class).get(rule);
+ SchemaMetaData actual = loader.load(databaseType, Collections.singletonMap("logic_db", dataSource), new DataNodes(Collections.singletonList(rule)), rule, props, Collections.emptyList());
+ assertThat(actual.get("t_encrypt").getColumnMetaData(0).getName(), is("id"));
+ assertThat(actual.get("t_encrypt").getColumnMetaData(1).getName(), is("pwd_cipher"));
+ assertThat(actual.get("t_encrypt").getColumnMetaData(2).getName(), is("pwd_plain"));
+ }
+
+ @Test
+ public void assertLoadByExistedTable() throws SQLException {
+ EncryptRule rule = createEncryptRule();
+ EncryptMetaDataLoader loader = (EncryptMetaDataLoader) OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(rule), RuleMetaDataLoader.class).get(rule);
+ Optional<TableMetaData> actual = loader.load(databaseType, Collections.singletonMap("logic_db", dataSource), new DataNodes(Collections.singletonList(rule)), "t_encrypt", rule, props);
+ assertTrue(actual.isPresent());
+ assertThat(actual.get().getColumnMetaData(0).getName(), is("id"));
+ assertThat(actual.get().getColumnMetaData(1).getName(), is("pwd_cipher"));
+ assertThat(actual.get().getColumnMetaData(2).getName(), is("pwd_plain"));
+ }
+
+ @Test
+ public void assertLoadByNotExistedTable() throws SQLException {
+ EncryptRule rule = createEncryptRule();
+ EncryptMetaDataLoader loader = new EncryptMetaDataLoader();
+ Optional<TableMetaData> actual = loader.load(databaseType, Collections.singletonMap("logic_db", dataSource), new DataNodes(Collections.singletonList(rule)), "not_existed_table", rule, props);
+ assertFalse(actual.isPresent());
+ }
+
+ private EncryptRule createEncryptRule() {
+ EncryptRule result = mock(EncryptRule.class);
+ when(result.getEncryptTableNames()).thenReturn(Collections.singletonList("t_encrypt"));
+ when(result.findEncryptTable("t_encrypt")).thenReturn(Optional.of(mock(EncryptTable.class)));
+ return result;
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm
index 24a65ce..19bba7f 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-common/src/test/resources/META-INF/services/org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm
@@ -15,5 +15,5 @@
# limitations under the License.
#
-org.apache.shardingsphere.encrypt.algorithm.fixture.TestEncryptAlgorithm
-org.apache.shardingsphere.encrypt.algorithm.fixture.TestQueryAssistedEncryptAlgorithm
+org.apache.shardingsphere.encrypt.fixture.TestEncryptAlgorithm
+org.apache.shardingsphere.encrypt.fixture.TestQueryAssistedEncryptAlgorithm
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/column/ColumnMetaDataLoader.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/column/ColumnMetaDataLoader.java
index 3e18966..5df3afa 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/column/ColumnMetaDataLoader.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/column/ColumnMetaDataLoader.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.sql.parser.binder.metadata.column;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.sql.parser.binder.metadata.util.JdbcUtil;
import java.sql.Connection;
import java.sql.ResultSet;
@@ -28,7 +29,6 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
-import org.apache.shardingsphere.sql.parser.binder.metadata.util.JdbcUtil;
/**
* Column meta data loader.