Search in sources :

Example 11 with WebResponse

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());
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebResponse(com.enonic.xp.web.WebResponse) Test(org.junit.jupiter.api.Test)

Example 12 with WebResponse

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"));
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PageUrlParams(com.enonic.xp.portal.url.PageUrlParams) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 13 with WebResponse

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"));
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebResponse(com.enonic.xp.web.WebResponse) Test(org.junit.jupiter.api.Test)

Example 14 with WebResponse

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"));
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PageUrlParams(com.enonic.xp.portal.url.PageUrlParams) Test(org.junit.jupiter.api.Test)

Example 15 with WebResponse

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());
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebResponse(com.enonic.xp.web.WebResponse) 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