Search in sources :

Example 6 with GroupDto

use of org.entando.entando.aps.system.services.group.model.GroupDto 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 7 with GroupDto

use of org.entando.entando.aps.system.services.group.model.GroupDto 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 8 with GroupDto

use of org.entando.entando.aps.system.services.group.model.GroupDto 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)

Example 9 with GroupDto

use of org.entando.entando.aps.system.services.group.model.GroupDto in project entando-core by entando.

the class GroupController method addGroup.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> addGroup(@Valid @RequestBody GroupRequest groupRequest, BindingResult bindingResult) throws ApsSystemException {
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    // business validations
    getGroupValidator().validate(groupRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationConflictException(bindingResult);
    }
    GroupDto dto = this.getGroupService().addGroup(groupRequest);
    return new ResponseEntity<>(new RestResponse(dto), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with GroupDto

use of org.entando.entando.aps.system.services.group.model.GroupDto in project entando-core by entando.

the class GroupServiceIntegrationTest method testGetGroups_filter.

@Test
public void testGetGroups_filter() throws JsonProcessingException {
    RestListRequest restListRequest = new RestListRequest();
    restListRequest.addFilter(new Filter("groupname", "fr"));
    PagedMetadata<GroupDto> res = this.groupService.getGroups(restListRequest);
    assertThat(res.getPage(), is(1));
    assertThat(res.getPageSize(), is(100));
    assertThat(res.getLastPage(), is(1));
    assertThat(res.getTotalItems(), is(1));
}
Also used : 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) Test(org.junit.Test)

Aggregations

GroupDto (org.entando.entando.aps.system.services.group.model.GroupDto)12 Test (org.junit.Test)7 RestListRequest (org.entando.entando.web.common.model.RestListRequest)6 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 ResultActions (org.springframework.test.web.servlet.ResultActions)4 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)3 Filter (org.entando.entando.web.common.model.Filter)3 RestResponse (org.entando.entando.web.common.model.RestResponse)3 GroupRequest (org.entando.entando.web.group.model.GroupRequest)3 ResponseEntity (org.springframework.http.ResponseEntity)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Group (com.agiletec.aps.system.services.group.Group)2 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)2 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)2 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)2 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)2 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)2 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)1 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)1 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1