Search in sources :

Example 6 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_2.

@SuppressWarnings("unchecked")
@Test
public void should_load_the_list_of_dataModels_2() 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").param("filter[0].attribute", "code").param("filter[0].value", "1").header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
    RestListRequest restListReq = new RestListRequest();
    restListReq.setPage(1);
    restListReq.setPageSize(4);
    restListReq.addFilter(new Filter("code", "1"));
    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) Filter(org.entando.entando.web.common.model.Filter) 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)

Example 7 with RestListRequest

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

the class GroupControllerUnitTest method testSeachGroups.

@Test
public void testSeachGroups() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    when(groupService.getGroups(any(RestListRequest.class))).thenReturn(new PagedMetadata<GroupDto>());
    ResultActions result = mockMvc.perform(get("/groups").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(groupService, Mockito.times(1)).getGroups(restListReq);
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) RestListRequest(org.entando.entando.web.common.model.RestListRequest) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 8 with RestListRequest

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

the class GroupControllerUnitTest method testSearchGroupsWithFilters.

@Test
public void testSearchGroupsWithFilters() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    when(groupService.getGroups(any(RestListRequest.class))).thenReturn(new PagedMetadata<GroupDto>());
    ResultActions result = mockMvc.perform(get("/groups").param("page", "1").param("pageSize", "4").param("filter[0].attribute", "code").param("filter[0].value", "free").header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
    RestListRequest restListReq = new RestListRequest();
    restListReq.setPage(1);
    restListReq.setPageSize(4);
    restListReq.addFilter(new Filter("code", "free"));
    Mockito.verify(groupService, Mockito.times(1)).getGroups(restListReq);
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 9 with RestListRequest

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

the class EntityManagerServiceIntegrationTest method testGetEntityTypes_1.

@Test
public void testGetEntityTypes_1() {
    RestListRequest restListRequest = new RestListRequest();
    PagedMetadata<EntityTypeShortDto> dtos = this.entityManagerService.getShortEntityTypes(SystemConstants.USER_PROFILE_MANAGER, restListRequest);
    assertNotNull(dtos);
    assertEquals(1, dtos.getBody().size());
}
Also used : EntityTypeShortDto(org.entando.entando.aps.system.services.entity.model.EntityTypeShortDto) RestListRequest(org.entando.entando.web.common.model.RestListRequest) Test(org.junit.Test)

Example 10 with RestListRequest

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

the class GroupServiceIntegrationTest method testGetGroups.

@Test
public void testGetGroups() throws JsonProcessingException {
    RestListRequest restListRequest = new RestListRequest();
    restListRequest.setPageSize(5);
    PagedMetadata<GroupDto> res = this.groupService.getGroups(restListRequest);
    assertThat(res.getPage(), is(1));
    assertThat(res.getPageSize(), is(5));
    assertThat(res.getLastPage(), is(2));
    assertThat(res.getTotalItems(), is(6));
    // 
    restListRequest.setPageSize(2);
    res = this.groupService.getGroups(restListRequest);
    assertThat(res.getPage(), is(1));
    assertThat(res.getPageSize(), is(2));
    assertThat(res.getLastPage(), is(3));
    assertThat(res.getTotalItems(), is(6));
    // 
    restListRequest.setPageSize(4);
    res = this.groupService.getGroups(restListRequest);
    assertThat(res.getPage(), is(1));
    assertThat(res.getPageSize(), is(4));
    assertThat(res.getLastPage(), is(2));
    assertThat(res.getTotalItems(), is(6));
    // 
    restListRequest.setPageSize(4);
    restListRequest.setPage(1);
    res = this.groupService.getGroups(restListRequest);
    assertThat(res.getPage(), is(1));
    assertThat(res.getPageSize(), is(4));
    assertThat(res.getLastPage(), is(2));
    assertThat(res.getTotalItems(), is(6));
    // 
    restListRequest.setPageSize(4);
    restListRequest.setPage(1000);
    res = this.groupService.getGroups(restListRequest);
    assertThat(res.getPage(), is(1000));
    assertThat(res.getPageSize(), is(4));
    assertThat(res.getLastPage(), is(2));
    assertThat(res.getTotalItems(), is(6));
}
Also used : RestListRequest(org.entando.entando.web.common.model.RestListRequest) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) 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