use of org.broadinstitute.consent.http.models.PaginationToken in project consent by DataBiosphere.
the class DarCollectionServiceTest method testQueryCollectionsByFiltersAndUserRolesForResearcher.
@Test
public void testQueryCollectionsByFiltersAndUserRolesForResearcher() {
User user = new User();
user.setDacUserId(1);
String dacRoleName = UserRoles.RESEARCHER.getRoleName();
Integer dacRoleId = UserRoles.RESEARCHER.getRoleId();
UserRole memberRole = new UserRole(dacRoleId, dacRoleName);
user.addRole(memberRole);
int pageSize = 10;
int mockCollectionSize = 3;
List<DarCollection> mockCollection = createMockCollections(mockCollectionSize);
PaginationToken token = initPaginationToken("darCode", "DESC", "", pageSize);
when(darCollectionDAO.returnUnfilteredResearcherCollectionCount(anyInt())).thenReturn(mockCollectionSize);
when(darCollectionDAO.getFilteredListForResearcher(anyString(), anyString(), anyInt(), anyString())).thenReturn(mockCollection);
initService();
PaginationResponse<DarCollection> response = service.queryCollectionsByFiltersAndUserRoles(user, token, dacRoleName);
assertNotNull(response);
assertEquals(mockCollectionSize, (int) response.getUnfilteredCount());
assertEquals(3, (int) response.getFilteredCount());
assertEquals(1, (int) response.getFilteredPageCount());
}
use of org.broadinstitute.consent.http.models.PaginationToken in project consent by DataBiosphere.
the class DarCollectionServiceTest method testInitWithInvalidTokenValues.
@Test
public void testInitWithInvalidTokenValues() {
int filteredCount = 5;
int unfilteredCount = 20;
PaginationToken token = new PaginationToken(2, 10, "darCode", "DESC", null, DarCollection.acceptableSortFields, DarCollection.defaultTokenSortField);
initWithPaginationToken(token, unfilteredCount, filteredCount);
// Start index will be > end index in this case since we're trying to get results 11-20 when
// there are only 5 items in the results array, so there should be 0 results returned
PaginationResponse<DarCollection> response = service.queryCollectionsByFiltersAndUserRoles(user, token, UserRoles.ADMIN.getRoleName());
assertTrue(response.getResults().isEmpty());
}
use of org.broadinstitute.consent.http.models.PaginationToken in project consent by DataBiosphere.
the class DarCollectionServiceTest method testGetCollectionsWithFiltersByPage.
@Test
public void testGetCollectionsWithFiltersByPage() {
User user = createMockAdminUser();
IntStream.rangeClosed(1, 8).forEach(page -> {
int filteredCount = 75;
int unfilteredCount = 100;
PaginationToken token = new PaginationToken(page, 10, "darCode", "DESC", null, DarCollection.acceptableSortFields, DarCollection.defaultTokenSortField);
List<DarCollection> unfilteredList = createMockCollections(unfilteredCount);
List<DarCollection> filteredList = unfilteredList.subList(0, filteredCount);
initService();
when(darCollectionDAO.returnUnfilteredCollectionCount()).thenReturn(unfilteredCount);
when(darCollectionDAO.getFilteredCollectionsForAdmin(anyString(), anyString(), anyString())).thenReturn(filteredList);
PaginationResponse<DarCollection> response = service.queryCollectionsByFiltersAndUserRoles(user, token, UserRoles.ADMIN.getRoleName());
// Assert that the results sizes are correct
if (page == 8) {
int lastPageSize = token.getFilteredCount() % token.getPageSize();
assertEquals(lastPageSize, response.getResults().size());
} else {
assertEquals((int) token.getPageSize(), response.getResults().size());
}
// Assert that the returned results are what we expect them to be, based on ID
int expectedCollectionId = (page * token.getPageSize()) - token.getPageSize() + 1;
assertEquals(Integer.valueOf(expectedCollectionId), response.getResults().get(0).getDarCollectionId());
assertEquals(filteredCount, response.getFilteredCount().intValue());
});
}
use of org.broadinstitute.consent.http.models.PaginationToken in project consent by DataBiosphere.
the class DarCollectionServiceTest method testGetCollectionsWithFiltersByPageLessThanPageSize.
@Test
public void testGetCollectionsWithFiltersByPageLessThanPageSize() {
int filteredCount = 3;
int unfilteredCount = 5;
User user = createMockAdminUser();
PaginationToken token = new PaginationToken(1, 10, "darCode", "DESC", null, DarCollection.acceptableSortFields, DarCollection.defaultTokenSortField);
List<DarCollection> mockCollections = createMockCollections(3);
when(darCollectionDAO.returnUnfilteredCollectionCount()).thenReturn(unfilteredCount);
when(darCollectionDAO.getFilteredCollectionsForAdmin(anyString(), anyString(), anyString())).thenReturn(mockCollections);
initService();
PaginationResponse<DarCollection> response = service.queryCollectionsByFiltersAndUserRoles(user, token, UserRoles.ADMIN.getRoleName());
assertEquals(1, response.getFilteredPageCount().intValue());
assertEquals(filteredCount, response.getResults().size());
assertEquals(filteredCount, response.getFilteredCount().intValue());
}
use of org.broadinstitute.consent.http.models.PaginationToken in project consent by DataBiosphere.
the class DarCollectionServiceTest method testGetCollectionsWithFilters_EmptyUnfiltered.
@Test
public void testGetCollectionsWithFilters_EmptyUnfiltered() {
User user = createMockAdminUser();
PaginationToken token = new PaginationToken(1, 10, "darCode", "DESC", null, DarCollection.acceptableSortFields, DarCollection.defaultTokenSortField);
when(darCollectionDAO.returnUnfilteredCollectionCount()).thenReturn(0);
initService();
PaginationResponse<DarCollection> response = service.queryCollectionsByFiltersAndUserRoles(user, token, UserRoles.ADMIN.getRoleName());
assertEquals(1, response.getFilteredPageCount().intValue());
assertEquals(0, response.getUnfilteredCount().intValue());
assertEquals(0, response.getFilteredCount().intValue());
}
Aggregations