Search in sources :

Example 41 with PortalRequest

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();
}
Also used : PortalRequest(com.enonic.xp.portal.PortalRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 42 with PortalRequest

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());
}
Also used : PortalResponseSerializer(com.enonic.xp.portal.impl.controller.PortalResponseSerializer) WebSocketEvent(com.enonic.xp.web.websocket.WebSocketEvent) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 43 with PortalRequest

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ApplicationKey(com.enonic.xp.app.ApplicationKey) MacroServiceImpl(com.enonic.xp.impl.macro.MacroServiceImpl) StyleDescriptorService(com.enonic.xp.style.StyleDescriptorService) ResourceService(com.enonic.xp.resource.ResourceService) ContentService(com.enonic.xp.content.ContentService) Application(com.enonic.xp.app.Application) PortalRequest(com.enonic.xp.portal.PortalRequest) ApplicationService(com.enonic.xp.app.ApplicationService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 44 with PortalRequest

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;
}
Also used : Content(com.enonic.xp.content.Content) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 45 with PortalRequest

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;
}
Also used : RenderMode(com.enonic.xp.portal.RenderMode) Matcher(java.util.regex.Matcher) PortalRequest(com.enonic.xp.portal.PortalRequest)

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