Search in sources :

Example 6 with PortalResponse

use of com.enonic.xp.portal.PortalResponse in project xp by enonic.

the class PageHandlerTest method getContentFound.

@Test
public void getContentFound() throws Exception {
    setupSite();
    setupContent();
    setupTemplates();
    final PortalResponse portalResponse = PortalResponse.create().body("component rendered").header("some-header", "some-value").status(HttpStatus.OK).build();
    setRendererResult(portalResponse);
    this.request.setContentPath(ContentPath.from("/site/somepath/content"));
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals(MediaType.PLAIN_TEXT_UTF_8, res.getContentType());
    assertEquals("some-value", res.getHeaders().get("some-header"));
    assertEquals("component rendered", res.getBody());
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebResponse(com.enonic.xp.web.WebResponse) Test(org.junit.jupiter.api.Test)

Example 7 with PortalResponse

use of com.enonic.xp.portal.PortalResponse in project xp by enonic.

the class PageHandlerTest method renderCustomizedTemplate.

@Test
public void renderCustomizedTemplate() throws Exception {
    setupCustomizedTemplateContentAndSite();
    setupController();
    final PortalResponse portalResponse = PortalResponse.create().body("content rendered").header("some-header", "some-value").status(HttpStatus.OK).build();
    setRendererResult(portalResponse);
    this.request.setContentPath(ContentPath.from("/id"));
    this.request.setMode(RenderMode.EDIT);
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals(MediaType.PLAIN_TEXT_UTF_8, res.getContentType());
    assertEquals("some-value", res.getHeaders().get("some-header"));
    assertEquals("content rendered", res.getBody());
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebResponse(com.enonic.xp.web.WebResponse) Test(org.junit.jupiter.api.Test)

Example 8 with PortalResponse

use of com.enonic.xp.portal.PortalResponse in project xp by enonic.

the class PageHandlerTest method testOptions.

@Test
public void testOptions() throws Exception {
    setupSite();
    setupContent();
    setupTemplates();
    final PortalResponse portalResponse = PortalResponse.create().status(HttpStatus.METHOD_NOT_ALLOWED).build();
    setRendererResult(portalResponse);
    this.request.setContentPath(ContentPath.from("/site/somepath/content"));
    this.request.setMethod(HttpMethod.OPTIONS);
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals("GET,POST,HEAD,OPTIONS,PUT,DELETE,TRACE", res.getHeaders().get("Allow"));
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebResponse(com.enonic.xp.web.WebResponse) Test(org.junit.jupiter.api.Test)

Example 9 with PortalResponse

use of com.enonic.xp.portal.PortalResponse in project xp by enonic.

the class PageHandlerTest method renderForNoPageDescriptor.

@Test
public void renderForNoPageDescriptor() throws Exception {
    setupSite();
    setupContent();
    setupTemplates();
    final PortalResponse portalResponse = PortalResponse.create().body("content rendered").header("some-header", "some-value").status(HttpStatus.OK).build();
    setRendererResult(portalResponse);
    this.request.setContentPath(ContentPath.from("/site/somepath/content"));
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals(MediaType.PLAIN_TEXT_UTF_8, res.getContentType());
    assertEquals("some-value", res.getHeaders().get("some-header"));
    assertEquals("content rendered", res.getBody());
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebResponse(com.enonic.xp.web.WebResponse) Test(org.junit.jupiter.api.Test)

Example 10 with PortalResponse

use of com.enonic.xp.portal.PortalResponse in project xp by enonic.

the class AttachmentHandlerTest method cacheHeader.

@Test
void cacheHeader() throws Exception {
    this.request.setEndpointPath("/_/attachment/inline/123456:98765/logo.png");
    final PortalResponse res = (PortalResponse) this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertEquals("public, max-age=31536000, immutable", res.getHeaders().get("Cache-Control"));
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Aggregations

PortalResponse (com.enonic.xp.portal.PortalResponse)104 Test (org.junit.jupiter.api.Test)78 PortalRequest (com.enonic.xp.portal.PortalRequest)21 WebException (com.enonic.xp.web.WebException)14 BaseHandlerTest (com.enonic.xp.web.handler.BaseHandlerTest)14 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)13 PostProcessInstruction (com.enonic.xp.portal.postprocess.PostProcessInstruction)10 WebResponse (com.enonic.xp.web.WebResponse)10 ContentService (com.enonic.xp.content.ContentService)9 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)9 ResourceKey (com.enonic.xp.resource.ResourceKey)9 RenderMode (com.enonic.xp.portal.RenderMode)8 HtmlTag (com.enonic.xp.portal.postprocess.HtmlTag)8 PostProcessInjection (com.enonic.xp.portal.postprocess.PostProcessInjection)8 ByteSource (com.google.common.io.ByteSource)8 InputStream (java.io.InputStream)8 StandardCharsets (java.nio.charset.StandardCharsets)8 Arrays (java.util.Arrays)8 Collections (java.util.Collections)8 List (java.util.List)8