use of org.springframework.test.web.servlet.ResultActions 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 org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class PageControllerTest method shouldValidateStatusPutDraftRef.
@Test
public void shouldValidateStatusPutDraftRef() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
PageStatusRequest request = new PageStatusRequest();
request.setStatus("draft");
PageM pageToUnpublish = new PageM(true);
pageToUnpublish.setCode("page_to_unpublish");
pageToUnpublish.setParentCode("service");
pageToUnpublish.setChildrenCodes(new String[] { "child_page" });
PageM child = new PageM(true);
child.setCode("child_page");
child.setParentCode("page_to_unpublish");
PageM root = new PageM(true);
root.setCode("home");
root.setParentCode("home");
when(authorizationService.isAuth(any(UserDetails.class), any(String.class))).thenReturn(true);
when(this.controller.getPageValidator().getPageManager().getDraftPage(any(String.class))).thenReturn(pageToUnpublish, child);
when(this.controller.getPageValidator().getPageManager().getOnlineRoot()).thenReturn(root);
when(this.controller.getPageValidator().getPageUtilizer().getPageUtilizers(any(String.class))).thenReturn(new ArrayList());
ResultActions result = mockMvc.perform(put("/pages/{pageCode}/status", "page_to_publish").sessionAttr("user", user).content(convertObjectToJsonBytes(request)).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isBadRequest());
String response = result.andReturn().getResponse().getContentAsString();
System.out.println("RESPONSE: " + response);
result.andExpect(jsonPath("$.errors", hasSize(1)));
result.andExpect(jsonPath("$.errors[0].code", is(PageController.ERRCODE_REFERENCED_ONLINE_PAGE)));
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class PageModelControllerIntegrationTest method testAddPageModelWithExistingCode.
@Test
public void testAddPageModelWithExistingCode() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
String payload = " {\n" + " \"code\": \"home\",\n" + " \"descr\": \"test\",\n" + " \"configuration\": {\n" + " \"frames\": [{\n" + " \"pos\": 0,\n" + " \"descr\": \"test_frame\",\n" + " \"mainFrame\": false,\n" + " \"defaultWidget\": null,\n" + " \"sketch\": null\n" + " }]\n" + " },\n" + " \"pluginCode\": null,\n" + " \"template\": \"ciao\"\n" + " }";
ResultActions result = mockMvc.perform(post("/pagemodels").content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
// System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(status().isConflict());
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class PageModelControllerIntegrationTest method testGetPageModels.
@Test
public void testGetPageModels() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(get("/pagemodels").header("Authorization", "Bearer " + accessToken));
result.andExpect(status().isOk());
// System.out.println(result.andReturn().getResponse().getContentAsString());
}
use of org.springframework.test.web.servlet.ResultActions in project entando-core by entando.
the class PageModelControllerIntegrationTest method testDeletePageModelUnexistigCode.
@Test
public void testDeletePageModelUnexistigCode() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = mockMvc.perform(delete("/pagemodels/{code}", "unexistingPageModel").contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
// System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(status().isOk());
}
Aggregations