@Test public void getContentShortcut() throws Exception { final PropertyTree rootDataSet = new PropertyTree(); rootDataSet.addReference("target", Reference.from("ref")); final Content content = Content.create() .id(ContentId.from("id")) .path(ContentPath.from("site/somepath/shortcut")) .owner(PrincipalKey.from("user:myStore:me")) .displayName("My Content") .modifier(PrincipalKey.from("user:system:admin")) .type(ContentTypeName.shortcut()) .data(rootDataSet) .build(); Mockito.when(this.contentService.getByPath(content.getPath().asAbsolute())).thenReturn(content); Mockito.when(this.portalUrlService.pageUrl(Mockito.any(PageUrlParams.class))) .thenReturn("/master/site/otherpath"); this.request.setContentPath(ContentPath.from("/site/somepath/shortcut")); final PortalResponse res = this.handler.handle(this.request); assertNotNull(res); assertEquals(HttpStatus.TEMPORARY_REDIRECT, res.getStatus()); assertEquals("/master/site/otherpath", res.getHeaders().get("Location")); }
@Test public void testOptions() throws Exception { this.request.setMethod(HttpMethod.OPTIONS); final PortalResponse res = this.handler.handle(this.request); assertNotNull(res); assertEquals(HttpStatus.OK, res.getStatus()); assertEquals("GET,POST,HEAD,OPTIONS,PUT,DELETE,TRACE", res.getHeaders().get("Allow")); }
@Test public void testDownload() throws Exception { this.request.setEndpointPath("/_/attachment/download/123456/logo.png"); final PortalResponse res = this.handler.handle(this.request); assertNotNull(res); assertEquals(HttpStatus.OK, res.getStatus()); assertEquals(MediaType.PNG, res.getContentType()); assertEquals("attachment; filename=logo.png", res.getHeaders().get("Content-Disposition")); assertSame(this.mediaBytes, res.getBody()); }
@Before public void setup() { this.portalRequest = new PortalRequest(); this.portalResponse = PortalResponse.create().build(); mockCurrentContextHttpRequest(); this.injection = new LiveEditInjection(); }
@Test public void getContentFound() throws Exception { setupContentAndSite(); setupTemplates(); final PortalResponse portalResponse = PortalResponse.create() .body("component rendered") .header("some-header", "some-value") .status(HttpStatus.OK) .build(); setRendererResult(portalResponse); this.request.setContentPath(ContentPath.from("/site/somepath/content")); final PortalResponse res = this.handler.handle(this.request); 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()); }