Search in sources :

Example 1 with PagerParams

use of org.summerb.approaches.jdbccrud.api.dto.PagerParams in project summerb by skarpushin.

the class AttachmentServiceImplTest method testAttachment_expectMultipleResults.

@Test
public void testAttachment_expectMultipleResults() throws Exception {
    Attachment a = new Attachment();
    a.setArticleId(createTestArticle());
    a.setName("test attachment");
    a.setSize(123);
    a.setContents(createValidContentsReader());
    attachmentService.create(a);
    a.setContents(createValidContentsReader());
    a.setName("test attachment 2");
    attachmentService.create(a);
    PaginatedList<Attachment> result = attachmentService.query(new PagerParams(0, 100), Query.n().eq(Attachment.FN_ARTICLE_ID, a.getArticleId()));
    assertEquals(2, result.getItems().size());
}
Also used : PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) Attachment(org.summerb.microservices.articles.api.dto.Attachment) Test(org.junit.Test)

Example 2 with PagerParams

use of org.summerb.approaches.jdbccrud.api.dto.PagerParams in project summerb by skarpushin.

the class UserDaoImplTest method testFindUsersByDisplayNamePartial_expectUsersWillBeFound.

@Test
public void testFindUsersByDisplayNamePartial_expectUsersWillBeFound() throws Exception {
    User user = UserFactory.createNewUserTemplate();
    user.setDisplayName("oneUHapqoiwez");
    user.setEmail("email1@aaa.ru");
    userService.createUser(user);
    user = UserFactory.createNewUserTemplate();
    user.setDisplayName("twoUHapqoiwez");
    user.setEmail("email2@aaa.ru");
    userService.createUser(user);
    user = UserFactory.createNewUserTemplate();
    user.setDisplayName("threeUHapqoiwez");
    user.setEmail("email3@aaa.ru");
    userService.createUser(user);
    user = UserFactory.createNewUserTemplate();
    user.setDisplayName("other");
    user.setEmail("other@aaa.ru");
    userService.createUser(user);
    PaginatedList<User> results = userService.findUsersByDisplayNamePartial("UHapqoiwez", new PagerParams());
    assertNotNull(results);
    assertNotNull(results.getItems());
    assertTrue(results.getItems().size() == 3);
    assertTrue(results.getTotalResults() == 3);
    results = userService.findUsersByDisplayNamePartial("eUHapqoiwez", new PagerParams());
    assertTrue(results.getItems().size() == 2);
    assertTrue(results.getTotalResults() == 2);
    results = userService.findUsersByDisplayNamePartial("UHapqoiwez", new PagerParams(0, 1));
    assertTrue(results.getItems().size() == 1);
    assertTrue(results.getTotalResults() == 3);
}
Also used : User(org.summerb.microservices.users.api.dto.User) PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) Test(org.junit.Test)

Example 3 with PagerParams

use of org.summerb.approaches.jdbccrud.api.dto.PagerParams 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;
}
Also used : PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) ArrayList(java.util.ArrayList) StringIdAliasDao(org.summerb.microservices.properties.impl.dao.StringIdAliasDao) AliasEntry(org.summerb.microservices.properties.impl.dao.AliasEntry) Entry(java.util.Map.Entry) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PaginatedList(org.summerb.approaches.jdbccrud.api.dto.PaginatedList) AliasEntry(org.summerb.microservices.properties.impl.dao.AliasEntry)

Example 4 with PagerParams

use of org.summerb.approaches.jdbccrud.api.dto.PagerParams 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.microservices.users.impl.dao.AuthTokenDao) PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) AuthToken(org.summerb.microservices.users.api.dto.AuthToken) PaginatedList(org.summerb.approaches.jdbccrud.api.dto.PaginatedList) LinkedList(java.util.LinkedList)

Example 5 with PagerParams

use of org.summerb.approaches.jdbccrud.api.dto.PagerParams 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());
}
Also used : HasId(org.summerb.approaches.jdbccrud.api.dto.HasId) DataSetLoaderImpl(org.summerb.approaches.jdbccrud.impl.relations.DataSetLoaderImpl) EasyCrudService(org.summerb.approaches.jdbccrud.api.EasyCrudService) Query(org.summerb.approaches.jdbccrud.api.query.Query) PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) PaginatedList(org.summerb.approaches.jdbccrud.api.dto.PaginatedList) TestDto1(integr.org.summerb.jdbccrud.TestDto1) Test(org.junit.Test)

Aggregations

PagerParams (org.summerb.approaches.jdbccrud.api.dto.PagerParams)31 Test (org.junit.Test)27 PaginatedList (org.summerb.approaches.jdbccrud.api.dto.PaginatedList)6 EasyCrudService (org.summerb.approaches.jdbccrud.api.EasyCrudService)3 Query (org.summerb.approaches.jdbccrud.api.query.Query)3 DataSetLoaderImpl (org.summerb.approaches.jdbccrud.impl.relations.DataSetLoaderImpl)3 User (org.summerb.microservices.users.api.dto.User)3 TestDto1 (integr.org.summerb.jdbccrud.TestDto1)2 HasId (org.summerb.approaches.jdbccrud.api.dto.HasId)2 AliasEntry (org.summerb.microservices.properties.impl.dao.AliasEntry)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Entry (java.util.Map.Entry)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 Attachment (org.summerb.microservices.articles.api.dto.Attachment)1 PropertyServiceUnexpectedException (org.summerb.microservices.properties.api.exceptions.PropertyServiceUnexpectedException)1 StringIdAliasDao (org.summerb.microservices.properties.impl.dao.StringIdAliasDao)1 AuthToken (org.summerb.microservices.users.api.dto.AuthToken)1