use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class LiveEditAttributeInjectionTest method injectEmptyHtml.
@Test
public void injectEmptyHtml() throws Exception {
final String 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 = "";
assertEquals(expectedResult, outputHtml);
}
use of com.enonic.xp.portal.PortalResponse 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());
}
use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class PostProcessEvaluatorTest method testEvaluateInstructionSetHeader.
@Test
public void testEvaluateInstructionSetHeader() throws Exception {
final PostProcessInstruction setCookieInstruction = (portalRequest, instruction) -> {
if (instruction.startsWith("INSTRUCTION")) {
return PortalResponse.create().header("header-name", "header-value").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(1, result.getHeaders().size());
assertEquals("header-value", result.getHeaders().get("header-name"));
}
use of com.enonic.xp.portal.PortalResponse 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());
}
use of com.enonic.xp.portal.PortalResponse 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());
}
Aggregations