Search in sources :

Example 16 with ValidationConflictException

use of org.entando.entando.web.common.exceptions.ValidationConflictException in project entando-core by entando.

the class GroupControllerUnitTest method testValidateOnDeleteReservedGroups.

@Test
public void testValidateOnDeleteReservedGroups() throws ApsSystemException, Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String groupName = Group.FREE_GROUP_NAME;
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult("group", "group");
    bindingResult.reject(GroupValidator.ERRCODE_CANNOT_DELETE_RESERVED_GROUP, new String[] { groupName }, "group.cannot.delete.reserved");
    doThrow(new ValidationConflictException(bindingResult)).when(groupService).removeGroup(groupName);
    this.controller.setGroupValidator(new GroupValidator());
    ResultActions result = mockMvc.perform(delete("/groups/{groupName}", groupName).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isConflict());
    result.andExpect(jsonPath("$.errors[0].code", is(GroupValidator.ERRCODE_CANNOT_DELETE_RESERVED_GROUP)));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) GroupValidator(org.entando.entando.web.group.validator.GroupValidator) ResultActions(org.springframework.test.web.servlet.ResultActions) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Aggregations

ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)16 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)11 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)10 RestServerError (org.entando.entando.aps.system.exception.RestServerError)10 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)5 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)5 RestResponse (org.entando.entando.web.common.model.RestResponse)5 ResponseEntity (org.springframework.http.ResponseEntity)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Role (com.agiletec.aps.system.services.role.Role)3 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)3 RoleDto (org.entando.entando.aps.system.services.role.model.RoleDto)3 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)2 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)1 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)1 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)1 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)1 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)1 IAuthorizationService (com.agiletec.aps.system.services.authorization.IAuthorizationService)1 Group (com.agiletec.aps.system.services.group.Group)1