Skip to content

Commit

Permalink
Add modify constraint definition test
Browse files Browse the repository at this point in the history
  • Loading branch information
zihaoAK47 committed Sep 19, 2023
1 parent 27d4aee commit 530d7a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.ModifyCollectionRetrievalSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.column.alter.RenameColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.AddConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.alter.ModifyConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.index.RenameIndexDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.table.ConvertTableDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
Expand All @@ -46,6 +47,7 @@
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.definition.ExpectedAddColumnDefinition;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.definition.ExpectedChangeColumnDefinition;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.definition.ExpectedColumnDefinition;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.definition.ExpectedConstraintDefinition;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.definition.ExpectedModifyColumnDefinition;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.definition.ExpectedRenameIndexDefinition;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.definition.ExpectedRenameColumnDefinition;
Expand Down Expand Up @@ -81,6 +83,7 @@ public static void assertIs(final SQLCaseAssertContext assertContext, final Alte
assertRenameTable(assertContext, actual, expected);
assertAddColumnDefinitions(assertContext, actual, expected);
assertAddConstraintDefinitions(assertContext, actual, expected);
assertModifyConstraintDefinitions(assertContext, actual, expected);
assertModifyColumnDefinitions(assertContext, actual, expected);
assertChangeColumnDefinitions(assertContext, actual, expected);
assertDropColumns(assertContext, actual, expected);
Expand Down Expand Up @@ -152,6 +155,22 @@ private static void assertAddConstraintDefinitions(final SQLCaseAssertContext as
}
}

private static void assertModifyConstraintDefinitions(final SQLCaseAssertContext assertContext, final AlterTableStatement actual, final AlterTableStatementTestCase expected) {
assertThat(assertContext.getText("Modify constraint definitions size assertion error: "), actual.getModifyConstraintDefinitions().size(), is(expected.getModifyConstraints().size()));
int count = 0;
for (ModifyConstraintDefinitionSegment each : actual.getModifyConstraintDefinitions()) {
ExpectedConstraintDefinition expectedConstraintDefinition = expected.getModifyConstraints().get(count);
if (null == expectedConstraintDefinition.getConstraintName()) {
assertNull(each.getConstraintName(), "Actual modify constraint name should not exist.");
} else {
assertNotNull(each.getConstraintName(), "Actual modify constraint name should exist.");
assertThat(assertContext.getText("Actual modify constraint name assertion error."),
each.getConstraintName().getIdentifier().getValue(), is(expectedConstraintDefinition.getConstraintName()));
}
count++;
}
}

private static void assertModifyColumnDefinitions(final SQLCaseAssertContext assertContext, final AlterTableStatement actual, final AlterTableStatementTestCase expected) {
assertThat(assertContext.getText("Modify column definitions size assertion error: "), actual.getModifyColumnDefinitions().size(), is(expected.getModifyColumns().size()));
int count = 0;
Expand Down
1 change: 1 addition & 0 deletions test/it/parser/src/main/resources/case/ddl/alter-table.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@

<alter-table sql-case-id="alter_table_modify7">
<table name="locations" start-index="12" stop-index="20" />
<modify-constraint start-index="22" stop-index="55" />
</alter-table>

<alter-table sql-case-id="alter_table_modify8">
Expand Down

0 comments on commit 530d7a2

Please sign in to comment.