use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class MacroInstructionTest method setUp.
@BeforeEach
public void setUp() {
macroDescriptorService = Mockito.mock(MacroDescriptorService.class);
macroProcessorFactory = Mockito.mock(MacroProcessorFactory.class);
macroInstruction = new MacroInstruction();
macroInstruction.setMacroDescriptorService(macroDescriptorService);
macroInstruction.setMacroProcessorFactory(macroProcessorFactory);
portalRequest = new PortalRequest();
Site site = createSite("site-id", "site-name", "myapplication:content-type");
portalRequest.setSite(site);
portalRequest.setContent(site);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class MacroInstructionTest method testInstructionMacro.
@Test
public void testInstructionMacro() 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\" _body=\"body\"").getAsString();
assertEquals("mymacro: param1=value1, body=body", outputHtml);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class MacroInstructionTest method testInstructionSystemMacro.
@Test
public void testInstructionSystemMacro() throws Exception {
MacroKey key = MacroKey.from(ApplicationKey.SYSTEM, "mymacro");
MacroDescriptor macroDescriptor = MacroDescriptor.create().key(key).build();
when(macroDescriptorService.getByKey(key)).thenReturn(macroDescriptor);
when(macroDescriptorService.getByApplication(any())).thenReturn(MacroDescriptors.empty());
MacroProcessor macro = (ctx) -> PortalResponse.create().body(ctx.getName() + ": param1=" + ctx.getParam("param1") + ", body=" + ctx.getBody()).build();
when(macroProcessorFactory.fromScript(any())).thenReturn(macro);
String outputHtml = macroInstruction.evaluate(portalRequest, "MACRO _name=\"mymacro\" param1=\"value1\" _body=\"body\"").getAsString();
assertEquals("mymacro: param1=value1, body=body", outputHtml);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class MacroInstructionTest method testInstructionMacroParamsCaseInsensitive.
@Test
public void testInstructionMacroParamsCaseInsensitive() throws Exception {
MacroKey key = MacroKey.from("myapp:mymacro");
Form form = Form.create().addFormItem(createTextLineInput("param1", "Param 1").occurrences(1, 1).build()).addFormItem(createTextLineInput("param2", "Param 2").occurrences(1, 1).build()).build();
MacroDescriptor macroDescriptor = MacroDescriptor.create().key(key).form(form).build();
when(macroDescriptorService.getByKey(key)).thenReturn(macroDescriptor);
when(macroDescriptorService.getByApplication(key.getApplicationKey())).thenReturn(MacroDescriptors.from(macroDescriptor));
MacroProcessor macro = (ctx) -> PortalResponse.create().body(ctx.getName() + ": param1=" + ctx.getParam("param1") + ", body=" + ctx.getBody()).build();
when(macroProcessorFactory.fromScript(any())).thenReturn(macro);
String outputHtml = macroInstruction.evaluate(portalRequest, "MACRO _name=\"MYMACRO\" PARAM1=\"value1\" _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 htmlResponseComponentEditMode.
@Test
public void htmlResponseComponentEditMode() {
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 PortalResponse.create().body("<h1 class=\"important\">My component</h1>").contentType(MediaType.HTML_UTF_8).status(HttpStatus.OK).build();
}
@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 = "<h1 data-portal-component-type=\"part\" class=\"important\">My component</h1>";
assertEquals(expected, portalResponse.getAsString());
}
Aggregations