Search in sources :

Example 1 with ComponentService

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);
}
Also used : Site(com.enonic.xp.site.Site) Content(com.enonic.xp.content.Content) ComponentService(com.enonic.xp.region.ComponentService) RendererDelegate(com.enonic.xp.portal.impl.rendering.RendererDelegate) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 2 with ComponentService

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);
}
Also used : Site(com.enonic.xp.site.Site) PageTemplate(com.enonic.xp.page.PageTemplate) Content(com.enonic.xp.content.Content) DescriptorKey(com.enonic.xp.page.DescriptorKey) ComponentService(com.enonic.xp.region.ComponentService) Component(com.enonic.xp.region.Component) PartComponent(com.enonic.xp.region.PartComponent) RendererDelegate(com.enonic.xp.portal.impl.rendering.RendererDelegate) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 3 with ComponentService

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);
}
Also used : Site(com.enonic.xp.site.Site) PageTemplate(com.enonic.xp.page.PageTemplate) Content(com.enonic.xp.content.Content) DescriptorKey(com.enonic.xp.page.DescriptorKey) ComponentService(com.enonic.xp.region.ComponentService) Component(com.enonic.xp.region.Component) PartComponent(com.enonic.xp.region.PartComponent) RendererDelegate(com.enonic.xp.portal.impl.rendering.RendererDelegate) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Aggregations

Content (com.enonic.xp.content.Content)3 PortalRequest (com.enonic.xp.portal.PortalRequest)3 RendererDelegate (com.enonic.xp.portal.impl.rendering.RendererDelegate)3 ComponentService (com.enonic.xp.region.ComponentService)3 Site (com.enonic.xp.site.Site)3 Test (org.junit.jupiter.api.Test)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)2 PageTemplate (com.enonic.xp.page.PageTemplate)2 Component (com.enonic.xp.region.Component)2 PartComponent (com.enonic.xp.region.PartComponent)2