RaigorJiang commented on code in PR #30658: URL: https://github.com/apache/shardingsphere/pull/30658#discussion_r1540575256
########## features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptRuleConfigurationToDistSQLConverterTest.java: ########## @@ -0,0 +1,91 @@ +/* + * 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.distsql.handler.provider; + +import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration; +import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration; +import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration; +import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration; +import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.Properties; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class EncryptRuleConfigurationToDistSQLConverterTest { + + @Test + void assertConvertWithEmptyTables() { + EncryptRuleConfiguration encryptRuleConfiguration = mock(EncryptRuleConfiguration.class); + when(encryptRuleConfiguration.getTables()).thenReturn(Collections.emptyList()); + EncryptRuleConfigurationToDistSQLConverter encryptRuleConfigurationToDistSQLConverter = new EncryptRuleConfigurationToDistSQLConverter(); + assertThat(encryptRuleConfigurationToDistSQLConverter.convert(encryptRuleConfiguration), is("")); + Review Comment: Please remove useless empty line. ########## features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptRuleConfigurationToDistSQLConverterTest.java: ########## @@ -0,0 +1,91 @@ +/* + * 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.distsql.handler.provider; + +import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration; +import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration; +import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration; +import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration; +import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.Properties; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class EncryptRuleConfigurationToDistSQLConverterTest { + + @Test + void assertConvertWithEmptyTables() { + EncryptRuleConfiguration encryptRuleConfiguration = mock(EncryptRuleConfiguration.class); + when(encryptRuleConfiguration.getTables()).thenReturn(Collections.emptyList()); + EncryptRuleConfigurationToDistSQLConverter encryptRuleConfigurationToDistSQLConverter = new EncryptRuleConfigurationToDistSQLConverter(); + assertThat(encryptRuleConfigurationToDistSQLConverter.convert(encryptRuleConfiguration), is("")); + + } + + @Test + void assertConvert() { + EncryptRuleConfiguration encryptRuleConfiguration = getEncryptRuleConfiguration(); + EncryptRuleConfigurationToDistSQLConverter encryptRuleConfigurationToDistSQLConverter = new EncryptRuleConfigurationToDistSQLConverter(); + assertThat(encryptRuleConfigurationToDistSQLConverter.convert(encryptRuleConfiguration), is("CREATE ENCRYPT RULE t_encrypt (\nCOLUMNS(\n" + + + "(NAME=user_id, CIPHER=user_cipher, ASSISTED_QUERY_COLUMN=user_assisted, LIKE_QUERY_COLUMN=user_like, ENCRYPT_ALGORITHM(TYPE(NAME='md5')), " + + + "ASSISTED_QUERY_ALGORITHM(), LIKE_QUERY_ALGORITHM()),\n" + + + "(NAME=pwd, CIPHER=pwd_cipher, ASSISTED_QUERY_COLUMN=pwd_assisted, LIKE_QUERY_COLUMN=pwd_like, ENCRYPT_ALGORITHM(TYPE(NAME='md5')), " + + + "ASSISTED_QUERY_ALGORITHM(), LIKE_QUERY_ALGORITHM())\n" + + + ")),\n t_encrypt_another (\nCOLUMNS(\n" + + + "(NAME=user_id, CIPHER=user_cipher, ASSISTED_QUERY_COLUMN=user_assisted, LIKE_QUERY_COLUMN=user_like, ENCRYPT_ALGORITHM(TYPE(NAME='md5')), " + + + "ASSISTED_QUERY_ALGORITHM(), LIKE_QUERY_ALGORITHM())\n" + + + "));")); + Review Comment: Please remove useless empty line. ########## features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptRuleConfigurationToDistSQLConverterTest.java: ########## @@ -0,0 +1,91 @@ +/* + * 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.distsql.handler.provider; + +import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration; +import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnItemRuleConfiguration; +import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration; +import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration; +import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.Properties; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class EncryptRuleConfigurationToDistSQLConverterTest { + + @Test + void assertConvertWithEmptyTables() { + EncryptRuleConfiguration encryptRuleConfiguration = mock(EncryptRuleConfiguration.class); + when(encryptRuleConfiguration.getTables()).thenReturn(Collections.emptyList()); + EncryptRuleConfigurationToDistSQLConverter encryptRuleConfigurationToDistSQLConverter = new EncryptRuleConfigurationToDistSQLConverter(); + assertThat(encryptRuleConfigurationToDistSQLConverter.convert(encryptRuleConfiguration), is("")); + + } + + @Test + void assertConvert() { + EncryptRuleConfiguration encryptRuleConfiguration = getEncryptRuleConfiguration(); + EncryptRuleConfigurationToDistSQLConverter encryptRuleConfigurationToDistSQLConverter = new EncryptRuleConfigurationToDistSQLConverter(); + assertThat(encryptRuleConfigurationToDistSQLConverter.convert(encryptRuleConfiguration), is("CREATE ENCRYPT RULE t_encrypt (\nCOLUMNS(\n" + + + "(NAME=user_id, CIPHER=user_cipher, ASSISTED_QUERY_COLUMN=user_assisted, LIKE_QUERY_COLUMN=user_like, ENCRYPT_ALGORITHM(TYPE(NAME='md5')), " + + + "ASSISTED_QUERY_ALGORITHM(), LIKE_QUERY_ALGORITHM()),\n" Review Comment: `\n` may cause compatibility issues. Can it be replaced by `System.lineSeparator()`? ########## kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/provider/SingleRuleConfigurationToDistSQLConverterTest.java: ########## @@ -0,0 +1,57 @@ +/* + * 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.single.distsql.handler.provider; + +import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.Optional; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class SingleRuleConfigurationToDistSQLConverterTest { + + @Test + void assertConvert() { + SingleRuleConfiguration singleRuleConfiguration = new SingleRuleConfiguration(new LinkedList<>(Arrays.asList("t_0", "t_1")), "foo_ds"); + SingleRuleConfigurationToDistSQLConverter singleRuleConfigurationToDistSQLConverter = new SingleRuleConfigurationToDistSQLConverter(); + assertThat(singleRuleConfigurationToDistSQLConverter.convert(singleRuleConfiguration), is("LOAD SINGLE TABLE t_0,t_1;\n\nSET DEFAULT SINGLE TABLE STORAGE UNIT = foo_ds;")); + } + + @Test + void assertConvertWithoutDefaultDatasourceAndTables() { + SingleRuleConfiguration singleRuleConfiguration = mock(SingleRuleConfiguration.class); + when(singleRuleConfiguration.getDefaultDataSource()).thenReturn(Optional.empty()); + when(singleRuleConfiguration.getTables()).thenReturn(Collections.emptyList()); + SingleRuleConfigurationToDistSQLConverter singleRuleConfigurationToDistSQLConverter = new SingleRuleConfigurationToDistSQLConverter(); + assertThat(singleRuleConfigurationToDistSQLConverter.convert(singleRuleConfiguration), is("")); + } + + @Test + void assertGetType() { + SingleRuleConfigurationToDistSQLConverter singleRuleConfigurationToDistSQLConverter = new SingleRuleConfigurationToDistSQLConverter(); + assertThat(singleRuleConfigurationToDistSQLConverter.getType().getName(), is("org.apache.shardingsphere.single.api.config.SingleRuleConfiguration")); + } + Review Comment: Empty line. ########## features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskRuleConfigurationToDistSQLConverterTest.java: ########## @@ -0,0 +1,64 @@ +/* + * 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.mask.distsql.handler.provider; + +import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; +import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration; +import org.apache.shardingsphere.mask.api.config.rule.MaskColumnRuleConfiguration; +import org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration; +import org.junit.jupiter.api.Test; + +import java.util.Collections; +import java.util.Properties; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class MaskRuleConfigurationToDistSQLConverterTest { + + @Test + void assertConvertWithEmptyTables() { + MaskRuleConfiguration maskRuleConfiguration = mock(MaskRuleConfiguration.class); + when(maskRuleConfiguration.getTables()).thenReturn(Collections.emptyList()); + MaskRuleConfigurationToDistSQLConverter maskRuleConfigurationToDistSQLConverter = new MaskRuleConfigurationToDistSQLConverter(); + assertThat(maskRuleConfigurationToDistSQLConverter.convert(maskRuleConfiguration), is("")); + } + + @Test + void assertConvert() { + MaskRuleConfiguration maskRuleConfiguration = getMaskRuleConfiguration(); + MaskRuleConfigurationToDistSQLConverter maskRuleConfigurationToDistSQLConverter = new MaskRuleConfigurationToDistSQLConverter(); + assertThat(maskRuleConfigurationToDistSQLConverter.convert(maskRuleConfiguration), is("CREATE MASK RULE t_mask (\n" + "COLUMNS(\n" + "(NAME=user_id, TYPE(NAME='md5'))\n" + "),;")); + } + + @Test + void assertGetType() { + MaskRuleConfigurationToDistSQLConverter maskRuleConfigurationToDistSQLConverter = new MaskRuleConfigurationToDistSQLConverter(); + assertThat(maskRuleConfigurationToDistSQLConverter.getType().getName(), is("org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration")); + } + + private MaskRuleConfiguration getMaskRuleConfiguration() { + MaskColumnRuleConfiguration maskColumnRuleConfig = new MaskColumnRuleConfiguration("user_id", "t_mask_user_id_md5"); + MaskTableRuleConfiguration maskTableRuleConfig = new MaskTableRuleConfiguration("t_mask", Collections.singleton(maskColumnRuleConfig)); + AlgorithmConfiguration algorithmConfig = new AlgorithmConfiguration("md5", new Properties()); + return new MaskRuleConfiguration(Collections.singleton(maskTableRuleConfig), Collections.singletonMap("t_mask_user_id_md5", algorithmConfig)); + } + Review Comment: Please remove useless empty line. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
