提交 a01fce65 编写于 作者: S sluk3r 提交者: Liang Zhang

improved coverage for classed of EncryptRule, EncryptTable and EncryptColumn (#3204)

* test case added for EncryptRule and EncryptTable

* test case code added

* blanklines adjust
上级 e018ba0e
......@@ -28,7 +28,11 @@ import java.util.Collections;
import java.util.List;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThat;
public final class EncryptRuleTest {
......@@ -64,4 +68,64 @@ public final class EncryptRuleTest {
assertNull(value);
}
}
@Test
public void assertFindEncryptTable() {
assertTrue(new EncryptRule(encryptRuleConfig).findEncryptTable(table).isPresent());
}
@Test
public void assertGetLogicColumn() {
assertThat(new EncryptRule(encryptRuleConfig).getLogicColumn(table, "cipher_pwd"), is(column));
}
@Test
public void assertFindPlainColumn() {
assertFalse(new EncryptRule(encryptRuleConfig).findPlainColumn(table, "cipher_pwd").isPresent());
}
@Test(expected = NullPointerException.class)
public void assertGetCipherColumnWhenNoEncryptColumn() {
new EncryptRule(encryptRuleConfig).getCipherColumn(table, "cipher_pwd");
}
@Test
public void assertGetCipherColumnWhenEncryptColumnExist() {
assertThat(new EncryptRule(encryptRuleConfig).getCipherColumn(table, column), is("cipher_pwd"));
}
@Test
public void assertIsCipherColumn() {
assertTrue(new EncryptRule(encryptRuleConfig).isCipherColumn(table, "cipher_pwd"));
}
@Test
public void assertFindAssistedQueryColumn() {
assertFalse(new EncryptRule(encryptRuleConfig).findAssistedQueryColumn(table, "cipher_pwd").isPresent());
}
@Test
public void assertGetAssistedQueryColumns() {
assertTrue(new EncryptRule(encryptRuleConfig).getAssistedQueryColumns(table).isEmpty());
}
@Test
public void assertGetAssistedQueryAndPlainColumns() {
assertFalse(new EncryptRule(encryptRuleConfig).getAssistedQueryAndPlainColumns(table).isEmpty());
}
@Test
public void assertGetLogicAndCipherColumns() {
assertFalse(new EncryptRule(encryptRuleConfig).getLogicAndCipherColumns(table).isEmpty());
}
@Test
public void assertGetLogicAndPlainColumns() {
assertFalse(new EncryptRule(encryptRuleConfig).getLogicAndPlainColumns(table).isEmpty());
}
@Test
public void assertGetEncryptTableNames() {
assertFalse(new EncryptRule(encryptRuleConfig).getEncryptTableNames().isEmpty());
}
}
/*
* 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.core.strategy.encrypt.impl;
import org.apache.shardingsphere.core.strategy.encrypt.EncryptColumn;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public final class EncryptColumnTest {
@Test
public void assertGetAssistedQueryColumn() {
assertTrue(new EncryptColumn("cipherColumn", "assistedQueryColumn", "plainColumn", "encryptor").getAssistedQueryColumn().isPresent());
}
@Test
public void assertGetPlainColumn() {
assertTrue(new EncryptColumn("cipherColumn", "assistedQueryColumn", "plainColumn", "encryptor").getPlainColumn().isPresent());
}
}
/*
* 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.core.strategy.encrypt.impl;
import com.google.common.collect.ImmutableMap;
import org.apache.shardingsphere.api.config.encrypt.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.api.config.encrypt.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.core.exception.ShardingException;
import org.apache.shardingsphere.core.strategy.encrypt.EncryptTable;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public final class EncryptTableTest {
private EncryptTable encryptTable;
@Before
public void setUp() {
EncryptTableRuleConfiguration config = mock(EncryptTableRuleConfiguration.class);
EncryptColumnRuleConfiguration encryptColumnRuleConfiguration = mock(EncryptColumnRuleConfiguration.class);
when(config.getColumns()).thenReturn(ImmutableMap.of("key", encryptColumnRuleConfiguration));
when(encryptColumnRuleConfiguration.getCipherColumn()).thenReturn("cipherColumn");
when(encryptColumnRuleConfiguration.getAssistedQueryColumn()).thenReturn("assistedQueryColumn");
when(encryptColumnRuleConfiguration.getPlainColumn()).thenReturn("plainColumn");
when(encryptColumnRuleConfiguration.getEncryptor()).thenReturn("encryptor");
encryptTable = new EncryptTable(config);
}
@Test
public void assertGetLogicColumn() {
assertNotNull(encryptTable.getLogicColumn("cipherColumn"));
}
@Test(expected = ShardingException.class)
public void assertGetLogicColumnShardingExceptionThrownWhenCipherColumnAbsent() {
encryptTable.getLogicColumn("___cipherColumn");
}
@Test
public void assertGetLogicColumns() {
assertFalse(encryptTable.getLogicColumns().isEmpty());
}
@Test
public void assertFindPlainColumn() {
assertFalse(encryptTable.findPlainColumn("logicColumn").isPresent());
}
@Test
public void assertGetLogicAndCipherColumns() {
assertFalse(encryptTable.getLogicAndCipherColumns().isEmpty());
}
@Test
public void assertGetLogicAndPlainColumns() {
assertFalse(encryptTable.getLogicAndPlainColumns().isEmpty());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册