Search in sources :

Example 6 with BSFEngine

use of org.apache.bsf.BSFEngine in project groovy-core by groovy.

the class BSFTest method testCall.

public void testCall() throws Exception {
    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[] {});
    assertEquals("olleh", result);
}
Also used : BSFEngine(org.apache.bsf.BSFEngine)

Example 7 with BSFEngine

use of org.apache.bsf.BSFEngine in project groovy by apache.

the class CacheBSFTest method testVersion.

public void testVersion() throws Exception {
    //System.out.println("BSFManager.getVersion() = " + BSFManager.getVersion());
    BSFEngine bsfEngine = manager.loadScriptingEngine("groovy");
    assertEquals(CACHING_ENGINE, bsfEngine.getClass());
}
Also used : BSFEngine(org.apache.bsf.BSFEngine)

Example 8 with BSFEngine

use of org.apache.bsf.BSFEngine in project jmeter by apache.

the class BSFTestElement method processFileOrScript.

protected void processFileOrScript(BSFManager mgr) throws BSFException {
    BSFEngine bsfEngine = mgr.loadScriptingEngine(getScriptLanguage());
    final String scriptFile = getFilename();
    if (scriptFile.length() == 0) {
        bsfEngine.exec("[script]", 0, 0, getScript());
    } else {
        // we have a file, read and process it
        try {
            String script = FileUtils.readFileToString(new File(scriptFile), Charset.defaultCharset());
            bsfEngine.exec(scriptFile, 0, 0, script);
        } catch (IOException e) {
            if (log.isWarnEnabled()) {
                log.warn("Exception executing script. {}", e.getLocalizedMessage());
            }
            throw new BSFException(BSFException.REASON_IO_ERROR, "Problem reading script file", e);
        }
    }
}
Also used : BSFEngine(org.apache.bsf.BSFEngine) BSFException(org.apache.bsf.BSFException) IOException(java.io.IOException) File(java.io.File)

Example 9 with BSFEngine

use of org.apache.bsf.BSFEngine in project jmeter by apache.

the class BSFTestElement method evalFileOrScript.

protected Object evalFileOrScript(BSFManager mgr) throws BSFException {
    BSFEngine bsfEngine = mgr.loadScriptingEngine(getScriptLanguage());
    final String scriptFile = getFilename();
    if (scriptFile.length() == 0) {
        return bsfEngine.eval("[script]", 0, 0, getScript());
    } else {
        // we have a file, read and process it
        try {
            String script = FileUtils.readFileToString(new File(scriptFile), Charset.defaultCharset());
            return bsfEngine.eval(scriptFile, 0, 0, script);
        } catch (IOException e) {
            if (log.isWarnEnabled()) {
                log.warn("Exception evaluating script. {}", e.getLocalizedMessage());
            }
            throw new BSFException(BSFException.REASON_IO_ERROR, "Problem reading script file", e);
        }
    }
}
Also used : BSFEngine(org.apache.bsf.BSFEngine) BSFException(org.apache.bsf.BSFException) IOException(java.io.IOException) File(java.io.File)

Aggregations

BSFEngine (org.apache.bsf.BSFEngine)9 BSFException (org.apache.bsf.BSFException)3 BSFManager (org.apache.bsf.BSFManager)3 File (java.io.File)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 SampleResult (org.apache.jmeter.samplers.SampleResult)1