Search in sources :

Example 41 with WebResponse

use of com.enonic.xp.web.WebResponse in project xp by enonic.

the class AdminToolHandlerTest method test.

@Test
public void test() throws Exception {
    this.mockDescriptor(DescriptorKey.from("app:tool"), true);
    this.portalRequest.setBaseUri("/admin/tool/webapp/tool");
    this.portalRequest.setRawPath("/admin/tool/webapp/tool/1");
    WebResponse response = this.handler.doHandle(this.portalRequest, this.webResponse, this.chain);
    assertEquals(this.portalResponse, response);
    assertEquals("/admin/tool/webapp/tool", this.portalRequest.getContextPath());
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 42 with WebResponse

use of com.enonic.xp.web.WebResponse in project xp by enonic.

the class WidgetHandlerTest method executeScript_validSite.

@Test
public void executeScript_validSite() throws Exception {
    setupContentAndSite();
    mockDescriptor(true);
    this.request.setEndpointPath("/_/widgets/demo/test");
    this.request.setMode(RenderMode.ADMIN);
    final WebResponse response = this.handler.handle(this.request, WebResponse.create().build(), null);
    assertEquals(HttpStatus.OK, response.getStatus());
    Mockito.verify(this.controllerScript).execute(this.request);
    assertNotNull(this.request.getApplicationKey());
    assertEquals("/admin/tool/_/widgets/demo/test", this.request.getContextPath());
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 43 with WebResponse

use of com.enonic.xp.web.WebResponse in project xp by enonic.

the class WidgetHandlerTest method executeScript_noContent.

@Test
public void executeScript_noContent() throws Exception {
    mockDescriptor(true);
    this.request.setEndpointPath("/_/widgets/demo/test");
    this.request.setMode(RenderMode.ADMIN);
    final WebResponse response = this.handler.handle(this.request, WebResponse.create().build(), null);
    assertEquals(HttpStatus.OK, response.getStatus());
    Mockito.verify(this.controllerScript).execute(this.request);
    assertNotNull(this.request.getApplicationKey());
    assertNull(this.request.getSite());
    assertNull(this.request.getContent());
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 44 with WebResponse

use of com.enonic.xp.web.WebResponse in project xp by enonic.

the class BaseWebHandler method handle.

@Override
public WebResponse handle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
    if (canHandle(webRequest)) {
        final HttpMethod method = webRequest.getMethod();
        checkMethodAllowed(method);
        final WebResponse response = doHandle(webRequest, webResponse, webHandlerChain);
        if (HttpMethod.OPTIONS == method && response.getStatus() == HttpStatus.METHOD_NOT_ALLOWED) {
            return handleDefaultOptions();
        }
        return response;
    } else {
        return webHandlerChain.handle(webRequest, webResponse);
    }
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) HttpMethod(com.enonic.xp.web.HttpMethod)

Example 45 with WebResponse

use of com.enonic.xp.web.WebResponse in project xp by enonic.

the class MappingHandlerTest method executeFilter.

@Test
public void executeFilter() throws Exception {
    final ResourceKey filter = ResourceKey.from("demo:/services/test");
    final ControllerMappingDescriptor mapping = ControllerMappingDescriptor.create().filter(filter).pattern(".*/content").build();
    setupContentAndSite(mapping);
    this.request.setBaseUri("/site");
    this.request.setContentPath(ContentPath.from("/site/somesite/content"));
    final WebResponse response = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertEquals(HttpStatus.OK, response.getStatus());
    assertNotNull(this.request.getApplicationKey());
    assertNotNull(this.request.getSite());
    assertNotNull(this.request.getContent());
    assertEquals("/site/draft/site", this.request.getContextPath());
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Aggregations

WebResponse (com.enonic.xp.web.WebResponse)63 Test (org.junit.jupiter.api.Test)53 BaseHandlerTest (com.enonic.xp.web.handler.BaseHandlerTest)32 PortalResponse (com.enonic.xp.portal.PortalResponse)11 WebRequest (com.enonic.xp.web.WebRequest)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 ByteSource (com.google.common.io.ByteSource)6 Cookie (javax.servlet.http.Cookie)6 ResourceKey (com.enonic.xp.resource.ResourceKey)5 WebException (com.enonic.xp.web.WebException)5 ServletOutputStream (javax.servlet.ServletOutputStream)5 PortalRequest (com.enonic.xp.portal.PortalRequest)4 Content (com.enonic.xp.content.Content)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 PageUrlParams (com.enonic.xp.portal.url.PageUrlParams)2 MockResource (com.enonic.xp.resource.MockResource)2 Resource (com.enonic.xp.resource.Resource)2 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)2 Trace (com.enonic.xp.trace.Trace)2 VirtualHost (com.enonic.xp.web.vhost.VirtualHost)2