Search in sources :

Example 31 with WebResponse

use of com.enonic.xp.web.WebResponse in project xp by enonic.

the class AssetHandlerTest method testCacheHeader.

@Test
public void testCacheHeader() throws Exception {
    addResource("demo:/assets/css/main.css");
    this.request.setEndpointPath("/_/asset/demo:0000000000000001/css/main.css");
    final ResourceKey resourceKey = ResourceKey.from(ApplicationKey.from("demo"), "META-INF/MANIFEST.MF");
    when(this.resourceService.getResource(resourceKey)).thenReturn(MockResource.empty(resourceKey, 1));
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals("public, max-age=31536000, immutable", res.getHeaders().get("Cache-Control"));
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) ResourceKey(com.enonic.xp.resource.ResourceKey) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 32 with WebResponse

use of com.enonic.xp.web.WebResponse in project xp by enonic.

the class ComponentHandlerTest method testOptions.

@Test
public void testOptions() throws Exception {
    setupSite();
    setupContent();
    setupTemplates();
    final PortalResponse portalResponse = PortalResponse.create().status(HttpStatus.METHOD_NOT_ALLOWED).build();
    setRendererResult(portalResponse);
    Mockito.when(this.postProcessor.processResponseInstructions(Mockito.any(), Mockito.any())).thenReturn(portalResponse);
    this.request.setMethod(HttpMethod.OPTIONS);
    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("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 33 with WebResponse

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

Example 34 with WebResponse

use of com.enonic.xp.web.WebResponse in project xp by enonic.

the class ServiceHandlerTest method executeScript_invalidApplication.

@Test
public void executeScript_invalidApplication() throws Exception {
    this.request.setRawPath("/webapp/forbidden/_/service/demo/test");
    this.request.setEndpointPath("/_/service/demo/test");
    assertThrows(WebException.class, () -> {
        final WebResponse response = this.handler.handle(this.request, PortalResponse.create().build(), null);
        assertEquals(HttpStatus.OK, response.getStatus());
        Mockito.verify(this.controllerScript).execute(this.request);
        assertNotNull(this.request.getApplicationKey());
    });
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 35 with WebResponse

use of com.enonic.xp.web.WebResponse in project xp by enonic.

the class ServiceHandlerTest method executeScript_noContent.

@Test
public void executeScript_noContent() throws Exception {
    this.request.setEndpointPath("/_/service/demo/test");
    final WebResponse response = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertEquals(HttpStatus.OK, response.getStatus());
    Mockito.verify(this.controllerScript).execute(this.request);
    assertNotNull(this.request.getApplicationKey());
    assertNull(this.request.getSite());
    assertNull(this.request.getContent());
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) 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