|
19 | 19 |
|
20 | 20 | import org.junit.jupiter.api.Test;
|
21 | 21 | import org.springframework.data.relational.core.sql.Column;
|
| 22 | +import org.springframework.data.relational.core.sql.Expression; |
| 23 | +import org.springframework.data.relational.core.sql.Expressions; |
22 | 24 | import org.springframework.data.relational.core.sql.OrderByField;
|
23 | 25 | import org.springframework.data.relational.core.sql.SQL;
|
24 | 26 | import org.springframework.data.relational.core.sql.Select;
|
| 27 | +import org.springframework.data.relational.core.sql.SimpleFunction; |
25 | 28 | import org.springframework.data.relational.core.sql.Table;
|
26 | 29 |
|
| 30 | +import java.util.Arrays; |
| 31 | +import java.util.List; |
| 32 | + |
27 | 33 | /**
|
28 | 34 | * Unit tests for {@link OrderByClauseVisitor}.
|
29 | 35 | *
|
30 | 36 | * @author Mark Paluch
|
31 | 37 | * @author Jens Schauder
|
| 38 | + * @author Koen Punt |
32 | 39 | */
|
33 | 40 | class OrderByClauseVisitorUnitTests {
|
34 | 41 |
|
@@ -88,4 +95,38 @@ void shouldRenderOrderByFullyQualifiedNameWithTableAlias() {
|
88 | 95 | assertThat(visitor.getRenderedPart().toString()).isEqualTo("emp.name ASC");
|
89 | 96 | }
|
90 | 97 |
|
| 98 | + @Test // GH-1348 |
| 99 | + void shouldRenderOrderBySimpleFunction() { |
| 100 | + |
| 101 | + Table employee = SQL.table("employee").as("emp"); |
| 102 | + Column column = employee.column("name"); |
| 103 | + List<Expression> columns = Arrays.asList(employee.column("id"), column); |
| 104 | + |
| 105 | + SimpleFunction simpleFunction = SimpleFunction.create("GREATEST", columns); |
| 106 | + |
| 107 | + Select select = Select.builder().select(column).from(employee) |
| 108 | + .orderBy(OrderByField.from(simpleFunction).asc(), OrderByField.from(column).asc()).build(); |
| 109 | + |
| 110 | + OrderByClauseVisitor visitor = new OrderByClauseVisitor(new SimpleRenderContext(NamingStrategies.asIs())); |
| 111 | + select.visit(visitor); |
| 112 | + |
| 113 | + assertThat(visitor.getRenderedPart().toString()).isEqualTo("GREATEST(emp.id, emp.name) ASC, emp.name ASC"); |
| 114 | + } |
| 115 | + |
| 116 | + @Test // GH-1348 |
| 117 | + void shouldRenderOrderBySimpleExpression() { |
| 118 | + |
| 119 | + Table employee = SQL.table("employee").as("emp"); |
| 120 | + Column column = employee.column("name"); |
| 121 | + |
| 122 | + Expression simpleExpression = Expressions.just("1"); |
| 123 | + |
| 124 | + Select select = Select.builder().select(column).from(employee).orderBy(OrderByField.from(simpleExpression).asc()) |
| 125 | + .build(); |
| 126 | + |
| 127 | + OrderByClauseVisitor visitor = new OrderByClauseVisitor(new SimpleRenderContext(NamingStrategies.asIs())); |
| 128 | + select.visit(visitor); |
| 129 | + |
| 130 | + assertThat(visitor.getRenderedPart().toString()).isEqualTo("1 ASC"); |
| 131 | + } |
91 | 132 | }
|
0 commit comments