Search in sources :

Example 1 with GroupValidator

use of org.entando.entando.web.group.validator.GroupValidator in project entando-core by entando.

the class GroupControllerUnitTest method testParamSize.

@Test
public void testParamSize() throws ApsSystemException, Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    GroupRequest groupRequest = new GroupRequest();
    groupRequest.setCode(StringUtils.repeat("a", 21));
    groupRequest.setName(StringUtils.repeat("a", 51));
    ObjectMapper mapper = new ObjectMapper();
    String payload = mapper.writeValueAsString(groupRequest);
    this.controller.setGroupValidator(new GroupValidator());
    ResultActions result = mockMvc.perform(post("/groups").content(payload).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    // System.out.println(result.andReturn().getResponse().getContentAsString());
    result.andExpect(status().isBadRequest());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) GroupRequest(org.entando.entando.web.group.model.GroupRequest) GroupValidator(org.entando.entando.web.group.validator.GroupValidator) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 2 with GroupValidator

use of org.entando.entando.web.group.validator.GroupValidator in project entando-core by entando.

the class GroupControllerUnitTest method testValidateOnUpdateWithInvalidPathAndPayload.

@Test
public void testValidateOnUpdateWithInvalidPathAndPayload() throws ApsSystemException, Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    ObjectMapper mapper = new ObjectMapper();
    GroupRequest group = new GroupRequest();
    group.setCode("__helpdesk_");
    group.setName("Helpdesk");
    String payload = mapper.writeValueAsString(group);
    this.controller.setGroupValidator(new GroupValidator());
    ResultActions result = mockMvc.perform(put("/groups/{groupCode}", "helpdesk").content(payload).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isBadRequest());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) GroupRequest(org.entando.entando.web.group.model.GroupRequest) GroupValidator(org.entando.entando.web.group.validator.GroupValidator) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 3 with GroupValidator

use of org.entando.entando.web.group.validator.GroupValidator 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

UserDetails (com.agiletec.aps.system.services.user.UserDetails)3 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)3 GroupValidator (org.entando.entando.web.group.validator.GroupValidator)3 Test (org.junit.Test)3 ResultActions (org.springframework.test.web.servlet.ResultActions)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 GroupRequest (org.entando.entando.web.group.model.GroupRequest)2 ValidationConflictException (org.entando.entando.web.common.exceptions.ValidationConflictException)1 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)1