-
Notifications
You must be signed in to change notification settings - Fork 55
Fix sorting issue #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...-data-jdbc-querydsl/src/test/java/com/infobip/spring/data/jdbc/sorting/SortingEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.infobip.spring.data.jdbc.sorting; | ||
|
|
||
| import lombok.*; | ||
| import org.springframework.data.annotation.Id; | ||
| import org.springframework.data.relational.core.mapping.Column; | ||
| import org.springframework.data.relational.core.mapping.Table; | ||
|
|
||
| @Value | ||
| @Table("sorting_entity") | ||
| public class SortingEntity { | ||
|
|
||
| @With | ||
| @Id | ||
| @Column("id") | ||
| private final Long id; | ||
|
|
||
| @Column("foo_bar") | ||
| private final String fooBar; | ||
| } |
7 changes: 7 additions & 0 deletions
7
...dsl/src/test/java/com/infobip/spring/data/jdbc/sorting/SortingEntityPagingRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.infobip.spring.data.jdbc.sorting; | ||
|
|
||
| import com.infobip.spring.data.jdbc.QuerydslJdbcRepository; | ||
|
|
||
| public interface SortingEntityPagingRepository extends QuerydslJdbcRepository<SortingEntity, Long> { | ||
|
|
||
| } |
91 changes: 91 additions & 0 deletions
91
...src/test/java/com/infobip/spring/data/jdbc/sorting/SortingEntityPagingRepositoryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package com.infobip.spring.data.jdbc.sorting; | ||
|
|
||
| import com.infobip.spring.data.jdbc.TestBase; | ||
| import lombok.AllArgsConstructor; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Sort; | ||
| import org.springframework.data.domain.Sort.Order; | ||
| import org.springframework.data.querydsl.QPageRequest; | ||
|
|
||
| import static com.infobip.spring.data.jdbc.sorting.QSortingEntity.sortingEntity; | ||
| import static org.assertj.core.api.BDDAssertions.then; | ||
|
|
||
| @AllArgsConstructor | ||
| public class SortingEntityPagingRepositoryTest extends TestBase { | ||
|
|
||
| private final SortingEntityPagingRepository repository; | ||
|
|
||
| @Test | ||
| void shouldFindByPage() { | ||
| // given | ||
| SortingEntity givenEntity = repository.save(new SortingEntity(null, "givenValue")); | ||
|
|
||
| // when | ||
| Page<SortingEntity> actual = repository.findAll(PageRequest.of(0, 1)); | ||
|
|
||
| then(actual.getContent()).containsExactly(givenEntity); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldSortUsingQSort() { | ||
| // given | ||
| SortingEntity givenEntityA = repository.save(new SortingEntity(null, "A")); | ||
| SortingEntity givenEntityC = repository.save(new SortingEntity(null, "C")); | ||
| SortingEntity givenEntityB = repository.save(new SortingEntity(null, "B")); | ||
|
|
||
| // when | ||
| Page<SortingEntity> actual = repository.findAll(QPageRequest.of(0, 5, sortingEntity.fooBar.desc())); | ||
|
|
||
| then(actual.getContent()).containsExactly(givenEntityC, givenEntityB, givenEntityA); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldSortUsingSort() { | ||
| // given | ||
| SortingEntity givenEntityA = repository.save(new SortingEntity(null, "A")); | ||
| SortingEntity givenEntityC = repository.save(new SortingEntity(null, "C")); | ||
| SortingEntity givenEntityB = repository.save(new SortingEntity(null, "B")); | ||
|
|
||
| // when | ||
| Page<SortingEntity> actual = repository.findAll(PageRequest.of(0, 5, Sort.by(Order.desc("fooBar")))); | ||
|
|
||
| then(actual.getContent()).containsExactly(givenEntityC, givenEntityB, givenEntityA); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldSortUsingQSortCombinedWithPredicate() { | ||
| // given | ||
| SortingEntity givenEntityA = repository.save(new SortingEntity(null, "1A")); | ||
| SortingEntity givenEntityC = repository.save(new SortingEntity(null, "1C")); | ||
| SortingEntity givenEntityB = repository.save(new SortingEntity(null, "1B")); | ||
| SortingEntity otherEntity = repository.save(new SortingEntity(null, "2")); | ||
|
|
||
| // when | ||
| Page<SortingEntity> actual = repository.findAll( | ||
| sortingEntity.fooBar.startsWith("1"), | ||
| QPageRequest.of(0, 5, sortingEntity.fooBar.desc()) | ||
| ); | ||
|
|
||
| then(actual.getContent()).containsExactly(givenEntityC, givenEntityB, givenEntityA); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldSortUsingSortCombinedWithPredicate() { | ||
| // given | ||
| SortingEntity givenEntityA = repository.save(new SortingEntity(null, "1A")); | ||
| SortingEntity givenEntityC = repository.save(new SortingEntity(null, "1C")); | ||
| SortingEntity givenEntityB = repository.save(new SortingEntity(null, "1B")); | ||
| SortingEntity otherEntity = repository.save(new SortingEntity(null, "2")); | ||
|
|
||
| // when | ||
| Page<SortingEntity> actual = repository.findAll( | ||
| sortingEntity.fooBar.startsWith("1"), | ||
| PageRequest.of(0, 5, Sort.by(Order.desc("fooBar"))) | ||
| ); | ||
|
|
||
| then(actual.getContent()).containsExactly(givenEntityC, givenEntityB, givenEntityA); | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...ata-r2dbc-querydsl/src/test/java/com/infobip/spring/data/r2dbc/sorting/SortingEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.infobip.spring.data.r2dbc.sorting; | ||
|
|
||
| import lombok.Value; | ||
| import lombok.With; | ||
| import org.springframework.data.annotation.Id; | ||
| import org.springframework.data.relational.core.mapping.Column; | ||
| import org.springframework.data.relational.core.mapping.Table; | ||
|
|
||
| @Value | ||
| @Table("sorting_entity") | ||
| public class SortingEntity { | ||
|
|
||
| @With | ||
| @Id | ||
| @Column("id") | ||
| private final Long id; | ||
|
|
||
| @Column("foo_bar") | ||
| private final String fooBar; | ||
| } |
7 changes: 7 additions & 0 deletions
7
...sl/src/test/java/com/infobip/spring/data/r2dbc/sorting/SortingEntityPagingRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.infobip.spring.data.r2dbc.sorting; | ||
|
|
||
| import com.infobip.spring.data.r2dbc.QuerydslR2dbcRepository; | ||
|
|
||
| public interface SortingEntityPagingRepository extends QuerydslR2dbcRepository<SortingEntity, Long> { | ||
|
|
||
| } |
117 changes: 117 additions & 0 deletions
117
...rc/test/java/com/infobip/spring/data/r2dbc/sorting/SortingEntityPagingRepositoryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| package com.infobip.spring.data.r2dbc.sorting; | ||
|
|
||
| import com.infobip.spring.data.r2dbc.TestBase; | ||
| import lombok.AllArgsConstructor; | ||
| import org.assertj.core.api.BDDAssertions; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.data.domain.Sort; | ||
| import org.springframework.data.domain.Sort.Order; | ||
| import reactor.core.publisher.Flux; | ||
| import reactor.test.StepVerifier; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.function.Predicate; | ||
|
|
||
| import static com.infobip.spring.data.r2dbc.sorting.QSortingEntity.sortingEntity; | ||
|
|
||
| @AllArgsConstructor | ||
| public class SortingEntityPagingRepositoryTest extends TestBase { | ||
|
|
||
| private final SortingEntityPagingRepository repository; | ||
|
|
||
| @Test | ||
| void shouldSortUsingQSort() { | ||
| // given | ||
| SortingEntity givenEntityA = new SortingEntity(null, "A"); | ||
| SortingEntity givenEntityC = new SortingEntity(null, "C"); | ||
| SortingEntity givenEntityB = new SortingEntity(null, "B"); | ||
|
|
||
| Flux<SortingEntity> given = repository.saveAll(Arrays.asList(givenEntityA, givenEntityC, givenEntityB)); | ||
|
|
||
| // when | ||
| Flux<SortingEntity> actual = given.thenMany(repository.findAll(sortingEntity.fooBar.desc())); | ||
|
|
||
| // then | ||
| StepVerifier.create(actual) | ||
| .expectNextMatches(sortingEntity(givenEntityC.getFooBar())) | ||
| .expectNextMatches(sortingEntity(givenEntityB.getFooBar())) | ||
| .expectNextMatches(sortingEntity(givenEntityA.getFooBar())) | ||
| .verifyComplete(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldSortUsingSort() { | ||
| // given | ||
| SortingEntity givenEntityA = new SortingEntity(null, "A"); | ||
| SortingEntity givenEntityC = new SortingEntity(null, "C"); | ||
| SortingEntity givenEntityB = new SortingEntity(null, "B"); | ||
|
|
||
| Flux<SortingEntity> given = repository.saveAll(Arrays.asList(givenEntityA, givenEntityC, givenEntityB)); | ||
|
|
||
| // when | ||
| Flux<SortingEntity> actual = given.thenMany(repository.findAll(Sort.by(Order.desc("fooBar")))); | ||
|
|
||
| // then | ||
| StepVerifier.create(actual) | ||
| .expectNextMatches(sortingEntity(givenEntityC.getFooBar())) | ||
| .expectNextMatches(sortingEntity(givenEntityB.getFooBar())) | ||
| .expectNextMatches(sortingEntity(givenEntityA.getFooBar())) | ||
| .verifyComplete(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldSortUsingQSortCombinedWithPredicate() { | ||
| // given | ||
| SortingEntity givenEntityA = new SortingEntity(null, "1A"); | ||
| SortingEntity givenEntityC = new SortingEntity(null, "1C"); | ||
| SortingEntity givenEntityB = new SortingEntity(null, "1B"); | ||
| SortingEntity otherEntity = new SortingEntity(null, "2"); | ||
|
|
||
| Flux<SortingEntity> given = repository.saveAll(Arrays.asList(givenEntityA, givenEntityC, givenEntityB, otherEntity)); | ||
|
|
||
| // when | ||
| Flux<SortingEntity> actual = given.thenMany(repository.findAll( | ||
| sortingEntity.fooBar.startsWith("1"), | ||
| sortingEntity.fooBar.desc() | ||
| )); | ||
|
|
||
| // then | ||
| StepVerifier.create(actual) | ||
| .expectNextMatches(sortingEntity(givenEntityC.getFooBar())) | ||
| .expectNextMatches(sortingEntity(givenEntityB.getFooBar())) | ||
| .expectNextMatches(sortingEntity(givenEntityA.getFooBar())) | ||
| .verifyComplete(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldSortUsingSortCombinedWithPredicate() { | ||
| // given | ||
| SortingEntity givenEntityA = new SortingEntity(null, "1A"); | ||
| SortingEntity givenEntityC = new SortingEntity(null, "1C"); | ||
| SortingEntity givenEntityB = new SortingEntity(null, "1B"); | ||
| SortingEntity otherEntity = new SortingEntity(null, "2"); | ||
|
|
||
| Flux<SortingEntity> given = repository.saveAll(Arrays.asList(givenEntityA, givenEntityC, givenEntityB, otherEntity)); | ||
|
|
||
| // when | ||
| Flux<SortingEntity> actual = given.thenMany(repository.findAll( | ||
| sortingEntity.fooBar.startsWith("1"), | ||
| Sort.by(Order.desc("fooBar")) | ||
| )); | ||
|
|
||
| // then | ||
| StepVerifier.create(actual) | ||
| .expectNextMatches(sortingEntity(givenEntityC.getFooBar())) | ||
| .expectNextMatches(sortingEntity(givenEntityB.getFooBar())) | ||
| .expectNextMatches(sortingEntity(givenEntityA.getFooBar())) | ||
| .verifyComplete(); | ||
| } | ||
|
|
||
| private Predicate<SortingEntity> sortingEntity(String fooBarValue) { | ||
| return entity -> { | ||
| BDDAssertions.then(entity).isEqualTo(new SortingEntity(entity.getId(), fooBarValue)); | ||
| return true; | ||
| }; | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be moved above line 97 to minimize the scope (since it's merged I'll do it on master)