|
17 | 17 | package com.mongodb.hibernate.query.select;
|
18 | 18 |
|
19 | 19 | import static com.mongodb.hibernate.internal.MongoConstants.MONGO_DBMS_NAME;
|
20 |
| -import static com.mongodb.hibernate.internal.translate.mongoast.command.aggregate.AstSortOrder.ASC; |
21 | 20 | import static org.assertj.core.api.Assertions.assertThat;
|
22 | 21 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
23 | 22 | import static org.hibernate.cfg.QuerySettings.DEFAULT_NULL_ORDERING;
|
24 | 23 |
|
25 | 24 | import com.mongodb.hibernate.internal.FeatureNotSupportedException;
|
26 |
| -import com.mongodb.hibernate.internal.translate.mongoast.command.aggregate.AstSortOrder; |
27 | 25 | import java.util.Arrays;
|
28 | 26 | import java.util.List;
|
29 | 27 | import org.hibernate.query.NullPrecedence;
|
|
35 | 33 | import org.junit.jupiter.api.Nested;
|
36 | 34 | import org.junit.jupiter.api.Test;
|
37 | 35 | import org.junit.jupiter.params.ParameterizedTest;
|
38 |
| -import org.junit.jupiter.params.provider.EnumSource; |
39 | 36 | import org.junit.jupiter.params.provider.ValueSource;
|
40 | 37 |
|
41 | 38 | @DomainModel(annotatedClasses = Book.class)
|
@@ -64,25 +61,26 @@ void beforeEach() {
|
64 | 61 | }
|
65 | 62 |
|
66 | 63 | @ParameterizedTest
|
67 |
| - @EnumSource(AstSortOrder.class) |
68 |
| - void testOrderBySingleFieldWithoutTies(AstSortOrder sortOrder) { |
| 64 | + @ValueSource(strings = {"ASC", "DESC"}) |
| 65 | + void testOrderBySingleFieldWithoutTies(String sortOrder) { |
69 | 66 | assertSelectionQuery(
|
70 | 67 | "from Book as b ORDER BY b.publishYear " + sortOrder,
|
71 | 68 | Book.class,
|
72 |
| - "{ 'aggregate': 'books', 'pipeline': [ { '$sort': { 'publishYear': " + (sortOrder == ASC ? "1" : "-1") |
| 69 | + "{ 'aggregate': 'books', 'pipeline': [ { '$sort': { 'publishYear': " |
| 70 | + + (sortOrder.equals("ASC") ? "1" : "-1") |
73 | 71 | + " } }, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true} } ] }",
|
74 |
| - sortOrder == ASC ? getBooksByIds(2, 1, 3, 4, 5) : getBooksByIds(5, 4, 3, 1, 2)); |
| 72 | + sortOrder.equals("ASC") ? getBooksByIds(2, 1, 3, 4, 5) : getBooksByIds(5, 4, 3, 1, 2)); |
75 | 73 | }
|
76 | 74 |
|
77 | 75 | @ParameterizedTest
|
78 |
| - @EnumSource(AstSortOrder.class) |
79 |
| - void testOrderBySingleFieldWithTies(AstSortOrder sortOrder) { |
| 76 | + @ValueSource(strings = {"ASC", "DESC"}) |
| 77 | + void testOrderBySingleFieldWithTies(String sortOrder) { |
80 | 78 | assertSelectionQuery(
|
81 | 79 | "from Book as b ORDER BY b.title " + sortOrder,
|
82 | 80 | Book.class,
|
83 |
| - "{ 'aggregate': 'books', 'pipeline': [ { '$sort': { 'title': " + (sortOrder == ASC ? "1" : "-1") |
| 81 | + "{ 'aggregate': 'books', 'pipeline': [ { '$sort': { 'title': " + (sortOrder.equals("ASC") ? "1" : "-1") |
84 | 82 | + " } }, {'$project': {'_id': true, 'discount': true, 'isbn13': true, 'outOfStock': true, 'price': true, 'publishYear': true, 'title': true} } ] }",
|
85 |
| - sortOrder == ASC |
| 83 | + sortOrder.equals("ASC") |
86 | 84 | ? resultList -> assertThat(resultList)
|
87 | 85 | .satisfiesAnyOf(
|
88 | 86 | list -> assertResultListEquals(getBooksByIds(3, 2, 4, 1, 5), list),
|
|
0 commit comments