use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class LanguageControllerUnitTest method testUpdateWrongPayload.
@Test
public void testUpdateWrongPayload() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String payload = "{\"isActive\": \"WRONG\"}";
ResultActions result = mockMvc.perform(put("/languages/{code}", new Object[] { "de" }).content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
}
use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class PageConfigurationControllerIntegrationTest method testPageConfiguration.
@Test
public void testPageConfiguration() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/pages/{pageCode}/configuration", "homepage").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result.andExpect(jsonPath("$.payload.online", is(true)));
/**
* The response should have the correct CORS headers and the CORS
* configuration should reflect the one set in
* org.entando.entando.aps.servlet.CORSFilter class
*/
result.andExpect(header().string("Access-Control-Allow-Origin", "*"));
result.andExpect(header().string("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"));
result.andExpect(header().string("Access-Control-Allow-Headers", "Content-Type, Authorization"));
result.andExpect(header().string("Access-Control-Max-Age", "3600"));
}
use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class PageConfigurationControllerIntegrationTest method testGetPageConfigurationOnLineNotFound.
/**
* Given:
* a page only in draft
* When:
* the user request the configuration for status draft
* Then
* the result is ok
*
* Given:
* a page only in draft
* When:
* the user request the configuration for status published
* Then
* an error with status code 400 is raised
*
* @throws Exception
*/
@Test
public void testGetPageConfigurationOnLineNotFound() throws Exception {
String pageCode = "draft_page_100";
try {
Page mockPage = createPage(pageCode);
this.pageManager.addPage(mockPage);
IPage onlinePage = this.pageManager.getOnlinePage(pageCode);
assertThat(onlinePage, is(nullValue()));
IPage draftPage = this.pageManager.getDraftPage(pageCode);
assertThat(draftPage, is(not(nullValue())));
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/pages/{pageCode}/configuration", new Object[] { pageCode }).param("status", IPageService.STATUS_DRAFT).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
result = mockMvc.perform(get("/pages/{pageCode}/configuration", new Object[] { pageCode }).param("status", IPageService.STATUS_ONLINE).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
} finally {
this.pageManager.deletePage(pageCode);
}
}
use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class PageConfigurationControllerWidgetsIntegrationTest method testConfigureListViewer.
@Test
public void testConfigureListViewer() throws Exception {
String pageCode = "draft_page_100";
try {
Page mockPage = createPage(pageCode);
this.pageManager.addPage(mockPage);
IPage onlinePage = this.pageManager.getOnlinePage(pageCode);
assertThat(onlinePage, is(nullValue()));
IPage draftPage = this.pageManager.getDraftPage(pageCode);
assertThat(draftPage, is(not(nullValue())));
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/pages/{pageCode}/configuration", new Object[] { pageCode }).param("status", IPageService.STATUS_DRAFT).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
String payloadWithInvalidContentType = "{\n" + " \"code\": \"content_viewer_list\",\n" + " \"config\": {\n" + " \"contentType\": \"LOL\",\n" + " \"maxElements\": \"15\"\n" + " }\n" + "}";
result = mockMvc.perform(put("/pages/{pageCode}/widgets/{frameId}", new Object[] { pageCode, 0 }).param("status", IPageService.STATUS_ONLINE).content(payloadWithInvalidContentType).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(status().isConflict());
// -------------------
String payloadWithInvalidModelId = "{\n" + " \"code\": \"content_viewer_list\",\n" + " \"config\": {\n" + " \"contentType\": \"ART\",\n" + " \"modelId\": \"9999999999\",\n" + " \"maxElements\": \"15\"\n" + " }\n" + "}";
result = mockMvc.perform(put("/pages/{pageCode}/widgets/{frameId}", new Object[] { pageCode, 0 }).param("status", IPageService.STATUS_ONLINE).content(payloadWithInvalidModelId).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
// System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(status().isConflict());
} finally {
this.pageManager.deletePage(pageCode);
}
}
use of com.agiletec.aps.system.services.user.UserDetails in project entando-core by entando.
the class PageControllerTest method shouldValidateDeletePageWithChildren.
@Test
public void shouldValidateDeletePageWithChildren() throws ApsSystemException, Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
Page page = new Page();
page.setCode("page_with_children");
page.addChildCode("child");
when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
when(this.controller.getPageValidator().getPageManager().getDraftPage(any(String.class))).thenReturn(page);
ResultActions result = mockMvc.perform(delete("/pages/{pageCode}", "page_with_children").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_PAGE_HAS_CHILDREN)));
}
Aggregations