Search in sources :

Example 91 with PortalRequest

use of com.enonic.xp.portal.PortalRequest in project xp by enonic.

the class PortalErrorTest method testGetMessage.

@Test
public void testGetMessage() throws Exception {
    final PortalRequest request = new PortalRequest();
    final PortalError error = PortalError.create().request(request).status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    final PortalError error2 = PortalError.create().request(request).status(HttpStatus.INTERNAL_SERVER_ERROR).message("Some error").build();
    assertEquals("", error.getMessage());
    assertEquals("Some error", error2.getMessage());
}
Also used : PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 92 with PortalRequest

use of com.enonic.xp.portal.PortalRequest in project xp by enonic.

the class MappingHandlerTest method setup.

@BeforeEach
public final void setup() throws Exception {
    this.request = new PortalRequest();
    final ControllerScriptFactory controllerScriptFactory = mock(ControllerScriptFactory.class);
    ControllerScript controllerScript = mock(ControllerScript.class);
    when(controllerScriptFactory.fromDir(Mockito.any())).thenReturn(controllerScript);
    final PortalResponse portalResponse = PortalResponse.create().build();
    when(controllerScript.execute(Mockito.any())).thenReturn(portalResponse);
    FilterScriptFactory filterScriptFactory = mock(FilterScriptFactory.class);
    FilterScript filterScript = mock(FilterScript.class);
    when(filterScriptFactory.fromScript(Mockito.any())).thenReturn(filterScript);
    when(filterScript.execute(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(portalResponse);
    this.resourceService = mock(ResourceService.class);
    final Resource resourceNotFound = mock(Resource.class);
    when(resourceNotFound.exists()).thenReturn(false);
    final Resource resource = mock(Resource.class);
    when(resource.exists()).thenReturn(true);
    when(this.resourceService.getResource(ResourceKey.from("demo:/services/test"))).thenReturn(resource);
    this.contentService = mock(ContentService.class);
    this.rendererDelegate = mock(RendererDelegate.class);
    this.siteService = mock(SiteService.class);
    this.handler = new MappingHandler(resourceService, controllerScriptFactory, filterScriptFactory, rendererDelegate, new ControllerMappingsResolver(siteService), new ContentResolver(contentService));
    this.request.setMethod(HttpMethod.GET);
}
Also used : FilterScriptFactory(com.enonic.xp.portal.filter.FilterScriptFactory) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) FilterScript(com.enonic.xp.portal.filter.FilterScript) ResourceService(com.enonic.xp.resource.ResourceService) Resource(com.enonic.xp.resource.Resource) ContentService(com.enonic.xp.content.ContentService) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) ContentResolver(com.enonic.xp.portal.impl.ContentResolver) PortalResponse(com.enonic.xp.portal.PortalResponse) SiteService(com.enonic.xp.site.SiteService) RendererDelegate(com.enonic.xp.portal.impl.rendering.RendererDelegate) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 93 with PortalRequest

use of com.enonic.xp.portal.PortalRequest in project xp by enonic.

the class RenderBaseHandlerTest method setupRenderBaseHandlerTest.

@BeforeEach
void setupRenderBaseHandlerTest() {
    this.request = new PortalRequest();
    this.contentService = mock(ContentService.class);
    this.pageTemplateService = mock(PageTemplateService.class);
    this.pageDescriptorService = mock(PageDescriptorService.class);
    this.applicationService = mock(ApplicationService.class);
    this.portalUrlService = mock(PortalUrlService.class);
    this.rendererDelegate = mock(RendererDelegate.class);
    this.postProcessor = mock(PostProcessor.class);
    when(rendererDelegate.render(any(), same(request))).thenReturn(PortalResponse.create().body("Ok").build());
    this.rawRequest = mock(HttpServletRequest.class);
    when(this.rawRequest.isUserInRole(anyString())).thenReturn(Boolean.TRUE);
    this.request.setRawRequest(this.rawRequest);
    this.request.setBaseUri("/site");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) ContentService(com.enonic.xp.content.ContentService) PageTemplateService(com.enonic.xp.page.PageTemplateService) RendererDelegate(com.enonic.xp.portal.impl.rendering.RendererDelegate) PortalRequest(com.enonic.xp.portal.PortalRequest) ApplicationService(com.enonic.xp.app.ApplicationService) PortalUrlService(com.enonic.xp.portal.url.PortalUrlService) PostProcessor(com.enonic.xp.portal.postprocess.PostProcessor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 94 with PortalRequest

use of com.enonic.xp.portal.PortalRequest in project xp by enonic.

the class ServiceHandlerTest method setup.

@BeforeEach
public final void setup() throws Exception {
    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.resourceService = Mockito.mock(ResourceService.class);
    final Resource resourceNotFound = Mockito.mock(Resource.class);
    Mockito.when(resourceNotFound.exists()).thenReturn(false);
    final Resource resource = Mockito.mock(Resource.class);
    Mockito.when(resource.exists()).thenReturn(true);
    Mockito.when(this.resourceService.getResource(ResourceKey.from("demo:/services/test"))).thenReturn(resourceNotFound);
    this.serviceDescriptorService = Mockito.mock(ServiceDescriptorService.class);
    final DescriptorKey serviceDescriptorKey = DescriptorKey.from("demo:test");
    final ServiceDescriptor serviceDescriptor = ServiceDescriptor.create().key(serviceDescriptorKey).build();
    Mockito.when(this.serviceDescriptorService.getByKey(serviceDescriptorKey)).thenReturn(serviceDescriptor);
    this.contentService = Mockito.mock(ContentService.class);
    this.handler = new ServiceHandler();
    this.handler.setControllerScriptFactory(controllerScriptFactory);
    this.handler.setContentService(this.contentService);
    this.handler.setResourceService(this.resourceService);
    this.handler.setServiceDescriptorService(this.serviceDescriptorService);
    this.request.setMethod(HttpMethod.GET);
    this.request.setContentPath(ContentPath.from("/site/somepath/content"));
    this.request.setEndpointPath("/_/service/demo/myservice");
    this.request.setRawPath("/site/draft/site/somepath/content/_/service/demo/myservice");
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) ServiceDescriptor(com.enonic.xp.service.ServiceDescriptor) ResourceService(com.enonic.xp.resource.ResourceService) Resource(com.enonic.xp.resource.Resource) DescriptorKey(com.enonic.xp.page.DescriptorKey) ContentService(com.enonic.xp.content.ContentService) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) ServiceDescriptorService(com.enonic.xp.service.ServiceDescriptorService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 95 with PortalRequest

use of com.enonic.xp.portal.PortalRequest in project xp by enonic.

the class MacroContextMapperTest method setup.

@BeforeEach
public void setup() {
    PortalRequest portalRequest = new PortalRequest();
    portalRequest.setMethod(HttpMethod.GET);
    portalRequest.setScheme("http");
    portalRequest.setHost("localhost");
    portalRequest.setPort(80);
    portalRequest.setPath("/site/live/master/a/b");
    portalRequest.setRawPath("/site/live/master/a/b");
    portalRequest.setContextPath("/site/live/master/a");
    portalRequest.setUrl("http://localhost/site/live/master/a/b?param1=value1");
    portalRequest.setRemoteAddress("127.0.0.1");
    portalRequest.getParams().put("param1", "value1");
    portalRequest.getParams().put("param2", "value2");
    portalRequest.getParams().put("param3", "value3-A");
    portalRequest.getParams().put("param3", "value3-B");
    portalRequest.getHeaders().put("header1", "value1");
    portalRequest.getHeaders().put("header2", "value2");
    portalRequest.getHeaders().put("header3", "value3");
    portalRequest.setApplicationKey(ApplicationKey.from("myapplication"));
    portalRequest.setContent(ContentFixtures.newContent());
    portalRequest.setSite(ContentFixtures.newSite());
    portalRequest.setPageDescriptor(ContentFixtures.newPageDescriptor());
    this.macroContext = MacroContext.create().name("macroName").body("body").param("firstParam", "firstParamValue").param("firstParam", "firstParamSecondValue").param("secondParam", "secondParamValue").request(portalRequest).document("<h1>document</h1>").build();
}
Also used : PortalRequest(com.enonic.xp.portal.PortalRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

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