Search in sources :

Example 1 with BSFManager

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[]
}
Also used : List(java.util.List) BSFManager(org.apache.bsf.BSFManager) Test(org.junit.Test)

Example 2 with BSFManager

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[]
}
Also used : BSFEngine(org.apache.bsf.BSFEngine) BSFManager(org.apache.bsf.BSFManager) Test(org.junit.Test)

Example 3 with BSFManager

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();
}
Also used : BSFManager(org.apache.bsf.BSFManager)

Example 4 with 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[]
}
Also used : List(java.util.List) BSFManager(org.apache.bsf.BSFManager) Test(org.junit.Test)

Example 5 with BSFManager

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[]
}
Also used : BSFManager(org.apache.bsf.BSFManager) Test(org.junit.Test)

Aggregations

BSFManager (org.apache.bsf.BSFManager)21 BSFException (org.apache.bsf.BSFException)8 Test (org.junit.Test)8 BSFEngine (org.apache.bsf.BSFEngine)3 FileInputStream (java.io.FileInputStream)2 List (java.util.List)2 Vector (java.util.Vector)2 SampleResult (org.apache.jmeter.samplers.SampleResult)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 StringTokenizer (java.util.StringTokenizer)1 LogPreservingThreadFactory (org.opennms.core.concurrent.LogPreservingThreadFactory)1 Engine (org.opennms.netmgt.config.scriptd.Engine)1 StartScript (org.opennms.netmgt.config.scriptd.StartScript)1