1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.distsql.rdl;
19
20 import lombok.AccessLevel;
21 import lombok.NoArgsConstructor;
22 import org.apache.shardingsphere.encrypt.distsql.segment.EncryptColumnSegment;
23 import org.apache.shardingsphere.encrypt.distsql.segment.EncryptRuleSegment;
24 import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
25 import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.distsql.rdl.ExpectedEncryptColumn;
26 import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.distsql.rdl.ExpectedEncryptRule;
27
28 import java.util.Collection;
29 import java.util.List;
30
31 import static org.hamcrest.CoreMatchers.is;
32 import static org.hamcrest.MatcherAssert.assertThat;
33 import static org.junit.jupiter.api.Assertions.assertFalse;
34 import static org.junit.jupiter.api.Assertions.assertNotNull;
35 import static org.junit.jupiter.api.Assertions.assertNull;
36
37
38
39
40 @NoArgsConstructor(access = AccessLevel.PRIVATE)
41 public final class EncryptRuleAssert {
42
43
44
45
46
47
48
49
50 public static void assertIs(final SQLCaseAssertContext assertContext, final EncryptRuleSegment actual, final ExpectedEncryptRule expected) {
51 if (null == expected) {
52 assertNull(actual, assertContext.getText("Actual encrypt rule should not exist."));
53 } else {
54 assertNotNull(actual, assertContext.getText("Actual encrypt rule should exist."));
55 assertThat(assertContext.getText("encrypt rule assertion error: "), actual.getTableName(), is(expected.getName()));
56 assertEncryptColumns(assertContext, actual.getColumns(), expected.getColumns());
57 }
58 }
59
60 private static void assertEncryptColumns(final SQLCaseAssertContext assertContext, final Collection<EncryptColumnSegment> actual, final List<ExpectedEncryptColumn> expected) {
61 if (expected.isEmpty()) {
62 assertNull(actual, assertContext.getText("Actual encrypt column should not exist."));
63 } else {
64 assertFalse(actual.isEmpty(), assertContext.getText("Actual encrypt column should exist."));
65 assertThat(assertContext.getText(String.format("Actual encrypt column size should be %s, but it was %s.", expected.size(), actual.size())), actual.size(), is(expected.size()));
66 int count = 0;
67 for (EncryptColumnSegment encryptColumnSegment : actual) {
68 ExpectedEncryptColumn expectedEncryptColumn = expected.get(count);
69 EncryptColumnAssert.assertIs(assertContext, encryptColumnSegment, expectedEncryptColumn);
70 count++;
71 }
72 }
73 }
74 }