Search in sources :

Example 46 with WebResponse

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

Example 47 with WebResponse

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

the class IdentityHandlerTest method testHandleWithVirtualHostEnabled.

@Test
public void testHandleWithVirtualHostEnabled() throws Exception {
    final HttpServletRequest rawRequest = this.request.getRawRequest();
    final VirtualHost virtualHost = Mockito.mock(VirtualHost.class);
    Mockito.when(virtualHost.getIdProviderKeys()).thenReturn(IdProviderKeys.from("otherEnabledIdProvider", "myidprovider"));
    VirtualHostHelper.setVirtualHost(rawRequest, initVirtualHost(rawRequest, virtualHost));
    final WebResponse portalResponse = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertEquals(HttpStatus.OK, portalResponse.getStatus());
    assertEquals(HttpStatus.OK, portalResponse.getStatus());
    assertEquals("/site/draft/_/idprovider/myidprovider", this.request.getContextPath());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebResponse(com.enonic.xp.web.WebResponse) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 48 with WebResponse

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

the class IdentityHandlerTest method testHandleWithEmptyVirtualHostIdProviderConfig.

@Test
public void testHandleWithEmptyVirtualHostIdProviderConfig() throws Exception {
    final HttpServletRequest rawRequest = this.request.getRawRequest();
    final VirtualHost virtualHost = Mockito.mock(VirtualHost.class);
    Mockito.when(virtualHost.getIdProviderKeys()).thenReturn(IdProviderKeys.empty());
    VirtualHostHelper.setVirtualHost(rawRequest, virtualHost);
    final WebResponse portalResponse = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertEquals(HttpStatus.OK, portalResponse.getStatus());
    assertEquals(HttpStatus.OK, portalResponse.getStatus());
    assertEquals("/site/draft/_/idprovider/myidprovider", this.request.getContextPath());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebResponse(com.enonic.xp.web.WebResponse) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 49 with WebResponse

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

the class ImageHandlerTest method cacheHeader_draft_branch.

@Test
void cacheHeader_draft_branch() throws Exception {
    mockCachableContent();
    this.request.setEndpointPath("/_/image/123456:bb6d2c0f3112f562ec454654b9aebe7ab47ba865/scale-100-100/image-name.jpg.png");
    this.request.setBranch(ContentConstants.BRANCH_DRAFT);
    final WebResponse resDraft = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertEquals("private, max-age=31536000, immutable", resDraft.getHeaders().get("Cache-Control"));
}
Also used : WebResponse(com.enonic.xp.web.WebResponse) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 50 with WebResponse

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

the class ImageHandlerTest method cacheHeader.

@Test
void cacheHeader() throws Exception {
    mockCachableContent();
    this.request.setEndpointPath("/_/image/123456:bb6d2c0f3112f562ec454654b9aebe7ab47ba865/scale-100-100/image-name.jpg.png");
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertEquals("public, max-age=31536000, immutable", res.getHeaders().get("Cache-Control"));
}
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