use of com.enonic.xp.portal.controller.ControllerScriptFactory in project xp by enonic.
the class LayoutRendererTest method nullResponseComponentEditMode.
@Test
public void nullResponseComponentEditMode() {
final LayoutDescriptor layoutDescriptor = LayoutDescriptor.create().displayName("My layout component").config(Form.create().build()).key(DescriptorKey.from("module:myLayoutComponent")).regions(RegionDescriptors.create().add(RegionDescriptor.create().name("left").build()).add(RegionDescriptor.create().name("right").build()).build()).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 LayoutDescriptorService layoutDescriptorService = Mockito.mock(LayoutDescriptorService.class);
final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
renderer = new LayoutRenderer();
renderer.setLayoutDescriptorService(layoutDescriptorService);
renderer.setControllerScriptFactory(controllerScriptFactory);
when(layoutDescriptorService.getByKey(any())).thenReturn(layoutDescriptor);
when(controllerScriptFactory.fromDir(any())).thenReturn(controllerScript);
portalRequest.setMode(RenderMode.EDIT);
layoutComponent = LayoutComponent.create().descriptor("myapp:myLayoutComponent").descriptor(layoutDescriptor.getKey()).build();
// exercise
portalResponse = renderer.render(layoutComponent, portalRequest);
// verify
String expected = "<div data-portal-component-type=\"layout\"></div>";
assertEquals(expected, portalResponse.getAsString());
}
use of com.enonic.xp.portal.controller.ControllerScriptFactory in project xp by enonic.
the class WidgetHandlerTest method setup.
@BeforeEach
public final void setup() {
this.request = new PortalRequest();
final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
this.controllerScript = Mockito.mock(ControllerScript.class);
Mockito.when(controllerScriptFactory.fromDir(Mockito.any())).thenReturn(this.controllerScript);
final PortalResponse portalResponse = PortalResponse.create().build();
Mockito.when(this.controllerScript.execute(Mockito.any())).thenReturn(portalResponse);
this.contentService = Mockito.mock(ContentService.class);
this.widgetDescriptorService = Mockito.mock(WidgetDescriptorService.class);
this.handler = new WidgetHandler();
this.handler.setControllerScriptFactory(controllerScriptFactory);
this.handler.setWidgetDescriptorService(this.widgetDescriptorService);
HttpServletRequest rawRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(rawRequest.isUserInRole(Mockito.anyString())).thenReturn(Boolean.TRUE);
this.request.setRawRequest(rawRequest);
this.request.setMethod(HttpMethod.GET);
this.request.setContentPath(ContentPath.from("/site/somepath/content"));
this.request.setEndpointPath("/_/widgets/demo/mywidget");
this.request.setRawPath("/admin/tool/_/widgets/demo/mywidget");
}
use of com.enonic.xp.portal.controller.ControllerScriptFactory in project xp by enonic.
the class AdminToolHandlerTest method setup.
@BeforeEach
public final void setup() throws Exception {
this.adminToolDescriptorService = Mockito.mock(AdminToolDescriptorService.class);
ControllerScript controllerScript = Mockito.mock(ControllerScript.class);
this.portalResponse = PortalResponse.create().build();
Mockito.when(controllerScript.execute(Mockito.any(PortalRequest.class))).thenReturn(this.portalResponse);
final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
Mockito.when(controllerScriptFactory.fromDir(Mockito.any(ResourceKey.class))).thenReturn(controllerScript);
this.handler = new AdminToolHandler();
this.handler.setAdminToolDescriptorService(this.adminToolDescriptorService);
this.handler.setControllerScriptFactory(controllerScriptFactory);
this.rawRequest = Mockito.mock(HttpServletRequest.class);
Mockito.when(this.rawRequest.isUserInRole(Mockito.anyString())).thenReturn(true);
this.portalRequest = new PortalRequest();
this.portalRequest.setRawRequest(this.rawRequest);
this.portalRequest.setMode(RenderMode.ADMIN);
final DescriptorKey defaultDescriptorKey = AdminToolPortalHandler.DEFAULT_DESCRIPTOR_KEY;
this.portalRequest.setBaseUri(AdminToolPortalHandler.ADMIN_TOOL_PREFIX + defaultDescriptorKey.getApplicationKey() + "/" + defaultDescriptorKey.getName());
this.portalRequest.setApplicationKey(defaultDescriptorKey.getApplicationKey());
this.webResponse = WebResponse.create().build();
this.chain = Mockito.mock(WebHandlerChain.class);
}
use of com.enonic.xp.portal.controller.ControllerScriptFactory 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());
}
use of com.enonic.xp.portal.controller.ControllerScriptFactory in project xp by enonic.
the class LayoutRendererTest method htmlResponseComponentEditMode.
@Test
public void htmlResponseComponentEditMode() {
final LayoutDescriptor layoutDescriptor = LayoutDescriptor.create().displayName("My layout component").config(Form.create().build()).key(DescriptorKey.from("module:myLayoutComponent")).regions(RegionDescriptors.create().add(RegionDescriptor.create().name("left").build()).add(RegionDescriptor.create().name("right").build()).build()).build();
final ControllerScript controllerScript = new ControllerScript() {
@Override
public PortalResponse execute(final PortalRequest portalRequest) {
return PortalResponse.create().body("<div class=\"row\"><div data-portal-region=\"left\" class=\"col-left\"></div><div data-portal-region=\"right\" class=\"col-right\"></div></div>").contentType(MediaType.HTML_UTF_8).status(HttpStatus.OK).build();
}
@Override
public void onSocketEvent(final WebSocketEvent event) {
}
};
final LayoutDescriptorService layoutDescriptorService = Mockito.mock(LayoutDescriptorService.class);
final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
renderer = new LayoutRenderer();
renderer.setLayoutDescriptorService(layoutDescriptorService);
renderer.setControllerScriptFactory(controllerScriptFactory);
when(layoutDescriptorService.getByKey(any())).thenReturn(layoutDescriptor);
when(controllerScriptFactory.fromDir(any())).thenReturn(controllerScript);
portalRequest.setMode(RenderMode.EDIT);
layoutComponent = LayoutComponent.create().descriptor("myapp:myLayoutComponent").descriptor(layoutDescriptor.getKey()).build();
// exercise
portalResponse = renderer.render(layoutComponent, portalRequest);
// verify
String expected = "<div data-portal-component-type=\"layout\" class=\"row\"><div data-portal-region=\"left\" class=\"col-left\"></div><div data-portal-region=\"right\" class=\"col-right\"></div></div>";
assertEquals(expected, portalResponse.getAsString());
}
Aggregations