use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class AssetHandlerTest method testOptions.
@Test
public void testOptions() throws Exception {
addResource("demo:/assets/css/main.css");
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"));
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class ImageHandlerTest method imageWithOrientation.
@Test
void imageWithOrientation() throws Exception {
setupContent();
when(this.mediaInfoService.getImageOrientation(any(ByteSource.class))).thenReturn(ImageOrientation.LeftBottom);
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);
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class ImageHandlerTest method cacheHeader_fingerprint_missmatch.
@Test
void cacheHeader_fingerprint_missmatch() throws Exception {
mockCachableContent();
this.request.setEndpointPath("/_/image/123456:654321/scale-100-100/image-name.jpg.png");
final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
assertThat(res.getHeaders()).doesNotContainKey("Cache-Control");
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class ResponseSerializerTest method serializeHeadRequest.
@Test
public void serializeHeadRequest() throws Exception {
final WebRequest req = new WebRequest();
req.setMethod(HttpMethod.HEAD);
final WebResponse resp = WebResponse.create().status(HttpStatus.ACCEPTED).contentType(MediaType.PLAIN_TEXT_UTF_8).header("header-test", "header-value").cookie(new Cookie("cookie-name", "cookie-value")).body("String body").build();
final ResponseSerializer serializer = new ResponseSerializer(req, resp);
final HttpServletResponse httpResponse = mock(HttpServletResponse.class);
serializer.serialize(httpResponse);
verify(httpResponse).setHeader("header-test", "header-value");
verify(httpResponse).setStatus(202);
verify(httpResponse).setContentType("text/plain; charset=utf-8");
verify(httpResponse).setContentLength(11);
verify(httpResponse, times(0)).getOutputStream();
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class ResponseSerializerTest method serializeBodyByteSource.
@Test
public void serializeBodyByteSource() throws Exception {
final WebRequest req = new WebRequest();
req.setMethod(HttpMethod.GET);
final WebResponse resp = WebResponse.create().status(HttpStatus.ACCEPTED).contentType(MediaType.PLAIN_TEXT_UTF_8).header("header-test", "header-value").cookie(new Cookie("cookie-name", "cookie-value")).body(Resources.asByteSource(ResponseSerializerTest.class.getResource("body_file.txt"))).build();
final ResponseSerializer serializer = new ResponseSerializer(req, resp);
final HttpServletResponse httpResponse = mock(HttpServletResponse.class);
final ServletOutputStream servletOutputStream = mock(ServletOutputStream.class);
when(httpResponse.getOutputStream()).thenReturn(servletOutputStream);
serializer.serialize(httpResponse);
verify(httpResponse).setHeader("header-test", "header-value");
verify(httpResponse).setStatus(202);
verify(httpResponse).setContentType("text/plain; charset=utf-8");
verify(httpResponse, times(0)).setContentLength(anyInt());
verify(servletOutputStream).write(any(byte[].class), eq(0), eq(11));
}
Aggregations