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"));
}
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());
}
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());
}
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"));
}
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"));
}
Aggregations