use of org.apache.bsf.BSFManager in project groovy by apache.
the class BSFSpecTest method testSimpleIntegration.
@Test
public void testSimpleIntegration() throws BSFException {
// tag::bsf_simple[]
String myScript = "println('Hello World')\n return [1, 2, 3]";
BSFManager manager = new BSFManager();
List answer = (List) manager.eval("groovy", "myScript.groovy", 0, 0, myScript);
assertEquals(3, answer.size());
// end::bsf_simple[]
}
use of org.apache.bsf.BSFManager in project groovy by apache.
the class BSFSpecTest method testAccess.
@Test
public void testAccess() throws BSFException {
// tag::bsf_access[]
BSFManager manager = new BSFManager();
BSFEngine bsfEngine = manager.loadScriptingEngine("groovy");
manager.declareBean("myvar", "hello", String.class);
Object myvar = manager.lookupBean("myvar");
String result = (String) bsfEngine.call(myvar, "reverse", new Object[0]);
assertEquals("olleh", result);
// end::bsf_access[]
}
use of org.apache.bsf.BSFManager in project groovy by apache.
the class CacheBSFTest method setUp.
protected void setUp() throws Exception {
// override standard engine with caching one
BSFManager.registerScriptingEngine("groovy", CACHING_ENGINE.getName(), new String[] { "groovy", "gy" });
manager = new BSFManager();
}
use of org.apache.bsf.BSFManager in project groovy-core by groovy.
the class BSFSpecTest method testSimpleIntegration.
@Test
public void testSimpleIntegration() throws BSFException {
// tag::bsf_simple[]
String myScript = "println('Hello World')\n return [1, 2, 3]";
BSFManager manager = new BSFManager();
List answer = (List) manager.eval("groovy", "myScript.groovy", 0, 0, myScript);
assertEquals(3, answer.size());
// end::bsf_simple[]
}
use of org.apache.bsf.BSFManager in project groovy-core by groovy.
the class BSFSpecTest method testVariablePassing.
@Test
public void testVariablePassing() throws BSFException {
// tag::bsf_variable_passing[]
BSFManager manager = new BSFManager();
manager.declareBean("xyz", 4, Integer.class);
Object answer = manager.eval("groovy", "test.groovy", 0, 0, "xyz + 1");
assertEquals(5, answer);
// end::bsf_variable_passing[]
}
Aggregations