use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class AdminToolHandlerTest method test.
@Test
public void test() throws Exception {
this.mockDescriptor(DescriptorKey.from("app:tool"), true);
this.portalRequest.setBaseUri("/admin/tool/webapp/tool");
this.portalRequest.setRawPath("/admin/tool/webapp/tool/1");
WebResponse response = this.handler.doHandle(this.portalRequest, this.webResponse, this.chain);
assertEquals(this.portalResponse, response);
assertEquals("/admin/tool/webapp/tool", this.portalRequest.getContextPath());
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class WidgetHandlerTest method executeScript_validSite.
@Test
public void executeScript_validSite() throws Exception {
setupContentAndSite();
mockDescriptor(true);
this.request.setEndpointPath("/_/widgets/demo/test");
this.request.setMode(RenderMode.ADMIN);
final WebResponse response = this.handler.handle(this.request, WebResponse.create().build(), null);
assertEquals(HttpStatus.OK, response.getStatus());
Mockito.verify(this.controllerScript).execute(this.request);
assertNotNull(this.request.getApplicationKey());
assertEquals("/admin/tool/_/widgets/demo/test", this.request.getContextPath());
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class WidgetHandlerTest method executeScript_noContent.
@Test
public void executeScript_noContent() throws Exception {
mockDescriptor(true);
this.request.setEndpointPath("/_/widgets/demo/test");
this.request.setMode(RenderMode.ADMIN);
final WebResponse response = this.handler.handle(this.request, WebResponse.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());
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class BaseWebHandler method handle.
@Override
public WebResponse handle(final WebRequest webRequest, final WebResponse webResponse, final WebHandlerChain webHandlerChain) throws Exception {
if (canHandle(webRequest)) {
final HttpMethod method = webRequest.getMethod();
checkMethodAllowed(method);
final WebResponse response = doHandle(webRequest, webResponse, webHandlerChain);
if (HttpMethod.OPTIONS == method && response.getStatus() == HttpStatus.METHOD_NOT_ALLOWED) {
return handleDefaultOptions();
}
return response;
} else {
return webHandlerChain.handle(webRequest, webResponse);
}
}
use of com.enonic.xp.web.WebResponse in project xp by enonic.
the class MappingHandlerTest method executeFilter.
@Test
public void executeFilter() throws Exception {
final ResourceKey filter = ResourceKey.from("demo:/services/test");
final ControllerMappingDescriptor mapping = ControllerMappingDescriptor.create().filter(filter).pattern(".*/content").build();
setupContentAndSite(mapping);
this.request.setBaseUri("/site");
this.request.setContentPath(ContentPath.from("/site/somesite/content"));
final WebResponse response = this.handler.handle(this.request, PortalResponse.create().build(), null);
assertEquals(HttpStatus.OK, response.getStatus());
assertNotNull(this.request.getApplicationKey());
assertNotNull(this.request.getSite());
assertNotNull(this.request.getContent());
assertEquals("/site/draft/site", this.request.getContextPath());
}
Aggregations