use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class PostProcessorImplTest method processResponse_skip_non_html.
@Test
public void processResponse_skip_non_html() throws Exception {
final PostProcessorImpl postProcessor = new PostProcessorImpl();
final PortalResponse portalResponse = PortalResponse.create().contentType(MediaType.JAVASCRIPT_UTF_8).body("").build();
final PortalRequest portalRequest = new PortalRequest();
portalRequest.setMethod(HttpMethod.GET);
final PortalResponse result = postProcessor.processResponse(portalRequest, portalResponse);
assertSame(portalResponse, result);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ComponentInstructionTest method testInstructionRenderFragment.
@Test
public void testInstructionRenderFragment() throws Exception {
RendererDelegate rendererDelegate = newRendererFactory("<b>part content</b>");
ComponentService componentService = Mockito.mock(ComponentService.class);
Component component = createPartComponent();
doReturn(component).when(componentService).getByKey(isA(DescriptorKey.class));
ComponentInstruction instruction = new ComponentInstruction();
instruction.setRendererDelegate(rendererDelegate);
instruction.setComponentService(componentService);
PortalRequest portalRequest = new PortalRequest();
Content content = createFragmentPage("content-id", "content-name");
portalRequest.setContent(content);
Site site = createSite("site-id", "site-name", "myapplication:content-type");
portalRequest.setSite(site);
PageTemplate pageTemplate = createPageTemplate();
portalRequest.setPageTemplate(pageTemplate);
String outputHtml = instruction.evaluate(portalRequest, "COMPONENT fragment").getAsString();
assertEquals("<b>part content</b>", outputHtml);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class MacroInstructionTest method testInstructionMacroMultiValue.
@Test
public void testInstructionMacroMultiValue() throws Exception {
MacroKey key = MacroKey.from("myapp:mymacro");
MacroDescriptor macroDescriptor = MacroDescriptor.create().key(key).build();
when(macroDescriptorService.getByKey(key)).thenReturn(macroDescriptor);
MacroProcessor macro = (ctx) -> PortalResponse.create().body(ctx.getName() + ": param1=" + ctx.getParameter("param1").get(0) + ", body=" + ctx.getBody()).build();
when(macroProcessorFactory.fromScript(any())).thenReturn(macro);
String outputHtml = macroInstruction.evaluate(portalRequest, "MACRO _name=\"mymacro\" param1=\"value1\" param1=\"value2\" param2=\"other\" _body=\"body\"").getAsString();
assertEquals("mymacro: param1=value1, body=body", outputHtml);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class PartRendererTest method htmlResponseComponentEditModeNoMethodToHandleReq.
@Test
public void htmlResponseComponentEditModeNoMethodToHandleReq() {
final PartDescriptor partDescriptor = PartDescriptor.create().displayName("My part component").config(Form.create().build()).key(DescriptorKey.from("module:myPartComponent")).build();
final ControllerScript controllerScript = new ControllerScript() {
@Override
public PortalResponse execute(final PortalRequest portalRequest) {
return new PortalResponseSerializer(null, HttpStatus.METHOD_NOT_ALLOWED).serialize();
}
@Override
public void onSocketEvent(final WebSocketEvent event) {
}
};
final PartDescriptorService partDescriptorService = Mockito.mock(PartDescriptorService.class);
final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
renderer = new PartRenderer();
renderer.setPartDescriptorService(partDescriptorService);
renderer.setControllerScriptFactory(controllerScriptFactory);
when(partDescriptorService.getByKey(any())).thenReturn(partDescriptor);
when(controllerScriptFactory.fromDir(any())).thenReturn(controllerScript);
portalRequest.setMode(RenderMode.EDIT);
partComponent = PartComponent.create().descriptor("myapp:myPartComponent").descriptor(partDescriptor.getKey()).build();
// exercise
portalResponse = renderer.render(partComponent, portalRequest);
// verify
String expected = "<div data-portal-component-type=\"part\" data-portal-placeholder=\"true\" data-portal-placeholder-error=\"true\"><span class=\"data-portal-placeholder-error\">No method provided to handle request</span></div>";
assertEquals(expected, portalResponse.getAsString());
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class PartRendererTest method before.
@BeforeEach
public void before() {
this.portalRequest = new PortalRequest();
this.portalRequest.setBranch(Branch.from("draft"));
this.portalRequest.setApplicationKey(ApplicationKey.from("myapplication"));
this.portalRequest.setBaseUri("/site");
this.portalRequest.setContentPath(ContentPath.from("context/path"));
this.portalResponse = PortalResponse.create().build();
this.portalRequest.setMode(RenderMode.EDIT);
}
Aggregations