Search in sources :

Example 16 with PagerParams

use of org.summerb.easycrud.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.easycrud.api.dto.PagerParams) Attachment(org.summerb.minicms.api.dto.Attachment) Test(org.junit.Test)

Example 17 with PagerParams

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

the class StringIdAliasServiceEagerImpl method loadAllAliases.

protected final BiMap<String, Long> loadAllAliases() {
    try {
        BiMap<String, Long> ret = HashBiMap.create();
        long maxOffset = -2;
        for (long offset = 0; maxOffset == -2 || offset < maxOffset; offset = offset + EAGER_LOAD_BATCH_SIZE) {
            PagerParams pagerParams = new PagerParams(offset, EAGER_LOAD_BATCH_SIZE);
            PaginatedList<AliasEntry> loadedAliases = stringIdAliasDao.loadAllAliases(pagerParams);
            maxOffset = loadedAliases.getTotalResults() - 1;
            for (Entry<String, Long> entry : loadedAliases.getItems()) {
                ret.put(entry.getKey(), entry.getValue());
            }
        }
        return ret;
    } catch (Throwable t) {
        String msg = "Failed to eagerly load alias map";
        log.error(msg, t);
        throw new PropertyServiceUnexpectedException(msg, t);
    }
}
Also used : PagerParams(org.summerb.easycrud.api.dto.PagerParams) PropertyServiceUnexpectedException(org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException) AliasEntry(org.summerb.properties.impl.dao.AliasEntry)

Example 18 with PagerParams

use of org.summerb.easycrud.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.easycrud.api.dto.PagerParams) Test(org.junit.Test)

Example 19 with PagerParams

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

the class GenericCrudServiceTestTemplate method testFindByQueryNotContains.

@Test
public void testFindByQueryNotContains() throws Exception {
    createTestData();
    PaginatedList<TestDto1> result = getTestDto1Service().query(new PagerParams(0, 100), Query.n().notContains("env", "env-P"));
    assertEquals(1, result.getTotalResults());
}
Also used : PagerParams(org.summerb.easycrud.api.dto.PagerParams) Test(org.junit.Test)

Example 20 with PagerParams

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

the class GenericCrudServiceTestTemplate method testFindByQueryNumberNotIn.

@Test
public void testFindByQueryNumberNotIn() throws Exception {
    createTestData();
    PaginatedList<TestDto1> result = getTestDto1Service().query(new PagerParams(0, 100), Query.n().notIn("minorVersion", 4L, 5L));
    assertEquals(1, result.getTotalResults());
}
Also used : PagerParams(org.summerb.easycrud.api.dto.PagerParams) Test(org.junit.Test)

Aggregations

PagerParams (org.summerb.easycrud.api.dto.PagerParams)31 Test (org.junit.Test)27 PaginatedList (org.summerb.easycrud.api.dto.PaginatedList)6 EasyCrudService (org.summerb.easycrud.api.EasyCrudService)3 Query (org.summerb.easycrud.api.query.Query)3 User (org.summerb.users.api.dto.User)3 TestDto1 (integr.org.summerb.easycrud.TestDto1)2 HasId (org.summerb.easycrud.api.dto.HasId)2 AliasEntry (org.summerb.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.minicms.api.dto.Attachment)1 PropertyServiceUnexpectedException (org.summerb.properties.api.exceptions.PropertyServiceUnexpectedException)1 StringIdAliasDao (org.summerb.properties.impl.dao.StringIdAliasDao)1 AuthToken (org.summerb.users.api.dto.AuthToken)1 AuthTokenDao (org.summerb.users.impl.dao.AuthTokenDao)1