Search in sources :

Example 86 with PortalRequest

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

Example 87 with PortalRequest

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Trace(com.enonic.xp.trace.Trace) ResourceService(com.enonic.xp.resource.ResourceService) ExceptionMapperImpl(com.enonic.xp.web.impl.exception.ExceptionMapperImpl) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) TraceManager(com.enonic.xp.trace.TraceManager) ExceptionRenderer(com.enonic.xp.web.exception.ExceptionRenderer) PortalRequest(com.enonic.xp.portal.PortalRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 88 with PortalRequest

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);
}
Also used : Bundle(org.osgi.framework.Bundle) ResourceService(com.enonic.xp.resource.ResourceService) PortalScriptServiceImpl(com.enonic.xp.portal.impl.script.PortalScriptServiceImpl) URL(java.net.URL) PortalRequest(com.enonic.xp.portal.PortalRequest) ResourceKey(com.enonic.xp.resource.ResourceKey) ScriptRuntimeFactoryImpl(com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) UrlResource(com.enonic.xp.resource.UrlResource) ScriptAsyncService(com.enonic.xp.script.impl.async.ScriptAsyncService) PostProcessorImpl(com.enonic.xp.portal.impl.postprocess.PostProcessorImpl) Application(com.enonic.xp.app.Application) BundleContext(org.osgi.framework.BundleContext) ApplicationService(com.enonic.xp.app.ApplicationService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 89 with PortalRequest

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

Example 90 with PortalRequest

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

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