use of com.enonic.xp.portal.postprocess.PostProcessInstruction 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.postprocess.PostProcessInstruction in project xp by enonic.
the class PostProcessEvaluatorTest method testEvaluateInstructionSetContribution.
@Test
public void testEvaluateInstructionSetContribution() throws Exception {
final PostProcessInstruction setCookieInstruction = (portalRequest, instruction) -> {
if (instruction.startsWith("INSTRUCTION")) {
return PortalResponse.create().contribution(HtmlTag.BODY_END, "<script src='my-script.js'/>").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.getContributions(HtmlTag.BODY_END).size());
assertEquals("<script src='my-script.js'/>", result.getContributions(HtmlTag.BODY_END).get(0));
}
use of com.enonic.xp.portal.postprocess.PostProcessInstruction in project xp by enonic.
the class PostProcessEvaluatorTest method testEvaluateInstructions.
@Test
public void testEvaluateInstructions() throws Exception {
final PostProcessInstruction uppercaseInstruction = (portalRequest, instruction) -> {
if (instruction.startsWith("UPPERCASE ")) {
return PortalResponse.create().body(instruction.substring("UPPERCASE ".length()).toUpperCase()).build();
}
return null;
};
final PostProcessInstruction expandInstruction = (portalRequest, instruction) -> {
if (instruction.startsWith("EXPAND ")) {
return PortalResponse.create().body("<!--#UPPERCASE " + instruction.substring("EXPAND ".length()) + "-->").build();
}
return null;
};
final PostProcessEvaluator evaluator = new PostProcessEvaluator();
evaluator.input = readResource("postProcessEvalSource3.html");
evaluator.injections = Collections.emptyList();
evaluator.instructions = List.of(uppercaseInstruction, expandInstruction);
evaluator.portalResponse = PortalResponse.create().build();
final PortalResponse result = evaluator.evaluate();
assertEqualsTrimmed(readResource("postProcessEvalResult3.html"), result.getAsString());
}
use of com.enonic.xp.portal.postprocess.PostProcessInstruction 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());
}
use of com.enonic.xp.portal.postprocess.PostProcessInstruction in project xp by enonic.
the class PostProcessEvaluatorTest method testEvaluateInstructionSetCookie.
@Test
public void testEvaluateInstructionSetCookie() throws Exception {
final PostProcessInstruction setCookieInstruction = (portalRequest, instruction) -> {
if (instruction.startsWith("INSTRUCTION")) {
return PortalResponse.create().cookie(new Cookie("cookie-name", "cookie-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.getCookies().size());
assertEquals("cookie-name", result.getCookies().get(0).getName());
assertEquals("cookie-value", result.getCookies().get(0).getValue());
}
Aggregations