Search in sources :

Example 16 with WebResponse

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

the class ServiceHandlerTest method executeScript_validSite.

@Test
public void executeScript_validSite() throws Exception {
    setupContentAndSite();
    this.request.setEndpointPath("/_/service/demo/test");
    final WebResponse response = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertEquals(HttpStatus.OK, response.getStatus());
    Mockito.verify(this.controllerScript).execute(this.request);
    assertNotNull(this.request.getApplicationKey());
    assertNotNull(this.request.getSite());
    assertNotNull(this.request.getContent());
    assertEquals("/site/draft/site/somepath/content/_/service/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 17 with WebResponse

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

the class ServiceHandlerTest method executeScript_validApplication.

@Test
public void executeScript_validApplication() throws Exception {
    this.request.setRawPath("/webapp/demo/_/service/demo/test");
    this.request.setEndpointPath("/_/service/demo/test");
    final WebResponse response = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertEquals(HttpStatus.OK, response.getStatus());
    Mockito.verify(this.controllerScript).execute(this.request);
    assertNotNull(this.request.getApplicationKey());
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 18 with WebResponse

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

the class ImageHandlerTest method options.

@Test
void options() throws Exception {
    setupContent();
    this.request.setMethod(HttpMethod.OPTIONS);
    this.request.setBaseUri("/site");
    this.request.setEndpointPath("/_/image/123456/scale-100-100/image-name.jpg");
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals("GET,HEAD,OPTIONS", res.getHeaders().get("Allow"));
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 19 with WebResponse

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

the class ImageHandlerTest method svgzImage.

@Test
void svgzImage() throws Exception {
    setupContentSvgz();
    when(this.mediaInfoService.getImageOrientation(any(ByteSource.class))).thenReturn(ImageOrientation.LeftBottom);
    this.request.setEndpointPath("/_/image/123456/full/image-name.svgz");
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals(MediaType.SVG_UTF_8.withoutParameters(), res.getContentType());
    assertTrue(res.getBody() instanceof ByteSource);
    assertEquals("gzip", res.getHeaders().get("Content-Encoding"));
    assertEquals("default-src 'none'; base-uri 'none'; form-action 'none'; style-src 'self' 'unsafe-inline'", res.getHeaders().get("Content-Security-Policy"));
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) ByteSource(com.google.common.io.ByteSource) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 20 with WebResponse

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

the class ImageHandlerTest method gifImage.

@Test
void gifImage() throws Exception {
    setupContentGif();
    this.request.setEndpointPath("/_/image/123456/full/image-name.gif");
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals(MediaType.GIF, res.getContentType());
    assertTrue(res.getBody() instanceof ByteSource);
    assertNull(res.getHeaders().get("Content-Encoding"));
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) ByteSource(com.google.common.io.ByteSource) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) 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