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());
}
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);
}
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");
}
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");
}
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();
}
Aggregations