Search in sources :

Example 1 with ExceptionMapperImpl

use of com.enonic.xp.web.impl.exception.ExceptionMapperImpl 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 2 with ExceptionMapperImpl

use of com.enonic.xp.web.impl.exception.ExceptionMapperImpl in project xp by enonic.

the class WebDispatcherServletTest method configure.

@Override
protected void configure() throws Exception {
    this.handler = new TestWebHandler();
    this.servlet = new WebDispatcherServlet(new WebDispatcherImpl());
    this.servlet.addWebHandler(this.handler);
    this.servlet.setExceptionMapper(new ExceptionMapperImpl());
    this.servlet.setExceptionRenderer((req, cause) -> WebResponse.create().status(HttpStatus.NOT_FOUND).build());
    this.servlet.setWebSocketContextFactory(Mockito.mock(WebSocketContextFactory.class));
    this.servlet.setResponseSerializationService(new ResponseSerializationServiceImpl());
    this.handler.response = WebResponse.create().status(HttpStatus.OK).build();
    addServlet(this.servlet, "/site/*");
}
Also used : WebSocketContextFactory(com.enonic.xp.web.websocket.WebSocketContextFactory) ResponseSerializationServiceImpl(com.enonic.xp.web.impl.serializer.ResponseSerializationServiceImpl) ExceptionMapperImpl(com.enonic.xp.web.impl.exception.ExceptionMapperImpl)

Aggregations

ExceptionMapperImpl (com.enonic.xp.web.impl.exception.ExceptionMapperImpl)2 PortalRequest (com.enonic.xp.portal.PortalRequest)1 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)1 ResourceService (com.enonic.xp.resource.ResourceService)1 Trace (com.enonic.xp.trace.Trace)1 TraceManager (com.enonic.xp.trace.TraceManager)1 ExceptionRenderer (com.enonic.xp.web.exception.ExceptionRenderer)1 WebHandlerChain (com.enonic.xp.web.handler.WebHandlerChain)1 ResponseSerializationServiceImpl (com.enonic.xp.web.impl.serializer.ResponseSerializationServiceImpl)1 WebSocketContextFactory (com.enonic.xp.web.websocket.WebSocketContextFactory)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1