Search in sources :

Example 71 with PortalRequest

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

the class PostProcessorImplTest method processResponse_skip_non_html.

@Test
public void processResponse_skip_non_html() throws Exception {
    final PostProcessorImpl postProcessor = new PostProcessorImpl();
    final PortalResponse portalResponse = PortalResponse.create().contentType(MediaType.JAVASCRIPT_UTF_8).body("").build();
    final PortalRequest portalRequest = new PortalRequest();
    portalRequest.setMethod(HttpMethod.GET);
    final PortalResponse result = postProcessor.processResponse(portalRequest, portalResponse);
    assertSame(portalResponse, result);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 72 with PortalRequest

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

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

the class MacroInstructionTest method testInstructionMacroMultiValue.

@Test
public void testInstructionMacroMultiValue() throws Exception {
    MacroKey key = MacroKey.from("myapp:mymacro");
    MacroDescriptor macroDescriptor = MacroDescriptor.create().key(key).build();
    when(macroDescriptorService.getByKey(key)).thenReturn(macroDescriptor);
    MacroProcessor macro = (ctx) -> PortalResponse.create().body(ctx.getName() + ": param1=" + ctx.getParameter("param1").get(0) + ", body=" + ctx.getBody()).build();
    when(macroProcessorFactory.fromScript(any())).thenReturn(macro);
    String outputHtml = macroInstruction.evaluate(portalRequest, "MACRO _name=\"mymacro\" param1=\"value1\" param1=\"value2\" param2=\"other\" _body=\"body\"").getAsString();
    assertEquals("mymacro: param1=value1, body=body", outputHtml);
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) MacroProcessorFactory(com.enonic.xp.portal.macro.MacroProcessorFactory) SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) MacroProcessor(com.enonic.xp.portal.macro.MacroProcessor) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) ContentId(com.enonic.xp.content.ContentId) PortalRequest(com.enonic.xp.portal.PortalRequest) PortalResponse(com.enonic.xp.portal.PortalResponse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PropertyTree(com.enonic.xp.data.PropertyTree) ContentPath(com.enonic.xp.content.ContentPath) SiteConfig(com.enonic.xp.site.SiteConfig) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) Mockito.when(org.mockito.Mockito.when) ApplicationKey(com.enonic.xp.app.ApplicationKey) RenderException(com.enonic.xp.portal.impl.rendering.RenderException) Test(org.junit.jupiter.api.Test) Form(com.enonic.xp.form.Form) MacroDescriptors(com.enonic.xp.macro.MacroDescriptors) Mockito(org.mockito.Mockito) MacroDescriptorService(com.enonic.xp.macro.MacroDescriptorService) InputTypeName(com.enonic.xp.inputtype.InputTypeName) Site(com.enonic.xp.site.Site) PrincipalKey(com.enonic.xp.security.PrincipalKey) SiteConfigs(com.enonic.xp.site.SiteConfigs) Input(com.enonic.xp.form.Input) MacroKey(com.enonic.xp.macro.MacroKey) MacroKey(com.enonic.xp.macro.MacroKey) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) MacroProcessor(com.enonic.xp.portal.macro.MacroProcessor) Test(org.junit.jupiter.api.Test)

Example 74 with PortalRequest

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

the class PartRendererTest method htmlResponseComponentEditModeNoMethodToHandleReq.

@Test
public void htmlResponseComponentEditModeNoMethodToHandleReq() {
    final PartDescriptor partDescriptor = PartDescriptor.create().displayName("My part component").config(Form.create().build()).key(DescriptorKey.from("module:myPartComponent")).build();
    final ControllerScript controllerScript = new ControllerScript() {

        @Override
        public PortalResponse execute(final PortalRequest portalRequest) {
            return new PortalResponseSerializer(null, HttpStatus.METHOD_NOT_ALLOWED).serialize();
        }

        @Override
        public void onSocketEvent(final WebSocketEvent event) {
        }
    };
    final PartDescriptorService partDescriptorService = Mockito.mock(PartDescriptorService.class);
    final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
    renderer = new PartRenderer();
    renderer.setPartDescriptorService(partDescriptorService);
    renderer.setControllerScriptFactory(controllerScriptFactory);
    when(partDescriptorService.getByKey(any())).thenReturn(partDescriptor);
    when(controllerScriptFactory.fromDir(any())).thenReturn(controllerScript);
    portalRequest.setMode(RenderMode.EDIT);
    partComponent = PartComponent.create().descriptor("myapp:myPartComponent").descriptor(partDescriptor.getKey()).build();
    // exercise
    portalResponse = renderer.render(partComponent, portalRequest);
    // verify
    String expected = "<div data-portal-component-type=\"part\" data-portal-placeholder=\"true\" data-portal-placeholder-error=\"true\"><span class=\"data-portal-placeholder-error\">No method provided to handle request</span></div>";
    assertEquals(expected, portalResponse.getAsString());
}
Also used : PartDescriptorService(com.enonic.xp.region.PartDescriptorService) PortalResponseSerializer(com.enonic.xp.portal.impl.controller.PortalResponseSerializer) WebSocketEvent(com.enonic.xp.web.websocket.WebSocketEvent) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) PartDescriptor(com.enonic.xp.region.PartDescriptor) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 75 with PortalRequest

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

the class PartRendererTest method before.

@BeforeEach
public void before() {
    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"));
    this.portalResponse = PortalResponse.create().build();
    this.portalRequest.setMode(RenderMode.EDIT);
}
Also used : 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