Search in sources :

Example 51 with PortalResponse

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

the class ComponentHandlerTest method testComponentFragment.

@Test
public void testComponentFragment() throws Exception {
    setupSite();
    setupContentFragment();
    setupTemplates();
    final PortalResponse portalResponse = PortalResponse.create().body("component rendered").header("some-header", "some-value").status(HttpStatus.OK).build();
    Mockito.when(this.postProcessor.processResponseInstructions(Mockito.any(), Mockito.any())).thenReturn(portalResponse);
    setRendererResult(portalResponse);
    this.request.setEndpointPath("/_/component/main-region/0");
    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 52 with PortalResponse

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

the class ServiceHandlerTest method testOptions.

@Test
public void testOptions() throws Exception {
    this.request.setMethod(HttpMethod.OPTIONS);
    final PortalResponse portalResponse = PortalResponse.create().status(HttpStatus.METHOD_NOT_ALLOWED).build();
    Mockito.when(this.controllerScript.execute(Mockito.any())).thenReturn(portalResponse);
    this.request.setEndpointPath("/_/service/demo/test");
    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) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 53 with PortalResponse

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

the class MacroInstructionTest method testMacroInstructionWithoutName.

@Test
public void testMacroInstructionWithoutName() throws Exception {
    PortalResponse response = macroInstruction.evaluate(portalRequest, "MACRO param1=\"value1\" _body=\"body\"");
    assertNull(response);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) Test(org.junit.jupiter.api.Test)

Example 54 with PortalResponse

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

the class LiveEditAttributeInjectionTest method injectWithSingleComment.

@Test
public void injectWithSingleComment() throws Exception {
    final String html = readResource("part8Source.html");
    final LiveEditAttributeInjection liveEditAttributeInjection = new LiveEditAttributeInjection();
    final PortalResponse.Builder responseBuilder = PortalResponse.create().body(html);
    final PortalResponse portalResponse = liveEditAttributeInjection.injectLiveEditAttribute(responseBuilder.build(), TextComponentType.INSTANCE);
    final String outputHtml = portalResponse.getBody().toString();
    final String expectedResult = readResource("part8Rendered.html");
    assertEquals(expectedResult, outputHtml);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) Test(org.junit.jupiter.api.Test)

Example 55 with PortalResponse

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

the class PostProcessEvaluatorTest method testEvaluateInstructionSetApplyFilters.

@Test
public void testEvaluateInstructionSetApplyFilters() throws Exception {
    final PostProcessInstruction setCookieInstruction = (portalRequest, instruction) -> {
        if (instruction.startsWith("INSTRUCTION")) {
            return PortalResponse.create().applyFilters(false).build();
        }
        return null;
    };
    final PostProcessEvaluator evaluator = new PostProcessEvaluator();
    evaluator.input = readResource("postProcessEvalSource6.html");
    evaluator.injections = Collections.emptyList();
    evaluator.instructions = List.of(setCookieInstruction);
    evaluator.portalResponse = PortalResponse.create().build();
    final PortalResponse result = evaluator.evaluate();
    assertEquals(false, result.applyFilters());
}
Also used : Arrays(java.util.Arrays) StandardCharsets(java.nio.charset.StandardCharsets) Collectors.joining(java.util.stream.Collectors.joining) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) HtmlTag(com.enonic.xp.portal.postprocess.HtmlTag) PortalResponse(com.enonic.xp.portal.PortalResponse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Cookie(javax.servlet.http.Cookie) PostProcessInstruction(com.enonic.xp.portal.postprocess.PostProcessInstruction) Collections(java.util.Collections) PostProcessInjection(com.enonic.xp.portal.postprocess.PostProcessInjection) InputStream(java.io.InputStream) PortalResponse(com.enonic.xp.portal.PortalResponse) PostProcessInstruction(com.enonic.xp.portal.postprocess.PostProcessInstruction) 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