DATACOUCH-211 - Applying sort that's passed in via the Pagenate object in call to N1qlCouchbaseRepository::findAll
This commit is contained in:
@@ -36,6 +36,8 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This tests PaginAndSortingRepository features in the Couchbase connector.
|
||||
*
|
||||
@@ -105,4 +107,22 @@ public class N1qlCouchbaseRepositoryTests {
|
||||
assertEquals(15, page1.getTotalElements()); //12 generated parties + 3 specifically crafted party
|
||||
assertEquals(8, page1.getNumberOfElements());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPageThroughSortedEntities() {
|
||||
Pageable pageable = new PageRequest(0, 8, Sort.Direction.DESC, "attendees");
|
||||
|
||||
Page<Party> page1 = repository.findAll(pageable);
|
||||
assertEquals(15, page1.getTotalElements()); //12 generated parties + 3 specifically crafted party
|
||||
assertEquals(8, page1.getNumberOfElements());
|
||||
|
||||
List<Party> parties = page1.getContent();
|
||||
Long previousAttendees = null;
|
||||
for (Party party : parties) {
|
||||
if (previousAttendees != null) {
|
||||
assertTrue(party.getAttendees() <= previousAttendees);
|
||||
}
|
||||
previousAttendees = party.getAttendees();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user