Search in sources :

Example 11 with PartDescriptor

use of com.enonic.xp.region.PartDescriptor in project xp by enonic.

the class PartRendererTest method nullResponseComponentEditMode.

@Test
public void nullResponseComponentEditMode() {
    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).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\"></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 12 with PartDescriptor

use of com.enonic.xp.region.PartDescriptor in project xp by enonic.

the class PartRendererTest method htmlResponseComponentEditMode.

@Test
public void htmlResponseComponentEditMode() {
    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 PortalResponse.create().body("<h1 class=\"important\">My component</h1>").contentType(MediaType.HTML_UTF_8).status(HttpStatus.OK).build();
        }

        @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 = "<h1 data-portal-component-type=\"part\" class=\"important\">My component</h1>";
    assertEquals(expected, portalResponse.getAsString());
}
Also used : PartDescriptorService(com.enonic.xp.region.PartDescriptorService) 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 13 with PartDescriptor

use of com.enonic.xp.region.PartDescriptor in project xp by enonic.

the class DescriptorsTest method partDescriptor.

@Test
public void partDescriptor() {
    final Form partForm = Form.create().addFormItem(Input.create().name("width").label("width").inputType(InputTypeName.DOUBLE).build()).build();
    final PartDescriptor partDescriptor = PartDescriptor.create().displayName("News part").config(partForm).key(DescriptorKey.from("module:new-part")).build();
    final PartDescriptor copy = PartDescriptor.copyOf(partDescriptor).build();
    assertEquals("News part", partDescriptor.getDisplayName());
    assertEquals(partDescriptor.getComponentPath(), copy.getComponentPath());
}
Also used : Form(com.enonic.xp.form.Form) PartDescriptor(com.enonic.xp.region.PartDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

PartDescriptor (com.enonic.xp.region.PartDescriptor)13 Test (org.junit.jupiter.api.Test)7 Form (com.enonic.xp.form.Form)5 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)5 PartComponent (com.enonic.xp.region.PartComponent)4 PropertyTree (com.enonic.xp.data.PropertyTree)3 PortalRequest (com.enonic.xp.portal.PortalRequest)3 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)3 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)3 PartDescriptorService (com.enonic.xp.region.PartDescriptorService)3 WebSocketEvent (com.enonic.xp.web.websocket.WebSocketEvent)3 EditableContent (com.enonic.xp.content.EditableContent)2 Page (com.enonic.xp.page.Page)2 PageDescriptor (com.enonic.xp.page.PageDescriptor)2 PortalResponseSerializer (com.enonic.xp.portal.impl.controller.PortalResponseSerializer)2 LayoutComponent (com.enonic.xp.region.LayoutComponent)2 AbstractDescriptorServiceTest (com.enonic.xp.core.impl.content.page.AbstractDescriptorServiceTest)1 DescriptorKey (com.enonic.xp.page.DescriptorKey)1