use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ContributionInjectionTest method setup.
@BeforeEach
public void setup() {
this.injection = new ContributionInjection();
this.request = new PortalRequest();
this.responseBuilder = PortalResponse.create();
}
use of com.enonic.xp.portal.PortalRequest 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.PortalRequest in project xp by enonic.
the class AbstractPortalUrlServiceImplTest method setup.
@BeforeEach
public void setup() {
final ApplicationKey applicationKey = ApplicationKey.from("myapplication");
final Application application = Mockito.mock(Application.class);
when(application.getKey()).thenReturn(applicationKey);
req = mock(HttpServletRequest.class);
this.portalRequest = new PortalRequest();
this.portalRequest.setBranch(Branch.from("draft"));
this.portalRequest.setApplicationKey(applicationKey);
this.portalRequest.setBaseUri("/site");
this.portalRequest.setContentPath(ContentPath.from("context/path"));
this.portalRequest.setRawRequest(req);
this.service = new PortalUrlServiceImpl();
this.service.setMacroService(new MacroServiceImpl());
this.contentService = Mockito.mock(ContentService.class);
this.service.setContentService(this.contentService);
this.styleDescriptorService = Mockito.mock(StyleDescriptorService.class);
when(this.styleDescriptorService.getByApplications(Mockito.any())).thenReturn(StyleDescriptors.empty());
this.service.setStyleDescriptorService(this.styleDescriptorService);
this.applicationService = Mockito.mock(ApplicationService.class);
when(this.applicationService.getInstalledApplication(applicationKey)).thenReturn(application);
this.resourceService = Mockito.mock(ResourceService.class);
this.service.setResourceService(this.resourceService);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ScriptTestSupport method createPortalRequest.
protected PortalRequest createPortalRequest() {
final PortalRequest request = new PortalRequest();
request.setMode(RenderMode.LIVE);
request.setBranch(Branch.from("draft"));
request.setApplicationKey(this.appKey);
request.setBaseUri("/site");
final Content content = Content.create().id(ContentId.from("123")).path("some/path").build();
request.setContent(content);
return request;
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class AdminSiteHandler method createPortalRequest.
@Override
protected PortalRequest createPortalRequest(final WebRequest webRequest, final WebResponse webResponse) {
final Matcher matcher = BASE_URI_PATTERN.matcher(webRequest.getRawPath());
if (!matcher.find()) {
throw WebException.notFound("Mode needs to be specified");
}
final String baseUri = matcher.group(0);
final RenderMode mode = RenderMode.from(matcher.group(1));
final String baseSubPath = webRequest.getRawPath().substring(baseUri.length() + 1);
final PortalRequest portalRequest = doCreatePortalRequest(webRequest, baseUri, baseSubPath);
portalRequest.setMode(mode);
return portalRequest;
}
Aggregations