Search in sources :

Example 91 with UserDetails

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());
}
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 92 with UserDetails

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"));
}
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 93 with UserDetails

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);
    }
}
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 94 with UserDetails

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);
    }
}
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 95 with UserDetails

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)));
}
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)

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