use of groovy.lang.GroovyShell in project cuke4duke by cucumber.
the class GroovyLanguage method begin_scenario.
public void begin_scenario(Scenario scenario) throws IOException {
clearHooksAndStepDefinitions();
worldFactory = null;
GroovyShell shell = new GroovyShell(new Binding());
for (String groovyFile : groovyFiles) {
shell.evaluate(new File(groovyFile));
}
currentWorld = worldFactory == null ? new Object() : worldFactory.call();
}
use of groovy.lang.GroovyShell in project cas by apereo.
the class ReturnMappedAttributeReleasePolicy method getGroovyAttributeValue.
private static Object getGroovyAttributeValue(final String groovyScript, final Map<String, Object> resolvedAttributes) {
try {
final Binding binding = new Binding();
final GroovyShell shell = new GroovyShell(binding);
binding.setVariable("attributes", resolvedAttributes);
final Object res = shell.evaluate(groovyScript);
return res;
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
use of groovy.lang.GroovyShell in project cas by apereo.
the class GroovyRegisteredServiceUsernameProvider method getGroovyAttributeValue.
private static Object getGroovyAttributeValue(final Principal principal, final String script) {
try {
final Binding binding = new Binding();
final GroovyShell shell = new GroovyShell(binding);
binding.setVariable("attributes", principal.getAttributes());
binding.setVariable("id", principal.getId());
final Object res = shell.evaluate(script);
return res;
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
use of groovy.lang.GroovyShell in project groovy-core by groovy.
the class GroovyAssert method shouldFail.
/**
* Asserts that the given script fails when it is evaluated
*
* @param script the script expected to fail
* @return the caught exception
*/
public static Throwable shouldFail(String script) {
boolean failed = false;
Throwable th = null;
try {
GroovyShell shell = new GroovyShell();
shell.evaluate(script, genericScriptName());
} catch (GroovyRuntimeException gre) {
failed = true;
th = ScriptBytecodeAdapter.unwrap(gre);
} catch (Throwable e) {
failed = true;
th = e;
}
assertTrue("Script should have failed", failed);
return th;
}
use of groovy.lang.GroovyShell in project groovy-core by groovy.
the class GroovyAssert method shouldFail.
/**
* Asserts that the given script fails when it is evaluated
* and that a particular type of exception is thrown.
*
* @param clazz the class of the expected exception
* @param script the script that should fail
* @return the caught exception
*/
public static Throwable shouldFail(Class clazz, String script) {
Throwable th = null;
try {
GroovyShell shell = new GroovyShell();
shell.evaluate(script, genericScriptName());
} catch (GroovyRuntimeException gre) {
th = ScriptBytecodeAdapter.unwrap(gre);
} catch (Throwable e) {
th = e;
}
if (th == null) {
fail("Script should have failed with an exception of type " + clazz.getName());
} else if (!clazz.isInstance(th)) {
fail("Script should have failed with an exception of type " + clazz.getName() + ", instead got Exception " + th);
}
return th;
}
Aggregations