DATAJPA-1679 - Added a test.

Original pull request: #414.

Signed-off-by: Jens Schauder <jschauder@pivotal.io>
This commit is contained in:
Jens Schauder
2020-03-09 12:45:42 +01:00
parent 19c88393ff
commit f466b0f008

View File

@@ -21,6 +21,7 @@ import static org.springframework.data.jpa.repository.query.QueryUtils.*;
import java.util.Collections;
import java.util.Set;
import org.assertj.core.api.SoftAssertions;
import org.junit.Test;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.Sort;
@@ -483,6 +484,22 @@ public class QueryUtilsUnitTests {
assertThat(detectAlias("select * from User\nu\norder \n by name")).isEqualTo("u");
}
@Test // DATAJPA-1679
public void findProjectionClauseWithDistinct() {
SoftAssertions.assertSoftly(sofly -> {
sofly.assertThat(QueryUtils.getProjection("select * from x")).isEqualTo("*");
sofly.assertThat(QueryUtils.getProjection("select a, b, c from x")).isEqualTo("a, b, c");
sofly.assertThat(QueryUtils.getProjection("select distinct a, b, c from x")).isEqualTo("a, b, c");
sofly.assertThat(QueryUtils.getProjection("select DISTINCT a, b, c from x")).isEqualTo("a, b, c");
});
}
@Test // DATAJPA-1679
public void findProjectionClauseWithSubselect() {
assertThat(QueryUtils.getProjection("select * from (select x from y)")).isEqualTo("*");
}
private static void assertCountQuery(String originalQuery, String countQuery) {
assertThat(createCountQueryFor(originalQuery)).isEqualTo(countQuery);
}