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