Search in sources :

Example 71 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class DataObjectModelControllerTest method should_load_the_list_of_dataModels_2.

@SuppressWarnings("unchecked")
@Test
public void should_load_the_list_of_dataModels_2() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    when(dataObjectModelService.getDataObjectModels(any(RestListRequest.class))).thenReturn(new PagedMetadata<DataModelDto>());
    ResultActions result = mockMvc.perform(get("/dataModels").param("page", "1").param("pageSize", "4").param("filter[0].attribute", "code").param("filter[0].value", "1").header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isOk());
    RestListRequest restListReq = new RestListRequest();
    restListReq.setPage(1);
    restListReq.setPageSize(4);
    restListReq.addFilter(new Filter("code", "1"));
    Mockito.verify(dataObjectModelService, Mockito.times(1)).getDataObjectModels(restListReq);
}
Also used : DataModelDto(org.entando.entando.aps.system.services.dataobjectmodel.model.DataModelDto) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Filter(org.entando.entando.web.common.model.Filter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 72 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class EntityManagerControllerTest method should_be_unauthorized.

@Test
public void should_be_unauthorized() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").withGroup(Group.FREE_GROUP_NAME).build();
    String accessToken = mockOAuthInterceptor(user);
    ResultActions result = mockMvc.perform(get("/entityManagers").header("Authorization", "Bearer " + accessToken));
    String response = result.andReturn().getResponse().getContentAsString();
    System.out.println(response);
    result.andExpect(status().isUnauthorized());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 73 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails 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 74 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.

the class GroupControllerIntegrationTest method testGetGroupsPagination.

@Test
public void testGetGroupsPagination() throws Exception {
    List<Group> testGroups = new ArrayList<>();
    try {
        for (int i = 0; i < 25; i++) {
            String x = ("tmp_" + i);
            Group group = new Group();
            group.setDescription(x);
            group.setName(x);
            testGroups.add(group);
            this.groupManager.addGroup(group);
        }
        UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
        String accessToken = mockOAuthInterceptor(user);
        ResultActions result = mockMvc.perform(get("/groups").param("pageSize", "5").header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(jsonPath("$.metaData.pageSize", is(5)));
        result.andExpect(jsonPath("$.metaData.totalItems", is(31)));
        result.andExpect(jsonPath("$.metaData.page", is(1)));
        result.andExpect(jsonPath("$.metaData.lastPage", is(7)));
        result.andExpect(jsonPath("$.payload[0].code", is("administrators")));
        // -------------
        result = mockMvc.perform(get("/groups").param("pageSize", "5").param("page", "1").header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(jsonPath("$.metaData.pageSize", is(5)));
        result.andExpect(jsonPath("$.metaData.totalItems", is(31)));
        result.andExpect(jsonPath("$.metaData.page", is(1)));
        result.andExpect(jsonPath("$.metaData.lastPage", is(7)));
        result.andExpect(jsonPath("$.payload[0].code", is("administrators")));
        // -------------
        result = mockMvc.perform(get("/groups").param("pageSize", "5").param("page", "7").header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(jsonPath("$.metaData.pageSize", is(5)));
        result.andExpect(jsonPath("$.metaData.totalItems", is(31)));
        result.andExpect(jsonPath("$.metaData.page", is(7)));
        result.andExpect(jsonPath("$.metaData.lastPage", is(7)));
        result.andExpect(jsonPath("$.payload[0].code", is("tmp_9")));
        // -------------
        result = mockMvc.perform(get("/groups").param("pageSize", "0").param("page", "7").header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isNotFound());
        // -------------
        result = mockMvc.perform(get("/groups").param("pageSize", "7").param("page", "0").header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isBadRequest());
        // -------------
        result = mockMvc.perform(get("/groups").param("pageSize", "1").param("page", "7").header("Authorization", "Bearer " + accessToken));
        result.andExpect(status().isOk());
        System.out.println(result.andReturn().getResponse().getContentAsString());
        result.andExpect(jsonPath("$.metaData.pageSize", is(1)));
        result.andExpect(jsonPath("$.metaData.totalItems", is(31)));
        result.andExpect(jsonPath("$.metaData.page", is(7)));
        result.andExpect(jsonPath("$.metaData.lastPage", is(31)));
        result.andExpect(jsonPath("$.payload[0].code", is("tmp_0")));
    } finally {
        for (Group group : testGroups) {
            this.groupManager.removeGroup(group);
        }
    }
}
Also used : Group(com.agiletec.aps.system.services.group.Group) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ArrayList(java.util.ArrayList) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 75 with UserDetails

use of com.agiletec.aps.system.services.user.UserDetails 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)

Aggregations

UserDetails (com.agiletec.aps.system.services.user.UserDetails)271 Test (org.junit.Test)150 ResultActions (org.springframework.test.web.servlet.ResultActions)142 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)77 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)71 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)25 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)22 Group (com.agiletec.aps.system.services.group.Group)15 ArrayList (java.util.ArrayList)15 IAuthorizationManager (com.agiletec.aps.system.services.authorization.IAuthorizationManager)14 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)13 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)12 HttpSession (javax.servlet.http.HttpSession)12 RestListRequest (org.entando.entando.web.common.model.RestListRequest)12 HashMap (java.util.HashMap)9 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)9 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)9 IPage (com.agiletec.aps.system.services.page.IPage)8 JspException (javax.servlet.jsp.JspException)8 Page (com.agiletec.aps.system.services.page.Page)7