Search in sources :

Example 1 with GroupRequest

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

the class GroupControllerIntegrationTest 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);
    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) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 2 with GroupRequest

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

the class GroupControllerIntegrationTest method testAddExistingGroup.

@Test
public void testAddExistingGroup() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    GroupDto group = this.groupService.getGroup(Group.FREE_GROUP_NAME);
    GroupRequest groupRequest = new GroupRequest();
    groupRequest.setCode(group.getCode());
    groupRequest.setName(group.getName());
    ObjectMapper mapper = new ObjectMapper();
    String payload = mapper.writeValueAsString(groupRequest);
    ResultActions result = mockMvc.perform(post("/groups").content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
    // System.out.println(result.andReturn().getResponse().getContentAsString());
    result.andExpect(status().isConflict());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) GroupRequest(org.entando.entando.web.group.model.GroupRequest) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 3 with GroupRequest

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

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

the class GroupValidator method validate.

@Override
public void validate(Object target, Errors errors) {
    GroupRequest request = (GroupRequest) target;
    String groupCode = request.getCode();
    if (null != groupManager.getGroup(groupCode)) {
        errors.reject(ERRCODE_GROUP_ALREADY_EXISTS, new String[] { groupCode }, "group.exists");
    }
}
Also used : GroupRequest(org.entando.entando.web.group.model.GroupRequest)

Example 5 with GroupRequest

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

the class GroupControllerIntegrationTest method testGetInvalidGroup.

@Test
public void testGetInvalidGroup() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    GroupDto group = this.groupService.getGroup(Group.FREE_GROUP_NAME);
    GroupRequest groupRequest = new GroupRequest();
    groupRequest.setCode(group.getCode());
    groupRequest.setName(group.getName());
    ResultActions result = mockMvc.perform(get("/groups/{code}", "invalid_code").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) GroupDto(org.entando.entando.aps.system.services.group.model.GroupDto) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

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