Search in sources :

Example 11 with Direction

use of org.springframework.data.domain.Sort.Direction in project irida by phac-nml.

the class CRUDServiceImplTest method testSearchSortSetProperty.

@Test
@SuppressWarnings("unchecked")
public void testSearchSortSetProperty() {
    int page = 1;
    int size = 1;
    String property = "nonNull";
    Direction order = Direction.ASC;
    Page<IdentifiableTestEntity> idPage = new PageImpl<>(Lists.newArrayList(new IdentifiableTestEntity(), new IdentifiableTestEntity()));
    when(crudRepository.findAll(any(Specification.class), any(Pageable.class))).thenReturn(idPage);
    Page<IdentifiableTestEntity> search = crudService.search(IdentifiableTestEntitySpecification.search(), page, size, order, property);
    assertEquals(2, search.getTotalElements());
    ArgumentCaptor<Pageable> pageArgument = ArgumentCaptor.forClass(Pageable.class);
    verify(crudRepository).findAll(any(Specification.class), pageArgument.capture());
    // ensure a created date sort property is set
    Pageable pagable = pageArgument.getValue();
    Order sort = pagable.getSort().iterator().next();
    assertEquals(property, sort.getProperty());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Order(org.springframework.data.domain.Sort.Order) IdentifiableTestEntity(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity) Pageable(org.springframework.data.domain.Pageable) IdentifiableTestEntitySpecification(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntitySpecification) Specification(org.springframework.data.jpa.domain.Specification) Direction(org.springframework.data.domain.Sort.Direction) Test(org.junit.Test)

Example 12 with Direction

use of org.springframework.data.domain.Sort.Direction in project irida by phac-nml.

the class CRUDServiceImplTest method testSearchSortEmptyArray.

@Test
@SuppressWarnings("unchecked")
public void testSearchSortEmptyArray() {
    int page = 1;
    int size = 1;
    Direction order = Direction.ASC;
    Page<IdentifiableTestEntity> idPage = new PageImpl<>(Lists.newArrayList(new IdentifiableTestEntity(), new IdentifiableTestEntity()));
    when(crudRepository.findAll(any(Specification.class), any(Pageable.class))).thenReturn(idPage);
    Page<IdentifiableTestEntity> search = crudService.search(IdentifiableTestEntitySpecification.search(), page, size, order, new String[0]);
    assertEquals(2, search.getTotalElements());
    ArgumentCaptor<Pageable> pageArgument = ArgumentCaptor.forClass(Pageable.class);
    verify(crudRepository).findAll(any(Specification.class), pageArgument.capture());
    // ensure a created date sort property is set
    Pageable pagable = pageArgument.getValue();
    Order sort = pagable.getSort().iterator().next();
    assertEquals("createdDate", sort.getProperty());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Order(org.springframework.data.domain.Sort.Order) IdentifiableTestEntity(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity) Pageable(org.springframework.data.domain.Pageable) IdentifiableTestEntitySpecification(ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntitySpecification) Specification(org.springframework.data.jpa.domain.Specification) Direction(org.springframework.data.domain.Sort.Direction) Test(org.junit.Test)

Example 13 with Direction

use of org.springframework.data.domain.Sort.Direction in project irida by phac-nml.

the class UserServiceImplTest method testSearchUser.

@SuppressWarnings("unchecked")
@Test
public void testSearchUser() {
    int page = 1;
    int size = 10;
    Direction order = Direction.ASC;
    String sortProperties = "id";
    String searchString = "tom";
    Page<User> userPage = new PageImpl<>(Lists.newArrayList(new User(1L, "tom", "tom@nowhere.com", "123456798", "Tom", "Matthews", "1234"), new User(2L, "tomorrow", "tomorrow@somewhere.com", "ABCDEFGHIJ", "Tommorrow", "Sillyname", "5678")));
    when(userRepository.findAll(any(Specification.class), any(PageRequest.class))).thenReturn(userPage);
    Page<User> searchUser = userService.search(UserSpecification.searchUser(searchString), page, size, order, sortProperties);
    assertEquals(userPage, searchUser);
    verify(userRepository).findAll(any(Specification.class), any(PageRequest.class));
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) User(ca.corefacility.bioinformatics.irida.model.user.User) UserSpecification(ca.corefacility.bioinformatics.irida.repositories.specification.UserSpecification) Specification(org.springframework.data.jpa.domain.Specification) Direction(org.springframework.data.domain.Sort.Direction) Test(org.junit.Test)

Aggregations

Direction (org.springframework.data.domain.Sort.Direction)13 Test (org.junit.Test)8 PageImpl (org.springframework.data.domain.PageImpl)8 Order (org.springframework.data.domain.Sort.Order)8 Specification (org.springframework.data.jpa.domain.Specification)6 IdentifiableTestEntity (ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntity)4 IdentifiableTestEntitySpecification (ca.corefacility.bioinformatics.irida.utils.model.IdentifiableTestEntitySpecification)4 Pageable (org.springframework.data.domain.Pageable)4 User (ca.corefacility.bioinformatics.irida.model.user.User)3 Project (ca.corefacility.bioinformatics.irida.model.project.Project)2 ArrayList (java.util.ArrayList)2 RemoteAPI (ca.corefacility.bioinformatics.irida.model.RemoteAPI)1 UserSpecification (ca.corefacility.bioinformatics.irida.repositories.specification.UserSpecification)1 MongoException (com.mongodb.MongoException)1 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)1 DistributionWithAuditInfo (com.synopsys.integration.alert.common.rest.model.DistributionWithAuditInfo)1 Principal (java.security.Principal)1 List (java.util.List)1 PageRequest (org.springframework.data.domain.PageRequest)1 Sort (org.springframework.data.domain.Sort)1