|
25 | 25 | import org.junit.jupiter.api.Test;
|
26 | 26 | import org.springframework.data.domain.Sort;
|
27 | 27 | import org.springframework.data.mongodb.core.aggregation.ArrayOperators.ArrayToObject;
|
| 28 | +import org.springframework.data.mongodb.core.aggregation.ArrayOperators.SortArray; |
28 | 29 |
|
29 | 30 | /**
|
30 | 31 | * Unit tests for {@link ArrayOperators}
|
@@ -179,4 +180,27 @@ void sortByWithFieldRef() {
|
179 | 180 | assertThat(ArrayOperators.arrayOf("team").sort(Sort.by("name")).toDocument(Aggregation.DEFAULT_CONTEXT))
|
180 | 181 | .isEqualTo("{ $sortArray: { input: \"$team\", sortBy: { name: 1 } } }");
|
181 | 182 | }
|
| 183 | + |
| 184 | + @Test // GH-4929 |
| 185 | + public void sortArrayByValueAscending() { |
| 186 | + Document result = SortArray.sortArrayOf("numbers").byValueAscending().toDocument(Aggregation.DEFAULT_CONTEXT); |
| 187 | + Document expected = new Document("$sortArray", new Document("input", "$numbers").append("sortBy", 1)); |
| 188 | + assertThat(result).isEqualTo(expected); |
| 189 | + } |
| 190 | + |
| 191 | + @Test // GH-4929 |
| 192 | + public void sortArrayByValueDescending() { |
| 193 | + Document result = SortArray.sortArrayOf("numbers").byValueDescending().toDocument(Aggregation.DEFAULT_CONTEXT); |
| 194 | + Document expected = new Document("$sortArray", new Document("input", "$numbers").append("sortBy", -1)); |
| 195 | + assertThat(result).isEqualTo(expected); |
| 196 | + } |
| 197 | + |
| 198 | + @Test // GH-4929 |
| 199 | + public void sortArrayByPropertyUnchanged() { |
| 200 | + Document result = SortArray.sortArrayOf("items").by(Sort.by(Sort.Direction.ASC, "price")) |
| 201 | + .toDocument(Aggregation.DEFAULT_CONTEXT); |
| 202 | + Document expected = new Document("$sortArray", |
| 203 | + new Document("input", "$items").append("sortBy", new Document("price", 1))); |
| 204 | + assertThat(result).isEqualTo(expected); |
| 205 | + } |
182 | 206 | }
|
0 commit comments