DATACOUCH-211 - Applying sort that's passed in via the Pagenate object in call to N1qlCouchbaseRepository::findAll

This commit is contained in:
James Thomson
2016-03-10 21:31:23 +00:00
parent 0149144bc0
commit 8357122950
2 changed files with 34 additions and 1 deletions

View File

@@ -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();
}
}
}