use of com.enonic.xp.portal.impl.rendering.RendererDelegate in project xp by enonic.
the class ComponentInstructionTest method testInstruction.
@Test
public void testInstruction() throws Exception {
RendererDelegate rendererDelegate = newRendererFactory("<b>part content</b>");
ComponentService componentService = Mockito.mock(ComponentService.class);
ComponentInstruction instruction = new ComponentInstruction();
instruction.setRendererDelegate(rendererDelegate);
instruction.setComponentService(componentService);
PortalRequest portalRequest = new PortalRequest();
Content content = createPage("content-id", "content-name", "myapplication:content-type");
portalRequest.setContent(content);
Site site = createSite("site-id", "site-name", "myapplication:content-type");
portalRequest.setSite(site);
String outputHtml = instruction.evaluate(portalRequest, "COMPONENT myRegion/0").getAsString();
assertEquals("<b>part content</b>", outputHtml);
}
use of com.enonic.xp.portal.impl.rendering.RendererDelegate in project xp by enonic.
the class ComponentInstructionTest method testInstructionRenderByName.
@Test
public void testInstructionRenderByName() throws Exception {
RendererDelegate rendererFactory = 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(rendererFactory);
instruction.setComponentService(componentService);
PortalRequest portalRequest = new PortalRequest();
Content content = createPage("content-id", "content-name", "myapplication:content-type");
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 module:myPartComponent").getAsString();
assertEquals("<b>part content</b>", outputHtml);
}
use of com.enonic.xp.portal.impl.rendering.RendererDelegate 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.impl.rendering.RendererDelegate in project xp by enonic.
the class MappingHandlerTest method setup.
@BeforeEach
public final void setup() throws Exception {
this.request = new PortalRequest();
final ControllerScriptFactory controllerScriptFactory = mock(ControllerScriptFactory.class);
ControllerScript controllerScript = mock(ControllerScript.class);
when(controllerScriptFactory.fromDir(Mockito.any())).thenReturn(controllerScript);
final PortalResponse portalResponse = PortalResponse.create().build();
when(controllerScript.execute(Mockito.any())).thenReturn(portalResponse);
FilterScriptFactory filterScriptFactory = mock(FilterScriptFactory.class);
FilterScript filterScript = mock(FilterScript.class);
when(filterScriptFactory.fromScript(Mockito.any())).thenReturn(filterScript);
when(filterScript.execute(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(portalResponse);
this.resourceService = mock(ResourceService.class);
final Resource resourceNotFound = mock(Resource.class);
when(resourceNotFound.exists()).thenReturn(false);
final Resource resource = mock(Resource.class);
when(resource.exists()).thenReturn(true);
when(this.resourceService.getResource(ResourceKey.from("demo:/services/test"))).thenReturn(resource);
this.contentService = mock(ContentService.class);
this.rendererDelegate = mock(RendererDelegate.class);
this.siteService = mock(SiteService.class);
this.handler = new MappingHandler(resourceService, controllerScriptFactory, filterScriptFactory, rendererDelegate, new ControllerMappingsResolver(siteService), new ContentResolver(contentService));
this.request.setMethod(HttpMethod.GET);
}
use of com.enonic.xp.portal.impl.rendering.RendererDelegate in project xp by enonic.
the class ComponentInstructionTest method newRendererFactory.
private RendererDelegate newRendererFactory(final String renderResult) {
RendererDelegate rendererDelegate = mock(RendererDelegate.class);
when(rendererDelegate.render(any(), any())).thenReturn(PortalResponse.create().body(renderResult).build());
return rendererDelegate;
}
Aggregations