Skip to content

Commit f7b64d2

Browse files
committed
Verify another alias from another ticket
Related: #1655
1 parent 31e1327 commit f7b64d2

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/HqlQueryTransformerTests.java

+22-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.assertj.core.api.SoftAssertions;
2323
import org.junit.jupiter.api.Test;
2424
import org.springframework.dao.InvalidDataAccessApiUsageException;
25+
import org.springframework.data.domain.PageRequest;
2526
import org.springframework.data.domain.Sort;
2627
import org.springframework.data.jpa.domain.JpaSort;
2728
import org.springframework.lang.Nullable;
@@ -823,11 +824,27 @@ void sortShouldWorkWhenAliasingFunctions() {
823824
LEFT JOIN bundle bundle ON event.id = bundle.event_id
824825
GROUP BY event.id
825826
""", Sort.by(Sort.Direction.ASC, "cheapestBundlePrice") //
826-
.and(Sort.by(
827-
Sort.Direction.ASC, "earliestBundleStart")) //
828-
.and(Sort.by(Sort.Direction.ASC,
829-
"name"))))
830-
.endsWith(" order by cheapestBundlePrice asc, earliestBundleStart asc, name asc");
827+
.and(Sort.by(Sort.Direction.ASC, "earliestBundleStart")) //
828+
.and(Sort.by(Sort.Direction.ASC, "name"))))
829+
.endsWith(" order by cheapestBundlePrice asc, earliestBundleStart asc, name asc");
830+
}
831+
832+
@Test // GH-2863, GH-1655
833+
void shouldHandleAliasInsideCaseStatement() {
834+
835+
Sort sort = PageRequest.of(0, 20, Sort.Direction.DESC, "newDateDue").getSort();
836+
837+
assertThat(createQueryFor("Select DISTINCT new " + //
838+
"com.api.dto.FilterDTO(c.id, p.id, CASE WHEN item.dateDue IS NOT NULL THEN item.dateDue ELSE p.dateDue END AS newDateDue) "
839+
+ "FROM Customer c " + //
840+
"join c.productOrder p " + //
841+
"JOIN p.items item", //
842+
sort)).isEqualTo("Select DISTINCT new " + //
843+
"com.api.dto.FilterDTO(c.id, p.id, CASE WHEN item.dateDue IS NOT NULL THEN item.dateDue ELSE p.dateDue END AS newDateDue) "
844+
+ "FROM Customer c " + //
845+
"join c.productOrder p " + //
846+
"JOIN p.items item " + //
847+
"order by newDateDue desc");
831848
}
832849

833850
private void assertCountQuery(String originalQuery, String countQuery) {

0 commit comments

Comments
 (0)