View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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.shadow.distsql.segment.ShadowRuleSegment;
23  import org.apache.shardingsphere.shadow.distsql.statement.AlterShadowRuleStatement;
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.ShadowRuleAssert;
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.ExpectedShadowRule;
28  import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.shadow.AlterShadowRuleStatementTestCase;
29  
30  import java.util.Collection;
31  import java.util.List;
32  
33  import static org.junit.jupiter.api.Assertions.assertNotNull;
34  import static org.junit.jupiter.api.Assertions.assertNull;
35  
36  /**
37   * Alter shadow rule statement assert.
38   */
39  @NoArgsConstructor(access = AccessLevel.PRIVATE)
40  public final class AlterShadowRuleStatementAssert {
41      
42      /**
43       * Assert alter shadow rule statement is correct with expected parser result.
44       *
45       * @param assertContext assert context
46       * @param actual actual alter shadow rule statement
47       * @param expected expected alter shadow rule statement test case
48       */
49      public static void assertIs(final SQLCaseAssertContext assertContext, final AlterShadowRuleStatement actual, final AlterShadowRuleStatementTestCase expected) {
50          if (ExistingAssert.assertIs(assertContext, actual, expected)) {
51              assertShadowRule(assertContext, actual.getRules(), expected.getRules());
52          }
53      }
54      
55      private static void assertShadowRule(final SQLCaseAssertContext assertContext, final Collection<ShadowRuleSegment> actual, final List<ExpectedShadowRule> expected) {
56          if (null == expected) {
57              assertNull(actual, assertContext.getText("Actual shadow rule should not exist."));
58          } else {
59              assertNotNull(actual, assertContext.getText("Actual shadow rule should exist."));
60              int count = 0;
61              for (ShadowRuleSegment each : actual) {
62                  ShadowRuleAssert.assertIs(assertContext, each, expected.get(count));
63                  count++;
64              }
65          }
66      }
67  }