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

wuweijie 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 979c224  Refactor test cases of 
AlterDatabaseDiscoveryRuleStatementUpdater and AlterEncryptRuleStatementUpdater 
(#11065)
979c224 is described below

commit 979c224c7b3ce41de0aee759b2d78c8b1434ff70
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jun 29 23:25:10 2021 +0800

    Refactor test cases of AlterDatabaseDiscoveryRuleStatementUpdater and 
AlterEncryptRuleStatementUpdater (#11065)
    
    * Refactor AlterDatabaseDiscoveryRuleStatementUpdaterTest
    
    * Refactor AlterDatabaseDiscoveryRuleStatementUpdaterTest
    
    * Refactor AlterEncryptRuleStatementUpdaterTest
---
 ...terDatabaseDiscoveryRuleBackendHandlerTest.java | 140 ---------------------
 .../impl/AlterEncryptRuleBackendHandlerTest.java   | 127 -------------------
 ...rDatabaseDiscoveryRuleStatementUpdaterTest.java |  82 ++++++++++++
 .../AlterEncryptRuleStatementUpdaterTest.java      |  73 +++++++++++
 4 files changed, 155 insertions(+), 267 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandlerTest.java
deleted file mode 100644
index 5709a25..0000000
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterDatabaseDiscoveryRuleBackendHandlerTest.java
+++ /dev/null
@@ -1,140 +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.proxy.backend.text.distsql.rdl.impl;
-
-import com.google.common.collect.Maps;
-import 
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
-import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
-import 
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
-import 
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
-import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryType;
-import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import 
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import 
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleNotExistedException;
-import 
org.apache.shardingsphere.proxy.backend.exception.InvalidDatabaseDiscoveryTypesException;
-import 
org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
-import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
-import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
-import org.apache.shardingsphere.transaction.context.TransactionContexts;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.Properties;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class AlterDatabaseDiscoveryRuleBackendHandlerTest {
-    
-    @Mock
-    private BackendConnection backendConnection;
-    
-    @Mock
-    private AlterDatabaseDiscoveryRuleStatement sqlStatement;
-    
-    @Mock
-    private MetaDataContexts metaDataContexts;
-    
-    @Mock
-    private TransactionContexts transactionContexts;
-    
-    @Mock(answer = Answers.RETURNS_DEEP_STUBS)
-    private ShardingSphereMetaData shardingSphereMetaData;
-    
-    @Mock
-    private ShardingSphereRuleMetaData ruleMetaData;
-    
-    @Mock
-    private ShardingSphereResource shardingSphereResource;
-    
-    @Mock
-    private DatabaseDiscoveryDataSourceRuleConfiguration 
databaseDiscoveryDataSourceRuleConfiguration;
-    
-    private final RDLBackendHandler<AlterDatabaseDiscoveryRuleStatement> 
handler = new RDLBackendHandler<>(sqlStatement, backendConnection, 
DatabaseDiscoveryRuleConfiguration.class);
-    
-    @Before
-    public void setUp() {
-        ShardingSphereServiceLoader.register(DatabaseDiscoveryType.class);
-        ProxyContext.getInstance().init(metaDataContexts, transactionContexts);
-        
when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singleton("test"));
-        
when(metaDataContexts.getMetaData("test")).thenReturn(shardingSphereMetaData);
-        
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
-    }
-    
-    @Test
-    public void assertExecute() {
-        DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new 
DatabaseDiscoveryRuleSegment("ha_group", Arrays.asList("ds_0", "ds_1"), "TEST", 
new Properties());
-        
when(sqlStatement.getRules()).thenReturn(Collections.singleton(databaseDiscoveryRuleSegment));
-        when(ruleMetaData.getConfigurations()).thenReturn(
-                Collections.singleton(new 
DatabaseDiscoveryRuleConfiguration(new 
LinkedList<>(Collections.singleton(databaseDiscoveryDataSourceRuleConfiguration)),
 Maps.newHashMap())));
-        
when(databaseDiscoveryDataSourceRuleConfiguration.getName()).thenReturn("ha_group");
-        
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
-        ResponseHeader responseHeader = handler.execute("test", sqlStatement);
-        assertNotNull(responseHeader);
-        assertTrue(responseHeader instanceof UpdateResponseHeader);
-    }
-    
-    @Test(expected = DatabaseDiscoveryRuleNotExistedException.class)
-    public void assertExecuteWithNotExistDatabaseDiscoveryRule() {
-        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.emptyList());
-        handler.execute("test", sqlStatement);
-    }
-    
-    @Test(expected = DatabaseDiscoveryRuleNotExistedException.class)
-    public void assertExecuteWithNoAlteredDatabaseDiscoveryRule() {
-        DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new 
DatabaseDiscoveryRuleSegment("ha_group", Arrays.asList("ds_0", "ds_1"), "TEST", 
new Properties());
-        
when(sqlStatement.getRules()).thenReturn(Collections.singleton(databaseDiscoveryRuleSegment));
-        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.singleton(new 
DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), 
Collections.emptyMap())));
-        handler.execute("test", sqlStatement);
-    }
-    
-    @Test(expected = ResourceNotExistedException.class)
-    public void assertExecuteWithNotExistResources() {
-        DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new 
DatabaseDiscoveryRuleSegment("ha_group", Arrays.asList("ds_0", "ds_1"), "TEST", 
new Properties());
-        
when(sqlStatement.getRules()).thenReturn(Collections.singleton(databaseDiscoveryRuleSegment));
-        when(ruleMetaData.getConfigurations()).thenReturn(
-                Collections.singleton(new 
DatabaseDiscoveryRuleConfiguration(Collections.singleton(databaseDiscoveryDataSourceRuleConfiguration),
 Collections.emptyMap())));
-        
when(databaseDiscoveryDataSourceRuleConfiguration.getName()).thenReturn("ha_group");
-        handler.execute("test", sqlStatement);
-    }
-    
-    @Test(expected = InvalidDatabaseDiscoveryTypesException.class)
-    public void assertExecuteWithInvalidDiscoveryTypes() {
-        DatabaseDiscoveryRuleSegment databaseDiscoveryRuleSegment = new 
DatabaseDiscoveryRuleSegment("ha_group", Arrays.asList("ds_0", "ds_1"), 
"notExistType", new Properties());
-        
when(sqlStatement.getRules()).thenReturn(Collections.singleton(databaseDiscoveryRuleSegment));
-        when(ruleMetaData.getConfigurations()).thenReturn(
-                Collections.singleton(new 
DatabaseDiscoveryRuleConfiguration(Collections.singleton(databaseDiscoveryDataSourceRuleConfiguration),
 Collections.emptyMap())));
-        
when(databaseDiscoveryDataSourceRuleConfiguration.getName()).thenReturn("ha_group");
-        
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
-        handler.execute("test", sqlStatement);
-    }
-}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandlerTest.java
deleted file mode 100644
index bf5cd29..0000000
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandlerTest.java
+++ /dev/null
@@ -1,127 +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.proxy.backend.text.distsql.rdl.impl;
-
-import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
-import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
-import 
org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSegment;
-import 
org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
-import 
org.apache.shardingsphere.encrypt.distsql.parser.statement.AlterEncryptRuleStatement;
-import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
-import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import 
org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import 
org.apache.shardingsphere.proxy.backend.exception.EncryptRuleNotExistedException;
-import 
org.apache.shardingsphere.proxy.backend.exception.InvalidEncryptorsException;
-import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
-import 
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
-import org.apache.shardingsphere.transaction.context.TransactionContexts;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Properties;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public final class AlterEncryptRuleBackendHandlerTest {
-    
-    @Mock
-    private BackendConnection backendConnection;
-    
-    @Mock
-    private AlterEncryptRuleStatement sqlStatement;
-    
-    @Mock
-    private MetaDataContexts metaDataContexts;
-    
-    @Mock
-    private TransactionContexts transactionContexts;
-    
-    @Mock
-    private ShardingSphereMetaData shardingSphereMetaData;
-    
-    @Mock
-    private ShardingSphereRuleMetaData ruleMetaData;
-    
-    @Mock
-    private EncryptTableRuleConfiguration encryptTableRuleConfig;
-    
-    private final RDLBackendHandler<AlterEncryptRuleStatement> handler = new 
RDLBackendHandler<>(sqlStatement, backendConnection, 
EncryptRuleConfiguration.class);
-    
-    @Before
-    public void setUp() {
-        ShardingSphereServiceLoader.register(EncryptAlgorithm.class);
-        ProxyContext.getInstance().init(metaDataContexts, transactionContexts);
-        
when(metaDataContexts.getAllSchemaNames()).thenReturn(Collections.singletonList("test"));
-        
when(metaDataContexts.getMetaData(eq("test"))).thenReturn(shardingSphereMetaData);
-        
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
-    }
-    
-    @Test
-    public void assertExecute() {
-        EncryptRuleSegment encryptRuleSegment = new 
EncryptRuleSegment("t_encrypt", buildEncryptColumnSegments("MD5"));
-        
when(sqlStatement.getRules()).thenReturn(Collections.singletonList(encryptRuleSegment));
-        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.singleton(new 
EncryptRuleConfiguration(new 
LinkedList<>(Collections.singleton(encryptTableRuleConfig)), new HashMap<>())));
-        when(encryptTableRuleConfig.getName()).thenReturn("t_encrypt");
-        ResponseHeader responseHeader = handler.execute("test", sqlStatement);
-        assertNotNull(responseHeader);
-        assertTrue(responseHeader instanceof UpdateResponseHeader);
-    }
-    
-    @Test(expected = EncryptRuleNotExistedException.class)
-    public void assertExecuteWithNotExistEncryptRule() {
-        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.emptyList());
-        handler.execute("test", sqlStatement);
-    }
-    
-    @Test(expected = EncryptRuleNotExistedException.class)
-    public void assertExecuteWithNoAlteredEncryptRules() {
-        EncryptRuleSegment encryptRuleSegment = new 
EncryptRuleSegment("t_encrypt", buildEncryptColumnSegments("MD5"));
-        
when(sqlStatement.getRules()).thenReturn(Collections.singletonList(encryptRuleSegment));
-        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.singletonList(new 
EncryptRuleConfiguration(Collections.emptyList(), new HashMap<>())));
-        handler.execute("test", sqlStatement);
-    }
-    
-    @Test(expected = InvalidEncryptorsException.class)
-    public void assertExecuteWithInvalidEncryptors() {
-        EncryptRuleSegment encryptRuleSegment = new 
EncryptRuleSegment("t_encrypt", 
buildEncryptColumnSegments("notExistEncryptor"));
-        
when(sqlStatement.getRules()).thenReturn(Collections.singletonList(encryptRuleSegment));
-        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.singletonList(new 
EncryptRuleConfiguration(Collections.singleton(encryptTableRuleConfig), new 
HashMap<>())));
-        when(encryptTableRuleConfig.getName()).thenReturn("t_encrypt");
-        handler.execute("test", sqlStatement);
-    }
-    
-    private Collection<EncryptColumnSegment> buildEncryptColumnSegments(final 
String encryptorName) {
-        return Collections.singleton(new EncryptColumnSegment("user_id", 
"user_cipher", "user_plain", new AlgorithmSegment(encryptorName, new 
Properties())));
-    }
-}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java
new file mode 100644
index 0000000..39e9805
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.proxy.backend.text.distsql.rdl.impl.updater;
+
+import 
org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import 
org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment;
+import 
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
+import 
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
+import 
org.apache.shardingsphere.proxy.backend.exception.DatabaseDiscoveryRuleNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.InvalidDatabaseDiscoveryTypesException;
+import 
org.apache.shardingsphere.proxy.backend.exception.ResourceNotExistedException;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Properties;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class AlterDatabaseDiscoveryRuleStatementUpdaterTest {
+    
+    private final AlterDatabaseDiscoveryRuleStatementUpdater updater = new 
AlterDatabaseDiscoveryRuleStatementUpdater();
+    
+    @Test(expected = DatabaseDiscoveryRuleNotExistedException.class)
+    public void assertCheckSQLStatementWithoutCurrentRule() {
+        updater.checkSQLStatement("foo", new 
AlterDatabaseDiscoveryRuleStatement(Collections.emptyList()), null, 
mock(ShardingSphereResource.class));
+    }
+    
+    @Test(expected = DatabaseDiscoveryRuleNotExistedException.class)
+    public void 
assertCheckSQLStatementWithoutToBeAlteredDatabaseDiscoveryRule() {
+        updater.checkSQLStatement("foo", createSQLStatement("TEST"), 
+                new 
DatabaseDiscoveryRuleConfiguration(Collections.emptyList(), 
Collections.emptyMap()), mock(ShardingSphereResource.class));
+    }
+    
+    @Test(expected = ResourceNotExistedException.class)
+    public void assertCheckSQLStatementWithoutExistedResources() {
+        ShardingSphereResource resource = mock(ShardingSphereResource.class);
+        
when(resource.getNotExistedResources(any())).thenReturn(Collections.singleton("ds0"));
+        updater.checkSQLStatement("foo", createSQLStatement("TEST"), 
createCurrentRuleConfiguration(), resource);
+    }
+    
+    @Test(expected = InvalidDatabaseDiscoveryTypesException.class)
+    public void assertCheckSQLStatementWithoutToBeAlteredDiscoveryTypes() {
+        updater.checkSQLStatement("foo", createSQLStatement("INVALID_TYPE"), 
createCurrentRuleConfiguration(), mock(ShardingSphereResource.class));
+    }
+    
+    @Test
+    public void assertUpdateCurrentRuleConfiguration() {
+        updater.updateCurrentRuleConfiguration("foo", 
createSQLStatement("TEST"), createCurrentRuleConfiguration());
+        // TODO assert Current rule configuration
+    }
+    
+    private AlterDatabaseDiscoveryRuleStatement createSQLStatement(final 
String discoveryTypeName) {
+        DatabaseDiscoveryRuleSegment ruleSegment = new 
DatabaseDiscoveryRuleSegment("ha_group", Arrays.asList("ds_0", "ds_1"), 
discoveryTypeName, new Properties());
+        return new 
AlterDatabaseDiscoveryRuleStatement(Collections.singleton(ruleSegment));
+    }
+    
+    private DatabaseDiscoveryRuleConfiguration 
createCurrentRuleConfiguration() {
+        DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = 
new DatabaseDiscoveryDataSourceRuleConfiguration("ha_group", 
Collections.emptyList(), "TEST");
+        return new DatabaseDiscoveryRuleConfiguration(new 
LinkedList<>(Collections.singleton(dataSourceRuleConfig)), new HashMap<>());
+    }
+}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterEncryptRuleStatementUpdaterTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterEncryptRuleStatementUpdaterTest.java
new file mode 100644
index 0000000..fcd4dda
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/updater/AlterEncryptRuleStatementUpdaterTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.proxy.backend.text.distsql.rdl.impl.updater;
+
+import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
+import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
+import 
org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptColumnSegment;
+import 
org.apache.shardingsphere.encrypt.distsql.parser.segment.EncryptRuleSegment;
+import 
org.apache.shardingsphere.encrypt.distsql.parser.statement.AlterEncryptRuleStatement;
+import 
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
+import 
org.apache.shardingsphere.proxy.backend.exception.EncryptRuleNotExistedException;
+import 
org.apache.shardingsphere.proxy.backend.exception.InvalidEncryptorsException;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Properties;
+
+import static org.mockito.Mockito.mock;
+
+public final class AlterEncryptRuleStatementUpdaterTest {
+    
+    private final AlterEncryptRuleStatementUpdater updater = new 
AlterEncryptRuleStatementUpdater();
+    
+    @Test(expected = EncryptRuleNotExistedException.class)
+    public void assertCheckSQLStatementWithoutCurrentRule() {
+        updater.checkSQLStatement("foo", createSQLStatement("MD5"), null, 
mock(ShardingSphereResource.class));
+    }
+    
+    @Test(expected = EncryptRuleNotExistedException.class)
+    public void assertCheckSQLStatementWithoutToBeAlteredRules() {
+        updater.checkSQLStatement("foo", createSQLStatement("MD5"), new 
EncryptRuleConfiguration(Collections.emptyList(), new HashMap<>()), 
mock(ShardingSphereResource.class));
+    }
+    
+    @Test(expected = InvalidEncryptorsException.class)
+    public void assertCheckSQLStatementWithoutToBeAlteredEncryptors() {
+        updater.checkSQLStatement("foo", createSQLStatement("INVALID_TYPE"), 
createCurrentRuleConfiguration(), mock(ShardingSphereResource.class));
+    }
+    
+    @Test
+    public void assertUpdateCurrentRuleConfiguration() {
+        updater.updateCurrentRuleConfiguration("foo", 
createSQLStatement("MD5"), createCurrentRuleConfiguration());
+        // TODO assert Current rule configuration
+    }
+    
+    private AlterEncryptRuleStatement createSQLStatement(final String 
encryptorName) {
+        EncryptColumnSegment columnSegment = new 
EncryptColumnSegment("user_id", "user_cipher", "user_plain", new 
AlgorithmSegment(encryptorName, new Properties()));
+        EncryptRuleSegment ruleSegment = new EncryptRuleSegment("t_encrypt", 
Collections.singleton(columnSegment));
+        return new 
AlterEncryptRuleStatement(Collections.singleton(ruleSegment));
+    }
+    
+    private EncryptRuleConfiguration createCurrentRuleConfiguration() {
+        EncryptTableRuleConfiguration tableRuleConfig = new 
EncryptTableRuleConfiguration("t_encrypt", Collections.emptyList());
+        return new EncryptRuleConfiguration(new 
LinkedList<>(Collections.singleton(tableRuleConfig)), new HashMap<>());
+    }
+}

Reply via email to