Skip to content

Commit 3d4f27f

Browse files
committed
Polishing.
Extend tests to use aliased columns. See #1362 Original pull request: #1368
1 parent fe181e1 commit 3d4f27f

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/render/SelectRendererUnitTests.java

+21-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,20 @@
2121
import org.junit.jupiter.api.Test;
2222
import org.springframework.data.relational.core.dialect.PostgresDialect;
2323
import org.springframework.data.relational.core.dialect.RenderContextFactory;
24-
import org.springframework.data.relational.core.sql.*;
24+
import org.springframework.data.relational.core.sql.AnalyticFunction;
25+
import org.springframework.data.relational.core.sql.Column;
26+
import org.springframework.data.relational.core.sql.Comparison;
27+
import org.springframework.data.relational.core.sql.Conditions;
28+
import org.springframework.data.relational.core.sql.Expressions;
29+
import org.springframework.data.relational.core.sql.Functions;
30+
import org.springframework.data.relational.core.sql.InlineQuery;
31+
import org.springframework.data.relational.core.sql.LockMode;
32+
import org.springframework.data.relational.core.sql.OrderByField;
33+
import org.springframework.data.relational.core.sql.SQL;
34+
import org.springframework.data.relational.core.sql.Select;
35+
import org.springframework.data.relational.core.sql.SqlIdentifier;
36+
import org.springframework.data.relational.core.sql.StatementBuilder;
37+
import org.springframework.data.relational.core.sql.Table;
2538
import org.springframework.util.StringUtils;
2639

2740
/**
@@ -269,23 +282,24 @@ void shouldRenderJoinWithTwoInlineQueries() {
269282
Table department = SQL.table("department");
270283

271284
Select innerSelectOne = Select.builder()
272-
.select(employee.column("id"), employee.column("department_Id"), employee.column("name")).from(employee)
285+
.select(employee.column("id").as("empId"), employee.column("department_Id"), employee.column("name"))
286+
.from(employee)
273287
.build();
274288
Select innerSelectTwo = Select.builder().select(department.column("id"), department.column("name")).from(department)
275289
.build();
276290

277291
InlineQuery one = InlineQuery.create(innerSelectOne, "one");
278292
InlineQuery two = InlineQuery.create(innerSelectTwo, "two");
279293

280-
Select select = Select.builder().select(one.column("id"), two.column("name")).from(one) //
281-
.join(two).on(two.column("department_id")).equals(one.column("id")) //
294+
Select select = Select.builder().select(one.column("empId"), two.column("name")).from(one) //
295+
.join(two).on(two.column("department_id")).equals(one.column("empId")) //
282296
.build();
283297

284298
String sql = SqlRenderer.toString(select);
285-
assertThat(sql).isEqualTo("SELECT one.id, two.name FROM (" //
286-
+ "SELECT employee.id, employee.department_Id, employee.name FROM employee) one " //
299+
assertThat(sql).isEqualTo("SELECT one.empId, two.name FROM (" //
300+
+ "SELECT employee.id AS empId, employee.department_Id, employee.name FROM employee) one " //
287301
+ "JOIN (SELECT department.id, department.name FROM department) two " //
288-
+ "ON two.department_id = one.id");
302+
+ "ON two.department_id = one.empId");
289303
}
290304

291305
@Test // DATAJDBC-309

0 commit comments

Comments
 (0)