Search in sources :

Example 1 with RendererDelegate

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);
}
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 RendererDelegate

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);
}
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 RendererDelegate

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);
}
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 4 with RendererDelegate

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);
}
Also used : FilterScriptFactory(com.enonic.xp.portal.filter.FilterScriptFactory) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) FilterScript(com.enonic.xp.portal.filter.FilterScript) ResourceService(com.enonic.xp.resource.ResourceService) Resource(com.enonic.xp.resource.Resource) ContentService(com.enonic.xp.content.ContentService) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) ContentResolver(com.enonic.xp.portal.impl.ContentResolver) PortalResponse(com.enonic.xp.portal.PortalResponse) SiteService(com.enonic.xp.site.SiteService) RendererDelegate(com.enonic.xp.portal.impl.rendering.RendererDelegate) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with RendererDelegate

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;
}
Also used : RendererDelegate(com.enonic.xp.portal.impl.rendering.RendererDelegate)

Aggregations

RendererDelegate (com.enonic.xp.portal.impl.rendering.RendererDelegate)5 PortalRequest (com.enonic.xp.portal.PortalRequest)4 Content (com.enonic.xp.content.Content)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 ContentService (com.enonic.xp.content.ContentService)1 PortalResponse (com.enonic.xp.portal.PortalResponse)1 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)1 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)1 FilterScript (com.enonic.xp.portal.filter.FilterScript)1 FilterScriptFactory (com.enonic.xp.portal.filter.FilterScriptFactory)1 ContentResolver (com.enonic.xp.portal.impl.ContentResolver)1 Resource (com.enonic.xp.resource.Resource)1 ResourceService (com.enonic.xp.resource.ResourceService)1 SiteService (com.enonic.xp.site.SiteService)1