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