use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class AttachmentHandlerTest method byteServingLongerThanFile.
@Test
void byteServingLongerThanFile() throws Exception {
this.request.setEndpointPath("/_/attachment/inline/123456/logo.png");
this.request.getHeaders().put("Range", "bytes=5-1000");
final PortalResponse res = (PortalResponse) this.handler.handle(this.request, PortalResponse.create().build(), null);
assertNotNull(res);
assertEquals(HttpStatus.PARTIAL_CONTENT, res.getStatus());
assertEquals(MediaType.PNG.withoutParameters(), res.getContentType());
assertEquals("bytes", res.getHeaders().get("accept-ranges"));
assertNull(res.getHeaders().get("Content-Disposition"));
final byte[] responseBody = ((ByteSource) res.getBody()).read();
final byte[] mediaBytesData = mediaBytes.read();
assertEquals(2, responseBody.length);
assertArrayEquals(new byte[] { mediaBytesData[5], mediaBytesData[6] }, responseBody);
}
use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class AttachmentHandlerTest method byteServingMultipleRanges.
@Test
void byteServingMultipleRanges() throws Exception {
this.request.setEndpointPath("/_/attachment/inline/123456/logo.png");
this.request.getHeaders().put("Range", "bytes=0-1,3-4,6-");
final PortalResponse res = (PortalResponse) this.handler.handle(this.request, PortalResponse.create().build(), null);
assertNotNull(res);
assertEquals(HttpStatus.PARTIAL_CONTENT, res.getStatus());
assertEquals(MediaType.parse("multipart/byteranges"), res.getContentType().withoutParameters());
assertEquals("bytes", res.getHeaders().get("accept-ranges"));
final byte[] responseBody = ((ByteSource) res.getBody()).read();
final String responseMultipartString = new String(responseBody, StandardCharsets.UTF_8);
String[] responseMultipartLines = responseMultipartString.split("\\r?\\n");
assertEquals("Content-Type: image/png", responseMultipartLines[2]);
assertEquals("Content-Range: bytes 0-1/7", responseMultipartLines[3]);
assertEquals("01", responseMultipartLines[5]);
assertEquals("Content-Type: image/png", responseMultipartLines[7]);
assertEquals("Content-Range: bytes 3-4/7", responseMultipartLines[8]);
assertEquals("34", responseMultipartLines[10]);
assertEquals("Content-Type: image/png", responseMultipartLines[12]);
assertEquals("Content-Range: bytes 6-6/7", responseMultipartLines[13]);
assertEquals("6", responseMultipartLines[15]);
}
use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class AttachmentHandlerTest method cacheHeader_draft_branch.
@Test
void cacheHeader_draft_branch() throws Exception {
this.request.setBranch(ContentConstants.BRANCH_DRAFT);
this.request.setEndpointPath("/_/attachment/inline/123456:98765/logo.png");
final PortalResponse res = (PortalResponse) this.handler.handle(this.request, PortalResponse.create().build(), null);
assertEquals("private, max-age=31536000, immutable", res.getHeaders().get("Cache-Control"));
}
use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class IdentityHandlerTest method testOptions.
@Test
public void testOptions() throws Exception {
final IdProviderControllerService idProviderControllerService = Mockito.mock(IdProviderControllerService.class);
final PortalResponse response = PortalResponse.create().status(HttpStatus.METHOD_NOT_ALLOWED).build();
Mockito.when(idProviderControllerService.execute(Mockito.any())).thenReturn(response);
this.handler.setIdProviderControllerService(idProviderControllerService);
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,POST,HEAD,OPTIONS,PUT,DELETE,TRACE", res.getHeaders().get("Allow"));
}
use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class ComponentHandlerTest method testComponentFound.
@Test
public void testComponentFound() throws Exception {
setupSite();
setupContent();
setupTemplates();
final PortalResponse portalResponse = PortalResponse.create().body("component rendered").header("some-header", "some-value").status(HttpStatus.OK).build();
Mockito.when(this.postProcessor.processResponseInstructions(Mockito.any(), Mockito.any())).thenReturn(portalResponse);
setRendererResult(portalResponse);
this.request.setEndpointPath("/_/component/main-region/0");
final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
assertNotNull(res);
assertEquals(HttpStatus.OK, res.getStatus());
assertEquals(MediaType.PLAIN_TEXT_UTF_8, res.getContentType());
assertEquals("some-value", res.getHeaders().get("some-header"));
assertEquals("component rendered", res.getBody());
}
Aggregations