use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class PageHandlerTest method renderCustomizedTemplate.
@Test
public void renderCustomizedTemplate() throws Exception {
setupCustomizedTemplateContentAndSite();
setupController();
final PortalResponse portalResponse = PortalResponse.create().body("content rendered").header("some-header", "some-value").status(HttpStatus.OK).build();
setRendererResult(portalResponse);
this.request.setContentPath(ContentPath.from("/id"));
this.request.setMode(RenderMode.EDIT);
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("content rendered", res.getBody());
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class PageHandlerTest method getContentShortcutWithParams.
@Test
public void getContentShortcutWithParams() throws Exception {
final PropertyTree rootDataSet = new PropertyTree();
rootDataSet.addReference("target", Reference.from("ref"));
final PropertySet shortcutParam1 = new PropertySet();
shortcutParam1.addString("name", "product");
shortcutParam1.addString("value", "123456");
final PropertySet shortcutParam2 = new PropertySet();
shortcutParam2.addString("name", "order");
shortcutParam2.addString("value", "abcdef");
rootDataSet.addSet("parameters", shortcutParam1);
rootDataSet.addSet("parameters", shortcutParam2);
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();
when(this.contentService.getByPath(content.getPath().asAbsolute())).thenReturn(content);
when(this.portalUrlService.pageUrl(any(PageUrlParams.class))).thenReturn("/master/site/otherpath?product=123456&order=abcdef");
this.request.setContentPath(ContentPath.from("/site/somepath/shortcut"));
final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
assertNotNull(res);
assertEquals(HttpStatus.TEMPORARY_REDIRECT, res.getStatus());
assertEquals("/master/site/otherpath?product=123456&order=abcdef", res.getHeaders().get("Location"));
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class PageHandlerTest method testOptions.
@Test
public void testOptions() throws Exception {
setupSite();
setupContent();
setupTemplates();
final PortalResponse portalResponse = PortalResponse.create().status(HttpStatus.METHOD_NOT_ALLOWED).build();
setRendererResult(portalResponse);
this.request.setContentPath(ContentPath.from("/site/somepath/content"));
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.web.WebResponse in project xp by enonic.
the class PageHandlerTest method getContentShortcut.
@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();
when(this.contentService.getByPath(content.getPath().asAbsolute())).thenReturn(content);
when(this.portalUrlService.pageUrl(any(PageUrlParams.class))).thenReturn("/master/site/otherpath");
this.request.setContentPath(ContentPath.from("/site/somepath/shortcut"));
final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
assertNotNull(res);
assertEquals(HttpStatus.TEMPORARY_REDIRECT, res.getStatus());
assertEquals("/master/site/otherpath", res.getHeaders().get("Location"));
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class PageHandlerTest method renderForNoPageDescriptor.
@Test
public void renderForNoPageDescriptor() throws Exception {
setupSite();
setupContent();
setupTemplates();
final PortalResponse portalResponse = PortalResponse.create().body("content rendered").header("some-header", "some-value").status(HttpStatus.OK).build();
setRendererResult(portalResponse);
this.request.setContentPath(ContentPath.from("/site/somepath/content"));
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("content rendered", res.getBody());
}
Aggregations