Search in sources :

Example 1 with PostProcessInjection

use of com.enonic.xp.portal.postprocess.PostProcessInjection in project xp by enonic.

the class PostProcessEvaluatorTest method testEvaluateDuplicatedContributions.

@Test
public void testEvaluateDuplicatedContributions() throws Exception {
    final PostProcessInjection contributionsInjection = (portalRequest, portalResponse, tag) -> {
        switch(tag) {
            case HEAD_BEGIN:
                return Arrays.asList("<!-- HEAD BEGIN-->", "<!-- HEAD BEGIN DUPLICATED-1 -->", "<!-- HEAD BEGIN DUPLICATED-2 -->");
            case HEAD_END:
                return Arrays.asList("<!-- HEAD END -->");
            case BODY_BEGIN:
                return Arrays.asList("<!-- BODY BEGIN -->");
            case BODY_END:
                return Arrays.asList("<!-- BODY END -->");
            default:
                return null;
        }
    };
    final PostProcessInjection contributionsInjection2 = (portalRequest, portalResponse, tag) -> {
        switch(tag) {
            case HEAD_BEGIN:
                return Arrays.asList("<!-- HEAD BEGIN DUPLICATED-2 -->", "<!-- HEAD BEGIN DUPLICATED-1 -->");
            case BODY_END:
                return Arrays.asList("<!-- BODY END -->");
            default:
                return null;
        }
    };
    final PostProcessEvaluator evaluator = new PostProcessEvaluator();
    evaluator.input = readResource("postProcessEvalSource5.html");
    evaluator.injections = List.of(contributionsInjection, contributionsInjection2);
    evaluator.instructions = Collections.emptyList();
    evaluator.portalResponse = PortalResponse.create().build();
    final PortalResponse result = evaluator.evaluate();
    assertEqualsTrimmed(readResource("postProcessEvalResult5.html"), result.getAsString());
}
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) PostProcessInjection(com.enonic.xp.portal.postprocess.PostProcessInjection) Test(org.junit.jupiter.api.Test)

Example 2 with PostProcessInjection

use of com.enonic.xp.portal.postprocess.PostProcessInjection in project xp by enonic.

the class PostProcessEvaluatorTest method testEvaluateMultipleContributions.

@Test
public void testEvaluateMultipleContributions() throws Exception {
    final PostProcessInjection contributionsInjection = (portalRequest, portalResponse, tag) -> {
        switch(tag) {
            case HEAD_BEGIN:
                return Arrays.asList("<!-- HEAD BEGIN -->");
            case HEAD_END:
                return Arrays.asList("<!-- HEAD END -->");
            case BODY_BEGIN:
                return Arrays.asList("<!-- BODY BEGIN -->");
            case BODY_END:
                return Arrays.asList("<!-- BODY END -->");
            default:
                return null;
        }
    };
    final PostProcessInjection contributionsInjection2 = (portalRequest, portalResponse, tag) -> {
        switch(tag) {
            case HEAD_BEGIN:
                return Arrays.asList("<!-- HEAD BEGIN EXTRA-->");
            case BODY_END:
                return Arrays.asList("<!-- BODY END EXTRA-->");
            default:
                return null;
        }
    };
    final PostProcessEvaluator evaluator = new PostProcessEvaluator();
    evaluator.input = readResource("postProcessEvalSource4.html");
    evaluator.injections = List.of(contributionsInjection, contributionsInjection2);
    evaluator.instructions = Collections.emptyList();
    evaluator.portalResponse = PortalResponse.create().build();
    final PortalResponse result = evaluator.evaluate();
    assertEqualsTrimmed(readResource("postProcessEvalResult4.html"), result.getAsString());
}
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) PostProcessInjection(com.enonic.xp.portal.postprocess.PostProcessInjection) Test(org.junit.jupiter.api.Test)

Example 3 with PostProcessInjection

use of com.enonic.xp.portal.postprocess.PostProcessInjection in project xp by enonic.

the class PostProcessEvaluatorTest method testEvaluateContributions.

@Test
public void testEvaluateContributions() throws Exception {
    final PostProcessInjection contributionsInjection = (portalRequest, portalResponse, tag) -> {
        switch(tag) {
            case HEAD_BEGIN:
                return Arrays.asList("<!-- HEAD BEGIN -->");
            case HEAD_END:
                return Arrays.asList("<!-- HEAD END -->");
            case BODY_BEGIN:
                return Arrays.asList("<!-- BODY BEGIN -->");
            case BODY_END:
                return Arrays.asList("<!-- BODY END -->");
            default:
                return null;
        }
    };
    final PostProcessEvaluator evaluator = new PostProcessEvaluator();
    evaluator.input = readResource("postProcessEvalSource2.html");
    evaluator.injections = List.of(contributionsInjection);
    evaluator.instructions = Collections.emptyList();
    evaluator.portalResponse = PortalResponse.create().build();
    final PortalResponse result = evaluator.evaluate();
    assertEqualsTrimmed(readResource("postProcessEvalResult2.html"), result.getAsString());
}
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) PostProcessInjection(com.enonic.xp.portal.postprocess.PostProcessInjection) Test(org.junit.jupiter.api.Test)

Example 4 with PostProcessInjection

use of com.enonic.xp.portal.postprocess.PostProcessInjection in project xp by enonic.

the class PostProcessEvaluatorTest method testEvaluateInstructionsAndContributions.

@Test
public void testEvaluateInstructionsAndContributions() throws Exception {
    final PostProcessInjection contributionsInjection = (portalRequest, portalResponse, tag) -> {
        switch(tag) {
            case HEAD_BEGIN:
                return Arrays.asList("<!-- HEAD BEGIN -->");
            case HEAD_END:
                return Arrays.asList("<!-- HEAD END -->");
            case BODY_BEGIN:
                return Arrays.asList("<!-- BODY BEGIN -->");
            case BODY_END:
                return Arrays.asList("<!-- BODY END -->");
            default:
                return null;
        }
    };
    final PostProcessEvaluator evaluator = new PostProcessEvaluator();
    evaluator.input = readResource("postProcessEvalSource2.html");
    evaluator.injections = List.of(contributionsInjection);
    evaluator.instructions = Collections.emptyList();
    evaluator.portalResponse = PortalResponse.create().build();
    evaluator.evaluateInstructions();
    final PortalResponse result = evaluator.evaluateContributions();
    assertEqualsTrimmed(readResource("postProcessEvalResult2.html"), result.getAsString());
}
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) PostProcessInjection(com.enonic.xp.portal.postprocess.PostProcessInjection) Test(org.junit.jupiter.api.Test)

Aggregations

PortalResponse (com.enonic.xp.portal.PortalResponse)4 HtmlTag (com.enonic.xp.portal.postprocess.HtmlTag)4 PostProcessInjection (com.enonic.xp.portal.postprocess.PostProcessInjection)4 PostProcessInstruction (com.enonic.xp.portal.postprocess.PostProcessInstruction)4 InputStream (java.io.InputStream)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 List (java.util.List)4 Collectors.joining (java.util.stream.Collectors.joining)4 Stream (java.util.stream.Stream)4 Cookie (javax.servlet.http.Cookie)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Test (org.junit.jupiter.api.Test)4