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());
}
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"));
}
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);
}
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);
}
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());
}
Aggregations