Search in sources :

Example 1 with WebHandlerChain

use of com.enonic.xp.web.handler.WebHandlerChain in project xp by enonic.

the class FilterScriptImplTest method testNoFilterFunction.

@Test
public void testNoFilterFunction() throws Exception {
    WebHandlerChain webHandlerChain = Mockito.mock(WebHandlerChain.class);
    Mockito.when(webHandlerChain.handle(Mockito.any(), Mockito.any())).thenReturn(this.portalResponse);
    this.portalRequest.setMethod(HttpMethod.POST);
    try {
        execute("myapplication:/filter/nofilter.js", webHandlerChain);
        fail("Expected exception");
    } catch (WebException e) {
        assertEquals("Missing exported function 'filter' in filter script: myapplication:/filter/nofilter.js", e.getMessage());
    }
}
Also used : WebException(com.enonic.xp.web.WebException) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) Test(org.junit.jupiter.api.Test)

Example 2 with WebHandlerChain

use of com.enonic.xp.web.handler.WebHandlerChain in project xp by enonic.

the class MappingHandlerTest method testNoMatch_no_site_based.

@Test
public void testNoMatch_no_site_based() throws Exception {
    final WebHandlerChain chain = mock(WebHandlerChain.class);
    final PortalResponse response = PortalResponse.create().build();
    this.request.setContentPath(ContentPath.from("/site/content"));
    this.request.setBaseUri("/something");
    this.handler.handle(this.request, response, chain);
    verify(chain).handle(this.request, response);
    verifyNoInteractions(rendererDelegate);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) Test(org.junit.jupiter.api.Test)

Example 3 with WebHandlerChain

use of com.enonic.xp.web.handler.WebHandlerChain in project xp by enonic.

the class MappingHandlerTest method testNoMatch_endpointPath.

@Test
public void testNoMatch_endpointPath() throws Exception {
    this.request.setEndpointPath("something");
    final WebHandlerChain chain = mock(WebHandlerChain.class);
    final PortalResponse response = PortalResponse.create().build();
    this.handler.handle(this.request, response, chain);
    verify(chain).handle(this.request, response);
    verifyNoInteractions(rendererDelegate);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) Test(org.junit.jupiter.api.Test)

Example 4 with WebHandlerChain

use of com.enonic.xp.web.handler.WebHandlerChain in project xp by enonic.

the class MappingHandlerTest method executeNothing.

@Test
public void executeNothing() throws Exception {
    final ResourceKey controller = ResourceKey.from("demo:/services/test");
    final ControllerMappingDescriptor mapping = ControllerMappingDescriptor.create().controller(controller).pattern("/nomatch").build();
    setupContentAndSite(mapping);
    final WebHandlerChain chain = mock(WebHandlerChain.class);
    final PortalResponse response = PortalResponse.create().build();
    this.request.setBaseUri("/site");
    this.request.setContentPath(ContentPath.from("/site/somesite/content"));
    this.handler.handle(this.request, response, chain);
    verify(chain).handle(this.request, response);
    verifyNoInteractions(rendererDelegate);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 5 with WebHandlerChain

use of com.enonic.xp.web.handler.WebHandlerChain in project xp by enonic.

the class FilterScriptImplTest method testHandleException.

@Test
public void testHandleException() throws Exception {
    WebHandlerChain webHandlerChain = Mockito.mock(WebHandlerChain.class);
    Mockito.when(webHandlerChain.handle(Mockito.any(), Mockito.any())).thenThrow(Exception.class);
    final ResourceProblemException exception = Assertions.assertThrows(ResourceProblemException.class, () -> execute("myapplication:/filter/callnext.js", webHandlerChain));
    assertEquals("Error executing filter script: myapplication:/filter/callnext.js", exception.getMessage());
    Mockito.verify(webHandlerChain, Mockito.times(1)).handle(Mockito.any(), Mockito.any());
}
Also used : ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) Test(org.junit.jupiter.api.Test)

Aggregations

WebHandlerChain (com.enonic.xp.web.handler.WebHandlerChain)10 Test (org.junit.jupiter.api.Test)10 PortalResponse (com.enonic.xp.portal.PortalResponse)4 ResourceProblemException (com.enonic.xp.resource.ResourceProblemException)3 ResourceKey (com.enonic.xp.resource.ResourceKey)1 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)1 WebException (com.enonic.xp.web.WebException)1