Search in sources :

Example 16 with RestListRequest

use of org.entando.entando.web.common.model.RestListRequest in project entando-core by entando.

the class RestListRequestTest method should_exclude_pagination_when_pagesize_0.

@Test
public void should_exclude_pagination_when_pagesize_0() {
    RestListRequest request = new RestListRequest();
    request.setPage(1);
    request.setPageSize(0);
    request.setSort("name");
    request.setDirection(FieldSearchFilter.Order.ASC.name());
    request.addFilter(new Filter("name", "jack"));
    request.addFilter(new Filter("city", "rome"));
    request.addFilter(new Filter("mobile", "+39"));
    // filters
    List<FieldSearchFilter> filters = request.buildFieldSearchFilters();
    assertThat(filters.size(), is(4));
    assertThat(filters.get(0).getKey(), is("name"));
    assertThat(filters.get(1).getKey(), is("city"));
    assertThat(filters.get(2).getKey(), is("mobile"));
    // sort
    assertThat(filters.get(3).getKey(), is("name"));
    assertThat(filters.get(3).getOrder(), is(FieldSearchFilter.Order.ASC));
}
Also used : FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Test(org.junit.Test)

Example 17 with RestListRequest

use of org.entando.entando.web.common.model.RestListRequest in project entando-core by entando.

the class RestListRequestTest method shuold_create_filters.

@Test
public void shuold_create_filters() {
    RestListRequest request = new RestListRequest();
    request.setPage(1);
    request.setPageSize(25);
    request.setSort("name");
    request.setDirection(FieldSearchFilter.Order.ASC.name());
    request.addFilter(new Filter("name", "jack"));
    request.addFilter(new Filter("city", "rome"));
    request.addFilter(new Filter("mobile", "+39"));
    // filters
    List<FieldSearchFilter> filters = request.buildFieldSearchFilters();
    assertThat(filters.size(), is(5));
    assertThat(filters.get(0).getKey(), is("name"));
    assertThat(filters.get(1).getKey(), is("city"));
    assertThat(filters.get(2).getKey(), is("mobile"));
    // pagination
    assertThat(filters.get(3).getKey(), is(nullValue()));
    assertThat(filters.get(3).getLimit(), is(not(nullValue())));
    assertThat(filters.get(3).getOffset(), is(not(nullValue())));
    // sort
    assertThat(filters.get(4).getKey(), is("name"));
    assertThat(filters.get(4).getOrder(), is(FieldSearchFilter.Order.ASC));
}
Also used : FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Test(org.junit.Test)

Example 18 with RestListRequest

use of org.entando.entando.web.common.model.RestListRequest in project entando-core by entando.

the class RestListRequestTest method should_default_direction.

@Test
public void should_default_direction() {
    RestListRequest request = new RestListRequest();
    request.setPage(1);
    request.setPageSize(0);
    request.setSort("name");
    request.setDirection("wrong");
    // filters
    List<FieldSearchFilter> filters = request.buildFieldSearchFilters();
    assertThat(filters.size(), is(1));
    assertThat(filters.get(0).getOrder(), is(FieldSearchFilter.Order.ASC));
}
Also used : RestListRequest(org.entando.entando.web.common.model.RestListRequest) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Test(org.junit.Test)

Example 19 with RestListRequest

use of org.entando.entando.web.common.model.RestListRequest in project entando-core by entando.

the class TestPageModelManager method testSearch_with_page_filter.

public void testSearch_with_page_filter() throws ApsSystemException {
    RestListRequest restListRequest = new RestListRequest();
    restListRequest.setPageSize(2);
    restListRequest.setPage(1);
    List<FieldSearchFilter> filters = restListRequest.buildFieldSearchFilters();
    SearcherDaoPaginatedResult<PageModel> result = this._pageModelManager.searchPageModels(filters);
    assertThat(result.getCount(), is(3));
    assertThat(result.getList().size(), is(2));
    restListRequest.addFilter(new Filter("descr", "modello"));
    result = this._pageModelManager.searchPageModels(restListRequest.buildFieldSearchFilters());
    assertThat(result.getCount(), is(2));
    assertThat(result.getList().size(), is(2));
    restListRequest.setPage(0);
    result = this._pageModelManager.searchPageModels(restListRequest.buildFieldSearchFilters());
    assertThat(result.getCount(), is(2));
    assertThat(result.getList().size(), is(2));
}
Also used : FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter)

Example 20 with RestListRequest

use of org.entando.entando.web.common.model.RestListRequest in project entando-core by entando.

the class DataObjectModelControllerTest method should_load_the_list_of_dataModels.

@SuppressWarnings("unchecked")
@Test
public void should_load_the_list_of_dataModels() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    when(dataObjectModelService.getDataObjectModels(any(RestListRequest.class))).thenReturn(new PagedMetadata<DataModelDto>());
    ResultActions result = mockMvc.perform(get("/dataModels").param("page", "1").param("pageSize", "4").header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
    RestListRequest restListReq = new RestListRequest();
    restListReq.setPage(1);
    restListReq.setPageSize(4);
    Mockito.verify(dataObjectModelService, Mockito.times(1)).getDataObjectModels(restListReq);
}
Also used : DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) UserDetails(com.agiletec.aps.system.services.user.UserDetails) RestListRequest(org.entando.entando.web.common.model.RestListRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Aggregations

RestListRequest (org.entando.entando.web.common.model.RestListRequest)26 Test (org.junit.Test)19 UserDetails (com.agiletec.aps.system.services.user.UserDetails)11 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)10 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)9 Filter (org.entando.entando.web.common.model.Filter)9 ResultActions (org.springframework.test.web.servlet.ResultActions)9 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)7 ArrayList (java.util.ArrayList)7 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)7 GroupDto (org.entando.entando.aps.system.services.group.model.GroupDto)6 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)5 List (java.util.List)5 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)5 RestServerError (org.entando.entando.aps.system.exception.RestServerError)5 IDtoBuilder (org.entando.entando.aps.system.services.IDtoBuilder)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)4 Map (java.util.Map)3