use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ContentResolverTest method resolve_in_live_mode.
@Test
void resolve_in_live_mode() {
final Content content = newContent();
final Site site = newSite();
final PortalRequest request = new PortalRequest();
request.setContentPath(ContentPath.from("/mysite/landing-page"));
when(this.contentService.getByPath(ContentPath.from("/mysite/landing-page"))).thenReturn(content);
when(this.contentService.findNearestSiteByPath(ContentPath.from("/mysite/landing-page"))).thenReturn(site);
final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
assertSame(content, result.getContent());
assertSame(site, result.getNearestSite());
assertEquals("/landing-page", result.getSiteRelativePath());
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class WebAppHandlerTest method setup.
@BeforeEach
public void setup() {
this.resourceService = Mockito.mock(ResourceService.class);
this.controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
this.exceptionRenderer = Mockito.mock(ExceptionRenderer.class);
this.handler = new WebAppHandler();
this.handler.setResourceService(this.resourceService);
this.handler.setControllerScriptFactory(this.controllerScriptFactory);
this.handler.setExceptionMapper(new ExceptionMapperImpl());
this.handler.setExceptionRenderer(this.exceptionRenderer);
this.request = new PortalRequest();
this.request.setRawRequest(Mockito.mock(HttpServletRequest.class));
this.chain = Mockito.mock(WebHandlerChain.class);
Mockito.when(this.resourceService.getResource(Mockito.any())).thenReturn(MockResource.missing(ResourceKey.from("myapp:/unknown.txt")));
Mockito.when(this.exceptionRenderer.render(Mockito.any(), Mockito.any())).thenReturn(WebResponse.create().status(HttpStatus.INTERNAL_SERVER_ERROR).build());
final TraceManager manager = Mockito.mock(TraceManager.class);
final Trace trace = Mockito.mock(Trace.class);
Mockito.when(manager.newTrace(Mockito.any(), Mockito.any())).thenReturn(trace);
Tracer.setManager(manager);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class AbstractErrorHandlerTest method setup.
@BeforeEach
public void setup() throws Exception {
this.portalRequest = new PortalRequest();
this.portalRequest.setMethod(HttpMethod.GET);
this.portalResponse = PortalResponse.create().build();
final BundleContext bundleContext = Mockito.mock(BundleContext.class);
final Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(bundle.getBundleContext()).thenReturn(bundleContext);
final Application application = Mockito.mock(Application.class);
Mockito.when(application.getBundle()).thenReturn(bundle);
Mockito.when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
Mockito.when(application.isStarted()).thenReturn(true);
Mockito.when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
final ApplicationService applicationService = Mockito.mock(ApplicationService.class);
Mockito.when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(application);
this.resourceService = Mockito.mock(ResourceService.class);
Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
final URL resourceUrl = AbstractErrorHandlerTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
return new UrlResource(resourceKey, resourceUrl);
});
final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, this.resourceService, scriptAsyncService);
final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
scriptService.initialize();
this.factory = new ErrorHandlerScriptFactoryImpl();
this.factory.setScriptService(scriptService);
this.postProcessor = new PostProcessorImpl();
final HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
ServletRequestHolder.setRequest(req);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class PortalErrorTest method testGetRequest.
@Test
public void testGetRequest() throws Exception {
final PortalRequest request = new PortalRequest();
final PortalError error = PortalError.create().request(request).status(HttpStatus.INTERNAL_SERVER_ERROR).build();
assertSame(request, error.getRequest());
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class PortalErrorTest method testGetStatus.
@Test
public void testGetStatus() throws Exception {
final PortalRequest request = new PortalRequest();
final PortalError error = PortalError.create().request(request).status(HttpStatus.INTERNAL_SERVER_ERROR).build();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, error.getStatus());
}
Aggregations