Search in sources :

Example 6 with PaginatedList

use of org.summerb.easycrud.api.dto.PaginatedList in project summerb by skarpushin.

the class UserServiceImplTest method testFindUsersByDisplayNamePartial_blackbox_shouldReturnExpectedResults.

@Test
public void testFindUsersByDisplayNamePartial_blackbox_shouldReturnExpectedResults() throws Exception {
    UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
    PagerParams pagerParams = new PagerParams(20, 40);
    PaginatedList<User> resultFromDao = new PaginatedList<User>();
    resultFromDao.setTotalResults(1);
    resultFromDao.setPagerParams(pagerParams);
    resultFromDao.setItems(new LinkedList<User>());
    resultFromDao.getItems().add(UserFactory.createNewUserTemplate());
    when(fixture.getUserDao().findUserByDisplayNamePartial("asd", pagerParams)).thenReturn(resultFromDao);
    PaginatedList<User> results = fixture.findUsersByDisplayNamePartial("asd", pagerParams);
    assertNotNull(results);
    assertNotNull(results.getPagerParams());
    assertEquals(pagerParams.getOffset(), results.getPagerParams().getOffset());
    assertEquals(pagerParams.getMax(), results.getPagerParams().getMax());
    assertEquals(1, results.getTotalResults());
}
Also used : User(org.summerb.users.api.dto.User) PagerParams(org.summerb.easycrud.api.dto.PagerParams) PaginatedList(org.summerb.easycrud.api.dto.PaginatedList) Test(org.junit.Test)

Example 7 with PaginatedList

use of org.summerb.easycrud.api.dto.PaginatedList in project summerb by skarpushin.

the class AuthTokenServiceDbImplFactory method createAuthTokenServiceDbImpl.

public static AuthTokenServiceImpl createAuthTokenServiceDbImpl() {
    AuthTokenServiceImpl ret = new AuthTokenServiceImpl();
    ret.setPasswordService(PasswordServiceDbImplFactory.createPasswordServiceDbImpl());
    ret.setUserService(UserServiceImplFactory.createUsersServiceImpl());
    AuthTokenDao authTokenDao = Mockito.mock(AuthTokenDao.class);
    ret.setAuthTokenDao(authTokenDao);
    when(authTokenDao.findAuthTokenByUuid(AuthTokenFactory.AUTH_TOKEN_EXCEPTION)).thenThrow(new IllegalStateException("test simulate exception"));
    when(authTokenDao.findAuthTokenByUuid(AuthTokenFactory.AUTH_TOKEN_EXISTENT)).thenReturn(AuthTokenFactory.createAuthTokenForExistentUser());
    when(authTokenDao.findAuthTokenByUuid(AuthTokenFactory.AUTH_TOKEN_NOT_EXISTENT)).thenReturn(null);
    when(authTokenDao.findAuthTokenByUuid(AuthTokenFactory.AUTH_TOKEN_EXPIRED)).thenReturn(AuthTokenFactory.createExpiredAuthToken());
    List<AuthToken> expiredTokens = new LinkedList<AuthToken>();
    expiredTokens.add(AuthTokenFactory.createExpiredAuthToken());
    PaginatedList<AuthToken> expiredAuthTokens = new PaginatedList<AuthToken>(new PagerParams(), expiredTokens, 1);
    return ret;
}
Also used : AuthTokenDao(org.summerb.users.impl.dao.AuthTokenDao) PagerParams(org.summerb.easycrud.api.dto.PagerParams) AuthToken(org.summerb.users.api.dto.AuthToken) PaginatedList(org.summerb.easycrud.api.dto.PaginatedList) LinkedList(java.util.LinkedList)

Aggregations

PaginatedList (org.summerb.easycrud.api.dto.PaginatedList)7 PagerParams (org.summerb.easycrud.api.dto.PagerParams)6 Test (org.junit.Test)4 EasyCrudService (org.summerb.easycrud.api.EasyCrudService)3 Query (org.summerb.easycrud.api.query.Query)3 TestDto1 (integr.org.summerb.easycrud.TestDto1)2 HasId (org.summerb.easycrud.api.dto.HasId)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 AliasEntry (org.summerb.properties.impl.dao.AliasEntry)1 StringIdAliasDao (org.summerb.properties.impl.dao.StringIdAliasDao)1 AuthToken (org.summerb.users.api.dto.AuthToken)1 User (org.summerb.users.api.dto.User)1 AuthTokenDao (org.summerb.users.impl.dao.AuthTokenDao)1