|
73 | 73 | import org.springframework.data.mongodb.core.query.Criteria;
|
74 | 74 | import org.springframework.data.mongodb.core.query.Query;
|
75 | 75 | import org.springframework.data.mongodb.core.query.Update;
|
| 76 | +import org.springframework.data.util.CloseableIterator; |
76 | 77 | import org.springframework.test.context.ContextConfiguration;
|
77 | 78 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
78 | 79 | import org.springframework.util.ObjectUtils;
|
@@ -2742,6 +2743,44 @@ public void ignoresNullElementsForInsertAll() {
|
2742 | 2743 | assertThat(result, hasItems(newYork, washington));
|
2743 | 2744 | }
|
2744 | 2745 |
|
| 2746 | + /** |
| 2747 | + * @see DATAMONGO-1208 |
| 2748 | + */ |
| 2749 | + @Test |
| 2750 | + public void takesSortIntoAccountWhenStreaming() { |
| 2751 | + |
| 2752 | + Person youngestPerson = new Person("John", 20); |
| 2753 | + Person oldestPerson = new Person("Jane", 42); |
| 2754 | + |
| 2755 | + template.insertAll(Arrays.asList(oldestPerson, youngestPerson)); |
| 2756 | + |
| 2757 | + Query q = new Query(); |
| 2758 | + q.with(new Sort(Direction.ASC, "age")); |
| 2759 | + CloseableIterator<Person> stream = template.stream(q, Person.class); |
| 2760 | + |
| 2761 | + assertThat(stream.next().getAge(), is(youngestPerson.getAge())); |
| 2762 | + assertThat(stream.next().getAge(), is(oldestPerson.getAge())); |
| 2763 | + } |
| 2764 | + |
| 2765 | + /** |
| 2766 | + * @see DATAMONGO-1208 |
| 2767 | + */ |
| 2768 | + @Test |
| 2769 | + public void takesLimitIntoAccountWhenStreaming() { |
| 2770 | + |
| 2771 | + Person youngestPerson = new Person("John", 20); |
| 2772 | + Person oldestPerson = new Person("Jane", 42); |
| 2773 | + |
| 2774 | + template.insertAll(Arrays.asList(oldestPerson, youngestPerson)); |
| 2775 | + |
| 2776 | + Query q = new Query(); |
| 2777 | + q.with(new PageRequest(0, 1, new Sort(Direction.ASC, "age"))); |
| 2778 | + CloseableIterator<Person> stream = template.stream(q, Person.class); |
| 2779 | + |
| 2780 | + assertThat(stream.next().getAge(), is(youngestPerson.getAge())); |
| 2781 | + assertThat(stream.hasNext(), is(false)); |
| 2782 | + } |
| 2783 | + |
2745 | 2784 | static class DoucmentWithNamedIdField {
|
2746 | 2785 |
|
2747 | 2786 | @Id String someIdKey;
|
|
0 commit comments