Search in sources :

Example 6 with GroupRequest

use of org.entando.entando.web.group.model.GroupRequest in project entando-core by entando.

the class GroupControllerIntegrationTest method testUpdateInvalidGroup.

@Test
public void testUpdateInvalidGroup() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    GroupRequest groupRequest = new GroupRequest();
    groupRequest.setCode("invalid");
    groupRequest.setName("invalid");
    ObjectMapper mapper = new ObjectMapper();
    String payload = mapper.writeValueAsString(groupRequest);
    ResultActions result = mockMvc.perform(put("/groups/{code}", groupRequest.getCode()).content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
    // System.out.println(result.andReturn().getResponse().getContentAsString());
    result.andExpect(status().isNotFound());
    result.andExpect(jsonPath("$.errors[0].code", is(GroupValidator.ERRCODE_GROUP_NOT_FOUND)));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) GroupRequest(org.entando.entando.web.group.model.GroupRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 7 with GroupRequest

use of org.entando.entando.web.group.model.GroupRequest 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)

Aggregations

GroupRequest (org.entando.entando.web.group.model.GroupRequest)7 UserDetails (com.agiletec.aps.system.services.user.UserDetails)6 Test (org.junit.Test)6 ResultActions (org.springframework.test.web.servlet.ResultActions)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)4 GroupDto (org.entando.entando.aps.system.services.group.model.GroupDto)2 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)2 GroupValidator (org.entando.entando.web.group.validator.GroupValidator)2