use of com.enonic.xp.resource.ResourceProblemException in project xp by enonic.
the class SendMailScriptTest method testFailMissingTo.
@Test
public void testFailMissingTo() throws Exception {
final MailService mailService = message -> {
throw new RuntimeException("Error sending mail");
};
addService(MailService.class, mailService);
try {
runFunction("/test/send-test.js", "sendWithoutRequiredTo");
fail("Expected exception");
} catch (ResourceProblemException e) {
assertEquals("Parameter 'to' is required", e.getMessage());
}
assertNull(this.actualMessage);
}
use of com.enonic.xp.resource.ResourceProblemException in project xp by enonic.
the class SendMailScriptTest method testFailMissingFrom.
@Test
public void testFailMissingFrom() throws Exception {
final MailService mailService = message -> {
throw new RuntimeException("Error sending mail");
};
addService(MailService.class, mailService);
try {
runFunction("/test/send-test.js", "sendWithoutRequiredFrom");
fail("Expected exception");
} catch (ResourceProblemException e) {
assertEquals("Parameter 'from' is required", e.getMessage());
}
assertNull(this.actualMessage);
}
use of com.enonic.xp.resource.ResourceProblemException in project xp by enonic.
the class ScriptRuntimeTest method testCompileError.
@Test
public void testCompileError() {
final ResourceKey script = ResourceKey.from("myapplication:/error/error-test.js");
try {
runTestScript(script);
fail("Should throw ResourceProblemException");
} catch (final ResourceProblemException e) {
assertEquals(1, e.getLineNumber());
assertEquals(script, e.getResource());
}
}
use of com.enonic.xp.resource.ResourceProblemException in project xp by enonic.
the class ScriptRuntimeTest method testRuntimeError.
@Test
public void testRuntimeError() {
final ResourceKey script = ResourceKey.from("myapplication:/error/error-in-export-test.js");
final ScriptExports exports = runTestScript(script);
assertNotNull(exports);
try {
exports.executeMethod("hello");
fail("Should throw ResourceProblemException");
} catch (final ResourceProblemException e) {
assertEquals(1, e.getLineNumber());
assertEquals(ResourceKey.from("myapplication:/error/error-test.js"), e.getResource());
}
}
use of com.enonic.xp.resource.ResourceProblemException in project xp by enonic.
the class FilterNextFunctionWrapper method apply.
@Override
public Object apply(final Object scriptRequestObject) {
if (functionWasCalled) {
throw scriptError("Filter 'next' function was called multiple times", null);
}
functionWasCalled = true;
ScriptValue scriptRequestParam = scriptService.toScriptValue(this.script, scriptRequestObject);
try {
final PortalRequest portalRequest = new PortalRequestSerializer(request, scriptRequestParam).serialize();
final WebResponse newResponse = webHandlerChain.handle(portalRequest, response);
final PortalResponseMapper response = new PortalResponseMapper((PortalResponse) newResponse);
return scriptService.toNativeObject(this.script, response);
} catch (ResourceProblemException | WebException e) {
throw e;
} catch (Exception e) {
throw scriptError("Error executing filter script: " + script, e);
}
}
Aggregations