use of com.enonic.xp.region.ComponentService 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.region.ComponentService 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.region.ComponentService 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);
}
Aggregations