Search in sources :

Example 6 with PagerParams

use of org.summerb.approaches.jdbccrud.api.dto.PagerParams 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());
}
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)

Example 7 with PagerParams

use of org.summerb.approaches.jdbccrud.api.dto.PagerParams 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.microservices.users.api.dto.User) PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) PaginatedList(org.summerb.approaches.jdbccrud.api.dto.PaginatedList) Test(org.junit.Test)

Example 8 with PagerParams

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

the class UserServiceImplTest method testFindUsersByDisplayNamePartial_whitebox_expectUserServiceUnexpectedException.

@Test(expected = UserServiceUnexpectedException.class)
public void testFindUsersByDisplayNamePartial_whitebox_expectUserServiceUnexpectedException() throws Exception {
    UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
    fixture.findUsersByDisplayNamePartial(UserFactory.EXISTENT_USER, new PagerParams(20, 40));
    fail();
}
Also used : PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) Test(org.junit.Test)

Example 9 with PagerParams

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

the class GenericCrudServiceTestTemplate method testQuery_expectOrderingWorksCorrectly.

@Test
public void testQuery_expectOrderingWorksCorrectly() throws Exception {
    createTestData();
    PaginatedList<TestDto1> result = getTestDto1Service().query(new PagerParams(0, 100), Query.n().contains("env", "env-"), OrderBy.Asc("minorVersion"));
    assertEquals("env-prd", result.getItems().get(2).getEnv());
    assertEquals("env-pilot", result.getItems().get(1).getEnv());
    assertEquals("env-uat", result.getItems().get(0).getEnv());
    result = getTestDto1Service().query(new PagerParams(0, 100), Query.n().contains("env", "env-"), OrderBy.Desc("minorVersion"));
    assertEquals("env-prd", result.getItems().get(0).getEnv());
    assertEquals("env-pilot", result.getItems().get(1).getEnv());
    assertEquals("env-uat", result.getItems().get(2).getEnv());
}
Also used : PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) Test(org.junit.Test)

Example 10 with PagerParams

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

the class GenericCrudServiceTestTemplate method testFindByQueryNumberOneOf.

@Test
public void testFindByQueryNumberOneOf() throws Exception {
    createTestData();
    PaginatedList<TestDto1> result = getTestDto1Service().query(new PagerParams(0, 100), Query.n().in("minorVersion", 4L, 5L));
    assertEquals(2, result.getTotalResults());
}
Also used : PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) 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