Search in sources :

Example 16 with PortalResponse

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

the class PostProcessorImplTest method testPostProcessingInstructions.

private void testPostProcessingInstructions(final HttpMethod httpMethod) throws Exception {
    final String html = readResource("postProcessSource1.html");
    final PostProcessorImpl postProcessor = new PostProcessorImpl();
    postProcessor.addInstruction(new TestPostProcessInstruction());
    final PortalResponse.Builder portalResponseBuilder = PortalResponse.create().contentType(MediaType.HTML_UTF_8).body(html);
    final PortalRequest portalRequest = new PortalRequest();
    portalRequest.setMethod(httpMethod);
    final PortalResponse portalResponse = postProcessor.processResponse(portalRequest, portalResponseBuilder.build());
    final String outputHtml = portalResponse.getBody().toString();
    final String expectedResult = readResource("postProcessResult1.html");
    assertEqualsTrimmed(expectedResult, outputHtml);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 17 with PortalResponse

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

the class MacroInstructionTest method testNoMacroInstruction.

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

Example 18 with PortalResponse

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

the class MacroInstructionTest method testInvalidMacroInstruction.

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

Example 19 with PortalResponse

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

the class LiveEditAttributeInjectionTest method nonSingleRootTagHtml.

@Test
public void nonSingleRootTagHtml() throws Exception {
    final String html = readResource("part6Source.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();
    assertEquals(html, outputHtml);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) Test(org.junit.jupiter.api.Test)

Example 20 with PortalResponse

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

the class LiveEditAttributeInjectionTest method injectWithMultipleComments.

@Test
public void injectWithMultipleComments() throws Exception {
    final String html = readResource("part9Source.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("part9Rendered.html");
    assertEquals(expectedResult, outputHtml);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) 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