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());
}
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());
}
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)));
}
Aggregations