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.sharding.distsql.statement.AlterDefaultShardingStrategyStatement;
23  import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
24  import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ExistingAssert;
25  import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.sharding.AlterDefaultShardingStrategyStatementTestCase;
26  
27  import static org.hamcrest.CoreMatchers.is;
28  import static org.hamcrest.MatcherAssert.assertThat;
29  
30  /**
31   * Alter default sharding strategy statement assert.
32   */
33  @NoArgsConstructor(access = AccessLevel.PRIVATE)
34  public final class AlterDefaultShardingStrategyStatementAssert {
35      
36      /**
37       * Assert alter default sharding strategy statement is correct with expected parser result.
38       *
39       * @param assertContext assert context
40       * @param actual actual alter default sharding strategy statement
41       * @param expected expected alter default sharding strategy statement test case
42       */
43      public static void assertIs(final SQLCaseAssertContext assertContext, final AlterDefaultShardingStrategyStatement actual, final AlterDefaultShardingStrategyStatementTestCase expected) {
44          if (ExistingAssert.assertIs(assertContext, actual, expected)) {
45              assertThat(assertContext.getText(String.format("`%s`'s default sharding strategy segment assertion error: ", actual.getClass().getSimpleName())),
46                      actual.getDefaultType(), is(expected.getStrategy().getDefaultType()));
47              assertThat(assertContext.getText(String.format("`%s`'s default sharding strategy segment assertion error: ", actual.getClass().getSimpleName())),
48                      actual.getShardingColumn(), is(expected.getStrategy().getShardingColumn()));
49              assertThat(assertContext.getText(String.format("`%s`'s default sharding strategy segment assertion error: ", actual.getClass().getSimpleName())),
50                      actual.getStrategyType(), is(expected.getStrategy().getStrategyType()));
51              if (!"none".equalsIgnoreCase(actual.getStrategyType())) {
52                  assertThat(assertContext.getText(String.format("`%s`'s default sharding strategy segment assertion error: ", actual.getClass().getSimpleName())),
53                          actual.getAlgorithmSegment().getName(), is(expected.getStrategy().getAlgorithmSegment().getName()));
54              }
55          }
56      }
57  }