use of javax.script.Bindings in project OpenAM by OpenRock.
the class OidcClaimsExtensionTest method testProfileScope.
@Test
public void testProfileScope() throws Exception {
// Given
Bindings variables = testBindings(asSet("profile"));
when(identity.getAttribute("givenname")).thenReturn(asSet("joe"));
when(identity.getAttribute("sn")).thenReturn(asSet("bloggs"));
when(identity.getAttribute("preferredtimezone")).thenReturn(asSet("Europe/London"));
when(identity.getAttribute("preferredlocale")).thenReturn(asSet("en"));
when(identity.getAttribute("cn")).thenReturn(asSet("Joe Bloggs"));
// When
UserInfoClaims result = scriptEvaluator.evaluateScript(script, variables);
// Then
assertThat(result.getValues()).containsOnly(entry("given_name", "joe"), entry("family_name", "bloggs"), entry("name", "Joe Bloggs"), entry("zoneinfo", "Europe/London"), entry("locale", "en"));
assertThat(result.getCompositeScopes()).hasSize(1);
ArrayList<String> hashProfile = (ArrayList<String>) result.getCompositeScopes().get("profile");
assertThat(hashProfile).contains("zoneinfo", "name", "locale", "family_name", "given_name");
assertThat(hashProfile).hasSize(5);
}
use of javax.script.Bindings 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.Bindings 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.Bindings 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.Bindings 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);
}
Aggregations