Search in sources :

Example 6 with WebHandlerChain

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

the class FilterScriptImplTest method testNextFilter.

@Test
public void testNextFilter() throws Exception {
    WebHandlerChain webHandlerChain = Mockito.mock(WebHandlerChain.class);
    Mockito.when(webHandlerChain.handle(Mockito.any(), Mockito.any())).thenReturn(this.portalResponse);
    this.portalRequest.setMethod(HttpMethod.POST);
    execute("myapplication:/filter/callnext.js", webHandlerChain);
    assertEquals(HttpStatus.OK, this.portalResponse.getStatus());
}
Also used : WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) Test(org.junit.jupiter.api.Test)

Example 7 with WebHandlerChain

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

the class FilterScriptImplTest method testDuplicatedNextCall.

@Test
public void testDuplicatedNextCall() 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/duplicated_next_call.js", webHandlerChain);
        fail("Expected exception");
    } catch (ResourceProblemException e) {
        assertEquals("myapplication:/filter/duplicated_next_call.js", e.getResource().toString());
        assertEquals("Filter 'next' function was called multiple times", e.getMessage());
    }
}
Also used : ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) Test(org.junit.jupiter.api.Test)

Example 8 with WebHandlerChain

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

the class FilterScriptImplTest method testResourceException.

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

Example 9 with WebHandlerChain

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

the class FilterScriptImplTest method testExecErrorHandling.

@Test
public void testExecErrorHandling() throws Exception {
    WebHandlerChain webHandlerChain = Mockito.mock(WebHandlerChain.class);
    Mockito.when(webHandlerChain.handle(Mockito.any(), Mockito.any())).thenReturn(this.portalResponse);
    this.portalRequest.setMethod(HttpMethod.POST);
    final ResourceProblemException e = assertThrows(ResourceProblemException.class, () -> execute("myapplication:/filter/filtererror.js", webHandlerChain));
    assertEquals("myapplication:/filter/filtererror.js", e.getResource().toString());
    assertEquals(3, e.getLineNumber());
    assertNotNull(e.getMessage());
}
Also used : ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) Test(org.junit.jupiter.api.Test)

Example 10 with WebHandlerChain

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

the class MappingHandlerTest method testNoMatch_no_site.

@Test
public void testNoMatch_no_site() throws Exception {
    final WebHandlerChain chain = mock(WebHandlerChain.class);
    final PortalResponse response = PortalResponse.create().build();
    this.request.setBaseUri("/admin/site");
    this.request.setContentPath(ContentPath.from("/site/content"));
    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)

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