use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class AbstractSandboxTests method shouldNotBeAllowedToAccessBlackListedMember.
@Test
public void shouldNotBeAllowedToAccessBlackListedMember() throws Exception {
// Given
Allowed allowed = new Allowed();
Bindings bindings = new SimpleBindings();
bindings.put("allowed", allowed);
// When
try {
eval(bindings, "allowed.forbiddenFruit.setDirty()");
fail("Sandbox failed to protect access to black-listed member");
} catch (ScriptException ex) {
// Then
assertThat(allowed.fruit.dirty).isFalse();
}
}
use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class StandardScriptEvaluatorTest method shouldSupportJSONParsingInGroovy.
@Test
public void shouldSupportJSONParsingInGroovy() throws Exception {
ScriptObject script = getGroovyScript("import groovy.json.JsonSlurper", "def slurper = new JsonSlurper()", "def json = slurper.parseText(x)", "json.a");
Bindings scope = new SimpleBindings();
scope.put("x", "{\"a\" : 12}");
Object result = testEvaluator.evaluateScript(script, scope);
assertThat(result).isEqualTo(12);
}
use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class ThreadPoolScriptEvaluatorTest method shouldDelegateToConfiguredScriptEvaluator.
@Test
public void shouldDelegateToConfiguredScriptEvaluator() throws Exception {
testEvaluator = new ThreadPoolScriptEvaluator(scriptEngineManager, Executors.newSingleThreadExecutor(), mockEvaluator);
ScriptObject testScript = getGroovyScript("x + 1");
Bindings bindings = new SimpleBindings();
bindings.put("x", 3);
int expectedResult = 42;
given(mockEvaluator.evaluateScript(testScript, bindings)).willReturn(expectedResult);
// When
Number result = testEvaluator.evaluateScript(testScript, bindings);
// Then
verify(mockEvaluator).evaluateScript(testScript, bindings);
assertThat(result.intValue()).isEqualTo(expectedResult);
}
use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class StandardScriptEvaluatorTest method shouldOverrideGlobalVariablesWithScriptVariables.
@Test
public void shouldOverrideGlobalVariablesWithScriptVariables() throws Exception {
// Given
String varName = "testVar";
String globalValue = "global value";
String scriptValue = "script value";
testEvaluator.bindVariableInGlobalScope(varName, globalValue);
Bindings bindings = new SimpleBindings();
bindings.put(varName, scriptValue);
ScriptObject script = getJavascript(bindings, varName);
// When
String result = testEvaluator.evaluateScript(script, null);
// Then
assertThat(result).isEqualTo(scriptValue);
}
use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class StandardScriptEvaluatorTest method shouldExposeParameterVariables.
@Test
public void shouldExposeParameterVariables() throws Exception {
// Given
String varName = "paramVar";
String value = "a parameter value";
Bindings bindings = new SimpleBindings();
bindings.put(varName, value);
ScriptObject script = getJavascript(varName);
// When
String result = testEvaluator.evaluateScript(script, bindings);
// Then
assertThat(result).isEqualTo(value);
}
Aggregations