use of org.summerb.approaches.jdbccrud.api.dto.PaginatedList in project summerb by skarpushin.
the class StringIdAliasServiceEagerImplFactory method createDaoMock.
private static StringIdAliasDao createDaoMock() {
StringIdAliasDao ret = Mockito.mock(StringIdAliasDao.class);
when(ret.createAliasFor(NAME)).thenReturn(NAME_ALIAS);
when(ret.findAliasFor(NAME)).thenReturn(NAME_ALIAS);
when(ret.loadAllAliases(any(PagerParams.class))).thenAnswer(new Answer<PaginatedList<Entry<String, Long>>>() {
@Override
public PaginatedList<Entry<String, Long>> answer(InvocationOnMock invocation) throws Throwable {
PagerParams pagerParams = (PagerParams) invocation.getArguments()[0];
// Synthetic pause, simulate
Thread.sleep(250);
PaginatedList<Entry<String, Long>> result = new PaginatedList<Entry<String, Long>>();
result.setPagerParams(pagerParams);
result.setTotalResults(150);
ArrayList<Entry<String, Long>> items = new ArrayList<Entry<String, Long>>();
result.setItems(items);
long offset = pagerParams.getOffset();
long max = -1;
if (offset == 0) {
max = 100;
} else if (offset == 100) {
max = 50;
} else {
fail();
}
for (long i = offset; i < max; i++) {
items.add(new AliasEntry("str" + i, i));
}
return result;
}
});
return ret;
}
use of org.summerb.approaches.jdbccrud.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;
}
use of org.summerb.approaches.jdbccrud.api.dto.PaginatedList in project summerb by skarpushin.
the class DataSetLoaderImplTest method testLoadObjectsByIds_ExpectManyLoadByStrings.
@Test
public void testLoadObjectsByIds_ExpectManyLoadByStrings() throws Exception {
DataSetLoaderImpl fixture = buildMockedInstance();
EasyCrudService service = Mockito.mock(EasyCrudService.class);
when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto1")).thenReturn(service);
Matcher<Query> matcher = IsEqual.equalTo(Query.n().in(HasId.FN_ID, new String[] { "s1", "s2" }));
PaginatedList mockret = new PaginatedList<>(new PagerParams(), Arrays.asList(new TestDto1(), new TestDto1()), 2);
when(service.query(any(PagerParams.class), argThat(matcher))).thenReturn(mockret);
List<HasId> ret = fixture.loadObjectsByIds(ids("s1", "s2"), "dto1");
assertNotNull(ret);
assertEquals(2, ret.size());
}
use of org.summerb.approaches.jdbccrud.api.dto.PaginatedList in project summerb by skarpushin.
the class DataSetLoaderImplTest method testLoadObjectsByIds_ExpectManyLoadByLongsOk.
@Test
public void testLoadObjectsByIds_ExpectManyLoadByLongsOk() throws Exception {
DataSetLoaderImpl fixture = buildMockedInstance();
EasyCrudService service = Mockito.mock(EasyCrudService.class);
when(fixture.getEasyCrudServiceResolver().resolveByEntityType("dto1")).thenReturn(service);
Matcher<Query> matcher = IsEqual.equalTo(Query.n().in(HasId.FN_ID, new Long[] { 1L, 2L }));
PaginatedList mockret = new PaginatedList<>(new PagerParams(), Arrays.asList(new TestDto1(), new TestDto1()), 2);
when(service.query(any(PagerParams.class), argThat(matcher))).thenReturn(mockret);
List<HasId> ret = fixture.loadObjectsByIds(ids(1L, 2L), "dto1");
assertNotNull(ret);
assertEquals(2, ret.size());
}
use of org.summerb.approaches.jdbccrud.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());
}
Aggregations