Search in sources :

Example 51 with WebResponse

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

the class ImageHandlerTest method imageWithFilter.

@Test
void imageWithFilter() throws Exception {
    setupContent();
    this.request.setEndpointPath("/_/image/123456/scale-100-100/image-name.jpg");
    this.request.getParams().put("filter", "sepia()");
    this.request.getParams().put("quality", "75");
    this.request.getParams().put("background", "0x0");
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals(MediaType.PNG, res.getContentType());
    assertTrue(res.getBody() instanceof ByteSource);
}
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 52 with WebResponse

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

the class AttachmentHandlerTest method options.

@Test
void options() throws Exception {
    this.request.setEndpointPath("/_/attachment/download/123456/logo.png");
    this.request.setMethod(HttpMethod.OPTIONS);
    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 53 with WebResponse

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

the class AssetHandlerTest method testCacheHeader_FingerprintDoesntMatch.

@Test
public void testCacheHeader_FingerprintDoesntMatch() throws Exception {
    addResource("demo:/assets/css/main.css");
    this.request.setEndpointPath("/_/asset/demo:123/css/main.css");
    final ResourceKey resourceKey = ResourceKey.from(ApplicationKey.from("demo"), "META-INF/MANIFEST.MF");
    when(this.resourceService.getResource(resourceKey)).thenReturn(MockResource.empty(resourceKey, 1));
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertNull(res.getHeaders().get("Cache-Control"));
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) ResourceKey(com.enonic.xp.resource.ResourceKey) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 54 with WebResponse

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

the class AssetHandlerTest method testNoCacheHeader.

@Test
public void testNoCacheHeader() throws Exception {
    addResource("demo:/assets/css/main.css");
    this.request.setMode(RenderMode.EDIT);
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertNull(res.getHeaders().get("Cache-Control"));
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 55 with WebResponse

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

the class AssetHandlerTest method testRootResourceFound.

@Test
public void testRootResourceFound() throws Exception {
    final Resource resource = addResource("demo:/assets/css/main.css");
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals(MediaType.CSS_UTF_8.withoutParameters(), res.getContentType());
    assertSame(resource, res.getBody());
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) MockResource(com.enonic.xp.resource.MockResource) Resource(com.enonic.xp.resource.Resource) 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