Search in sources :

Example 16 with PortalRequest

use of com.enonic.xp.portal.PortalRequest in project xp by enonic.

the class PostProcessorImplTest method testPostProcessingInstructions.

private void testPostProcessingInstructions(final HttpMethod httpMethod) throws Exception {
    final String html = readResource("postProcessSource1.html");
    final PostProcessorImpl postProcessor = new PostProcessorImpl();
    postProcessor.addInstruction(new TestPostProcessInstruction());
    final PortalResponse.Builder portalResponseBuilder = PortalResponse.create().contentType(MediaType.HTML_UTF_8).body(html);
    final PortalRequest portalRequest = new PortalRequest();
    portalRequest.setMethod(httpMethod);
    final PortalResponse portalResponse = postProcessor.processResponse(portalRequest, portalResponseBuilder.build());
    final String outputHtml = portalResponse.getBody().toString();
    final String expectedResult = readResource("postProcessResult1.html");
    assertEqualsTrimmed(expectedResult, outputHtml);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 17 with PortalRequest

use of com.enonic.xp.portal.PortalRequest 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 18 with PortalRequest

use of com.enonic.xp.portal.PortalRequest 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 19 with PortalRequest

use of com.enonic.xp.portal.PortalRequest in project xp by enonic.

the class ProcessorChainResolverTest method before.

@BeforeEach
public void before() {
    portalRequest = new PortalRequest();
    siteService = Mockito.mock(SiteService.class);
    resolver = new ProcessorChainResolver();
    resolver.setSiteService(siteService);
}
Also used : SiteService(com.enonic.xp.site.SiteService) PortalRequest(com.enonic.xp.portal.PortalRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 20 with PortalRequest

use of com.enonic.xp.portal.PortalRequest in project xp by enonic.

the class AbstractViewFunctionTest method setup.

@BeforeEach
public final void setup() throws Exception {
    this.portalRequest = new PortalRequest();
    this.portalRequest.setBranch(Branch.from("draft"));
    this.portalRequest.setApplicationKey(ApplicationKey.from("myapplication"));
    this.portalRequest.setBaseUri("/site");
    this.portalRequest.setContentPath(ContentPath.from("context/path"));
    HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
    this.portalRequest.setRawRequest(httpServletRequest);
    this.service = new ViewFunctionServiceImpl();
    setupFunction();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PortalRequest(com.enonic.xp.portal.PortalRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

PortalRequest (com.enonic.xp.portal.PortalRequest)103 Test (org.junit.jupiter.api.Test)47 BeforeEach (org.junit.jupiter.api.BeforeEach)35 PortalResponse (com.enonic.xp.portal.PortalResponse)25 Site (com.enonic.xp.site.Site)19 Content (com.enonic.xp.content.Content)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ApplicationKey (com.enonic.xp.app.ApplicationKey)10 ContentPath (com.enonic.xp.content.ContentPath)10 ContentService (com.enonic.xp.content.ContentService)10 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)10 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)9 ResourceKey (com.enonic.xp.resource.ResourceKey)9 ResourceService (com.enonic.xp.resource.ResourceService)9 ContentId (com.enonic.xp.content.ContentId)7 Matcher (java.util.regex.Matcher)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)7 Assertions.fail (org.junit.jupiter.api.Assertions.fail)7 Mockito.when (org.mockito.Mockito.when)7