use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class StandardScriptEvaluatorTest method shouldOverrideScriptVariablesWithParameterVariables.
@Test
public void shouldOverrideScriptVariablesWithParameterVariables() throws Exception {
// Given
String varName = "testVar";
String paramValue = "param value";
String scriptValue = "script value";
Bindings scriptBindings = new SimpleBindings();
scriptBindings.put(varName, scriptValue);
ScriptObject script = getJavascript(scriptBindings, varName);
Bindings paramBindings = new SimpleBindings();
paramBindings.put(varName, paramValue);
// When
String result = testEvaluator.evaluateScript(script, paramBindings);
// Then
assertThat(result).isEqualTo(paramValue);
}
use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class StandardScriptEvaluatorTest method shouldExposeScriptVariables.
@Test
public void shouldExposeScriptVariables() throws Exception {
// Given
String varName = "scriptVar";
String value = "a script value";
Bindings bindings = new SimpleBindings();
bindings.put(varName, value);
ScriptObject script = getJavascript(bindings, varName);
// When
String result = testEvaluator.evaluateScript(script, null);
// Then
assertThat(result).isEqualTo(value);
}
use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class StandardScriptEvaluatorTest method shouldSupportJSONParsing.
@Test
public void shouldSupportJSONParsing() throws Exception {
ScriptObject script = getJavascript("var json = JSON.parse(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 StandardScriptEvaluatorTest method shouldPassBindingsByReference.
/**
* Ensure that binding scopes are passed by reference to the script engine so that any changes made by the script
* are reflected in the final state of the bindings passed in.
*/
@Test
public void shouldPassBindingsByReference() throws Exception {
// Given
String varName = "state";
Bindings scope = new SimpleBindings();
scope.put(varName, "initial");
String expected = "expected";
ScriptObject script = getJavascript(varName + " = '" + expected + "'");
// When
testEvaluator.evaluateScript(script, scope);
// Then
assertThat(scope.get(varName)).isEqualTo(expected);
}
use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class StandardScriptEvaluatorTest method shouldSupportGroovyScripts.
@Test
public void shouldSupportGroovyScripts() throws Exception {
// Given
String varName = "state";
String expected = "expected";
ScriptObject groovyScript = getGroovyScript(varName + " = \"" + expected + "\"");
Bindings scope = new SimpleBindings();
scope.put(varName, "initial");
// When
testEvaluator.evaluateScript(groovyScript, scope);
// Then
assertThat(scope.get(varName)).isEqualTo(expected);
}
Aggregations