Search in sources :

Example 6 with WebSocketEvent

use of com.enonic.xp.web.websocket.WebSocketEvent 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)

Aggregations

WebSocketEvent (com.enonic.xp.web.websocket.WebSocketEvent)6 Test (org.junit.jupiter.api.Test)6 PortalRequest (com.enonic.xp.portal.PortalRequest)5 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)5 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)5 PortalResponseSerializer (com.enonic.xp.portal.impl.controller.PortalResponseSerializer)3 PartDescriptor (com.enonic.xp.region.PartDescriptor)3 PartDescriptorService (com.enonic.xp.region.PartDescriptorService)3 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)2 LayoutDescriptorService (com.enonic.xp.region.LayoutDescriptorService)2 Session (javax.websocket.Session)1