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.statement.rdl.alter.impl;
19
20 import lombok.AccessLevel;
21 import lombok.NoArgsConstructor;
22 import org.apache.shardingsphere.sharding.distsql.segment.table.TableReferenceRuleSegment;
23 import org.apache.shardingsphere.sharding.distsql.statement.AlterShardingTableReferenceRuleStatement;
24 import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
25 import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.segment.distsql.rdl.ShardingTableReferenceRuleAssert;
26 import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ExistingAssert;
27 import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.distsql.rdl.ExpectedShardingTableReferenceRule;
28 import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.sharding.AlterShardingTableReferenceRulesStatementTestCase;
29
30 import java.util.Collection;
31 import java.util.List;
32
33 import static org.hamcrest.CoreMatchers.is;
34 import static org.junit.jupiter.api.Assertions.assertNotNull;
35 import static org.junit.jupiter.api.Assertions.assertNull;
36 import static org.hamcrest.MatcherAssert.assertThat;
37
38
39
40
41 @NoArgsConstructor(access = AccessLevel.PRIVATE)
42 public final class AlterShardingTableReferenceRulesStatementAssert {
43
44
45
46
47
48
49
50
51 public static void assertIs(final SQLCaseAssertContext assertContext, final AlterShardingTableReferenceRuleStatement actual, final AlterShardingTableReferenceRulesStatementTestCase expected) {
52 if (ExistingAssert.assertIs(assertContext, actual, expected)) {
53 assertShardingBindingTableRules(assertContext, actual.getRules(), expected.getRules());
54 }
55 }
56
57 private static void assertShardingBindingTableRules(final SQLCaseAssertContext assertContext, final Collection<TableReferenceRuleSegment> actual,
58 final List<ExpectedShardingTableReferenceRule> expected) {
59 if (null == expected) {
60 assertNull(actual, assertContext.getText("Actual sharding table reference rule should not exist."));
61 } else {
62 assertNotNull(actual, assertContext.getText("Actual sharding table reference rule should exist."));
63 assertThat(assertContext.getText(String.format("Actual sharding table reference rule size should be %s , but it was %s", expected.size(), actual.size())),
64 actual.size(), is(expected.size()));
65 int count = 0;
66 for (TableReferenceRuleSegment each : actual) {
67 ShardingTableReferenceRuleAssert.assertIs(assertContext, each, expected.get(count));
68 count++;
69 }
70 }
71 }
72 }