Search in sources :

Example 6 with ResourceProblemException

use of com.enonic.xp.resource.ResourceProblemException in project xp by enonic.

the class ScriptValueTest method testFunction_error.

@Test
public void testFunction_error() throws Exception {
    final ScriptValue obj = evalValue("testFunctionError");
    try {
        obj.call("a").getValue();
        fail("Should throw exception");
    } catch (final Exception e) {
        assertTrue(e instanceof ResourceProblemException);
    }
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) ResourceProblemException(com.enonic.xp.resource.ResourceProblemException) Test(org.junit.jupiter.api.Test)

Example 7 with ResourceProblemException

use of com.enonic.xp.resource.ResourceProblemException in project xp by enonic.

the class ErrorPageRichBuilder method buildSourceInfo.

private void buildSourceInfo(final HtmlBuilder html) {
    if (this.cause == null || !(this.cause.getCause() instanceof ResourceProblemException)) {
        return;
    }
    final ResourceProblemException problem = ((ResourceProblemException) this.cause.getCause()).getInnerError();
    if (problem.getResource() != null) {
        html.open("h2");
        html.escapedText("In " + problem.getResource() + " at line " + problem.getLineNumber());
        html.close();
    }
    html.open("div").attribute("id", "source-code");
    buildLineInfo(html, findSourceLines(problem));
    html.close();
    final List<LineInfo> callStack = getCallStack(problem);
    if (!callStack.isEmpty()) {
        html.open("h2");
        html.text("Here is the script calling stack:");
        html.close();
        html.open("div");
        buildLineInfo(html, callStack);
        html.close();
    }
}
Also used : ResourceProblemException(com.enonic.xp.resource.ResourceProblemException)

Example 8 with ResourceProblemException

use of com.enonic.xp.resource.ResourceProblemException 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)

Example 9 with ResourceProblemException

use of com.enonic.xp.resource.ResourceProblemException 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 10 with ResourceProblemException

use of com.enonic.xp.resource.ResourceProblemException 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)

Aggregations

ResourceProblemException (com.enonic.xp.resource.ResourceProblemException)10 Test (org.junit.jupiter.api.Test)8 WebHandlerChain (com.enonic.xp.web.handler.WebHandlerChain)3 MailMessage (com.enonic.xp.mail.MailMessage)2 MailService (com.enonic.xp.mail.MailService)2 ResourceKey (com.enonic.xp.resource.ResourceKey)2 ScriptValue (com.enonic.xp.script.ScriptValue)2 ScriptTestSupport (com.enonic.xp.testing.ScriptTestSupport)2 ByteSource (com.google.common.io.ByteSource)2 CharStreams (com.google.common.io.CharStreams)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Stream (java.util.stream.Stream)2 BodyPart (javax.mail.BodyPart)2 Message (javax.mail.Message)2 Session (javax.mail.Session)2 AddressException (javax.mail.internet.AddressException)2 InternetAddress (javax.mail.internet.InternetAddress)2 MimeMessage (javax.mail.internet.MimeMessage)2