Search in sources :

Example 11 with ResultActions

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);
    }
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Page(com.agiletec.aps.system.services.page.Page) IPage(com.agiletec.aps.system.services.page.IPage) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 12 with ResultActions

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)));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ArrayList(java.util.ArrayList) ResultActions(org.springframework.test.web.servlet.ResultActions) PageStatusRequest(org.entando.entando.web.page.model.PageStatusRequest) AbstractControllerTest(org.entando.entando.web.AbstractControllerTest) Test(org.junit.Test)

Example 13 with ResultActions

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());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 14 with ResultActions

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());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 15 with ResultActions

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());
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Aggregations

ResultActions (org.springframework.test.web.servlet.ResultActions)600 Test (org.junit.Test)525 UserDetails (com.agiletec.aps.system.services.user.UserDetails)297 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)221 AbstractControllerTest (org.entando.entando.web.AbstractControllerTest)101 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)43 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)39 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)38 MvcResult (org.springframework.test.web.servlet.MvcResult)27 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)26 UUID (java.util.UUID)22 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)22 InputStream (java.io.InputStream)18 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)17 HashMap (java.util.HashMap)17 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)16 Test (org.junit.jupiter.api.Test)15 WebIntegrationBaseTest (org.nextprot.api.web.dbunit.base.mvc.WebIntegrationBaseTest)14 IPage (com.agiletec.aps.system.services.page.IPage)13 Page (com.agiletec.aps.system.services.page.Page)12