Search in sources :

Example 96 with UserDetails

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

the class PageControllerTest method shouldValidatePutPathMismatch.

@Test
public void shouldValidatePutPathMismatch() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String mockJsonResult = "{\n" + "            \"code\": \"hello_page\",\n" + "            \"status\": \"draft\",\n" + "            \"displayedInMenu\": true,\n" + "            \"pageModel\": \"service\",\n" + "            \"charset\": \"utf8\",\n" + "            \"contentType\": \"text/html\",\n" + "            \"parentCode\": \"service\",\n" + "            \"seo\": false,\n" + "            \"titles\": {\n" + "                    \"en\": \"My Title\",\n" + "                \"it\": \"Mio Titolo\"\n" + "                },\n" + "            \"ownerGroup\": \"free\",\n" + "            \"joinGroups\": [\n" + "                \"free\",\n" + "                \"administrators\"\n" + "            ],\n" + "            \"position\": 7\n" + "        }";
    PageDto mockResult = (PageDto) this.createMetadata(mockJsonResult, PageDto.class);
    when(pageService.updatePage(any(String.class), any(PageRequest.class))).thenReturn(mockResult);
    when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
    ResultActions result = mockMvc.perform(put("/pages/{pageCode}", "wrong_page").sessionAttr("user", user).contentType(MediaType.APPLICATION_JSON).content(mockJsonResult).header("Authorization", "Bearer " + accessToken));
    String response = result.andReturn().getResponse().getContentAsString();
    result.andExpect(status().isBadRequest());
    result.andExpect(jsonPath("$.errors", hasSize(1)));
    result.andExpect(jsonPath("$.errors[0].code", is(PageController.ERRCODE_URINAME_MISMATCH)));
}
Also used : PageRequest(org.entando.entando.web.page.model.PageRequest) UserDetails(com.agiletec.aps.system.services.user.UserDetails) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 97 with UserDetails

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

the class PageControllerTest method shouldBeUnauthorized.

@Test
public void shouldBeUnauthorized() 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("/pages/{parentCode}", "mock_page").sessionAttr("user", user).header("Authorization", "Bearer " + accessToken));
    String response = result.andReturn().getResponse().getContentAsString();
    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 98 with UserDetails

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

the class PageControllerTest method shouldValidateDeleteOnlinePage.

@Test
public void shouldValidateDeleteOnlinePage() throws ApsSystemException, Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
    when(this.controller.getPageValidator().getPageManager().getOnlinePage(any(String.class))).thenReturn(new Page());
    ResultActions result = mockMvc.perform(delete("/pages/{pageCode}", "online_page").sessionAttr("user", user).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isBadRequest());
    String response = result.andReturn().getResponse().getContentAsString();
    result.andExpect(jsonPath("$.errors", hasSize(1)));
    result.andExpect(jsonPath("$.errors[0].code", is(PageController.ERRCODE_ONLINE_PAGE)));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) Page(com.agiletec.aps.system.services.page.Page) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 99 with UserDetails

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

the class PageControllerTest method shouldValidateMovePageInvalidRequest.

@Test
public void shouldValidateMovePageInvalidRequest() throws ApsSystemException, Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    PagePositionRequest request = new PagePositionRequest();
    request.setCode("page_to_move");
    request.setParentCode(null);
    request.setPosition(0);
    when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
    ResultActions result = mockMvc.perform(put("/pages/{pageCode}/position", "page_to_move").sessionAttr("user", user).content(convertObjectToJsonBytes(request)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
    result.andExpect(status().isBadRequest());
    String response = result.andReturn().getResponse().getContentAsString();
    result.andExpect(jsonPath("$.errors", hasSize(1)));
    result.andExpect(jsonPath("$.errors[0].code", is("NotBlank")));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) PagePositionRequest(org.entando.entando.web.page.model.PagePositionRequest) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 100 with UserDetails

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

the class PageControllerTest method shouldLoadAPageTree.

@Test
public void shouldLoadAPageTree() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String mockJsonResult = "[\n" + "        {\n" + "            \"code\": \"notfound\",\n" + "            \"status\": \"draft\",\n" + "            \"displayedInMenu\": true,\n" + "            \"pageModel\": \"service\",\n" + "            \"charset\": null,\n" + "            \"contentType\": null,\n" + "            \"parentCode\": \"service\",\n" + "            \"seo\": false,\n" + "            \"titles\": {\"en\": \"Page not found\",\n" + "                \"it\": \"Pagina non trovata\"\n" + "                },\n" + "            \"ownerGroup\": \"free\",\n" + "            \"joinGroups\": [],\n" + "            \"position\": 4\n" + "        },\n" + "        {\n" + "            \"code\": \"errorpage\",\n" + "            \"status\": \"draft\",\n" + "            \"displayedInMenu\": true,\n" + "            \"pageModel\": \"service\",\n" + "            \"charset\": null,\n" + "            \"contentType\": null,\n" + "            \"parentCode\": \"service\",\n" + "            \"seo\": false,\n" + "            \"titles\": {\n" + "                \"en\": \"Error page\",\n" + "                \"it\": \"Pagina di errore\"\n" + "                },\n" + "            \"ownerGroup\": \"free\",\n" + "            \"joinGroups\": [],\n" + "            \"position\": 5\n" + "        },\n" + "        {\n" + "            \"code\": \"login\",\n" + "            \"status\": \"draft\",\n" + "            \"displayedInMenu\": true,\n" + "            \"pageModel\": \"service\",\n" + "            \"charset\": null,\n" + "            \"contentType\": null,\n" + "            \"parentCode\": \"service\",\n" + "            \"seo\": false,\n" + "            \"titles\": {\n" + "                    \"en\": \"Login\",\n" + "                \"it\": \"Pagina di login\"\n" + "                },\n" + "            \"ownerGroup\": \"free\",\n" + "            \"joinGroups\": [],\n" + "            \"position\": 6\n" + "        },\n" + "        {\n" + "            \"code\": \"hello_page\",\n" + "            \"status\": \"draft\",\n" + "            \"displayedInMenu\": true,\n" + "            \"pageModel\": \"service\",\n" + "            \"charset\": \"utf8\",\n" + "            \"contentType\": \"text/html\",\n" + "            \"parentCode\": \"service\",\n" + "            \"seo\": false,\n" + "            \"titles\": {\n" + "                    \"en\": \"My Title\",\n" + "                \"it\": \"Mio Titolo\"\n" + "                },\n" + "            \"ownerGroup\": \"free\",\n" + "            \"joinGroups\": [\n" + "                \"free\",\n" + "                \"administrators\"\n" + "            ],\n" + "            \"position\": 7\n" + "        }\n" + "    ]";
    List<PageDto> mockResult = (List<PageDto>) this.createMetadataList(mockJsonResult);
    when(pageService.getPages(any(String.class))).thenReturn(mockResult);
    when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
    ResultActions result = mockMvc.perform(get("/pages").param("parentCode", "service").sessionAttr("user", user).header("Authorization", "Bearer " + accessToken));
    String response = result.andReturn().getResponse().getContentAsString();
    result.andExpect(status().isOk());
    result.andExpect(jsonPath("$.errors", hasSize(0)));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) PageDto(org.entando.entando.aps.system.services.page.model.PageDto) ArrayList(java.util.ArrayList) List(java.util.List) ResultActions(org.springframework.test.web.servlet.ResultActions) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

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