Skip to content

Commit

Permalink
add assertExpressionProjection
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Jan 18, 2020
1 parent 5464b86 commit a5a9d37
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedAggregationDistinctProjection;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedAggregationProjection;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedColumnProjection;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedExpressionProjection;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedProjection;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedProjections;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedShorthandProjection;
import org.apache.shardingsphere.sql.parser.integrate.jaxb.projection.ExpectedTableSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.AggregationDistinctProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.AggregationProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ColumnProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ExpressionProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ProjectionSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ProjectionsSegment;
import org.apache.shardingsphere.sql.parser.sql.segment.dml.item.ShorthandProjectionSegment;
Expand Down Expand Up @@ -87,16 +89,15 @@ private static void assertProjection(final SQLStatementAssertMessage assertMessa
} else if (actual instanceof AggregationProjectionSegment) {
assertThat(assertMessage.getText("Projection type assertion error: "), expected, instanceOf(ExpectedAggregationProjection.class));
assertAggregationProjection(assertMessage, (AggregationProjectionSegment) actual, (ExpectedAggregationProjection) expected);
}
if (!(actual instanceof ColumnProjectionSegment) && !(actual instanceof AggregationProjectionSegment)) {
assertThat(assertMessage.getText("Projection text assertion error: "), actual.getText(), is(expectedText));
} else if (actual instanceof ExpressionProjectionSegment) {
assertThat(assertMessage.getText("Projection type assertion error: "), expected, instanceOf(ExpectedExpressionProjection.class));
assertExpressionProjection(assertMessage, (ExpressionProjectionSegment) actual, (ExpectedExpressionProjection) expected);
}
assertThat(assertMessage.getText("Projection start index assertion error: "), actual.getStartIndex(), is(expected.getStartIndex()));
assertThat(assertMessage.getText("Projection stop index assertion error: "), actual.getStopIndex(), is(expected.getStopIndex()));
}

private static void assertShorthandProjection(final SQLStatementAssertMessage assertMessage, final ShorthandProjectionSegment actual, final ExpectedShorthandProjection expected) {
assertThat(assertMessage.getText("Shorthand projection text assertion error: "), actual.getText(), is(expected.getText()));
if (actual.getOwner().isPresent()) {
assertOwner(assertMessage, actual.getOwner().get(), expected.getOwner());
} else {
Expand Down Expand Up @@ -127,6 +128,10 @@ private static void assertAggregationProjection(final SQLStatementAssertMessage
}
}

private static void assertExpressionProjection(final SQLStatementAssertMessage assertMessage, final ExpressionProjectionSegment actual, final ExpectedExpressionProjection expected) {
assertThat(assertMessage.getText("Expression projection alias assertion error: "), actual.getAlias().orNull(), is(expected.getAlias()));
}

private static void assertOwner(final SQLStatementAssertMessage assertMessage, final TableSegment actual, final ExpectedTableSegment expected) {
assertThat(assertMessage.getText("Projection owner name assertion error: "), actual.getTableName(), is(expected.getName()));
assertThat(assertMessage.getText("Projection owner name start delimiter assertion error: "), actual.getTableQuoteCharacter().getStartDelimiter(), is(expected.getStartDelimiter()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<table name="t_order" start-index="14" stop-index="20" />
</tables>
<projections start-index="7" stop-index="7">
<shorthand-projection text="*" start-index="7" stop-index="7" />
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<sharding-conditions>
<and-condition>
Expand Down

0 comments on commit a5a9d37

Please sign in to comment.