INT-2177. Improved exception handling. Made ScriptExecutorFactory abstract
This commit is contained in:
committed by
Mark Fisher
parent
a0e7b3cd78
commit
eebb51f38a
@@ -13,6 +13,7 @@
|
||||
package org.springframework.integration.scripting.jsr223;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -20,7 +21,7 @@ import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.integration.scripting.ScriptExecutor;
|
||||
import org.springframework.integration.scripting.jsr223.DefaultScriptExecutor;
|
||||
import org.springframework.integration.scripting.ScriptingException;
|
||||
import org.springframework.scripting.support.ResourceScriptSource;
|
||||
import org.springframework.scripting.support.StaticScriptSource;
|
||||
|
||||
@@ -59,7 +60,8 @@ public class Jsr223ScriptExecutorTests {
|
||||
assertEquals("js",obj.toString());
|
||||
}
|
||||
|
||||
@Test public void testPython() {
|
||||
@Test
|
||||
public void testPython() {
|
||||
ScriptExecutor executor = ScriptExecutorFactory.getScriptExecutor("python");
|
||||
Object obj = executor.executeScript(new StaticScriptSource("x=2") );
|
||||
assertEquals(2,obj);
|
||||
@@ -67,4 +69,15 @@ public class Jsr223ScriptExecutorTests {
|
||||
obj = executor.executeScript(new StaticScriptSource("def foo(y):\n\tx=y\n\treturn y\nz=foo(2)") );
|
||||
assertEquals(2,obj);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidLanguageThrowsScriptingException() {
|
||||
try {
|
||||
ScriptExecutor executor = ScriptExecutorFactory.getScriptExecutor("foo");
|
||||
executor.executeScript(new StaticScriptSource("x=2"));
|
||||
fail("should throw Exception");
|
||||
} catch (ScriptingException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public class PythonScriptExecutorTests {
|
||||
public void init() {
|
||||
executor = new PythonScriptExecutor();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteral() {
|
||||
Object obj = executor.executeScript(new StaticScriptSource("3+4") );
|
||||
|
||||
Reference in New Issue
Block a user