Package javax.script

Examples of javax.script.ScriptEngine


    }

    protected ScriptEngine getScriptEngine() throws ScriptException {
        final String lang = getScriptLanguage();

        ScriptEngine scriptEngine = getInstance().getEngineByName(lang);
        if (scriptEngine == null) {
            throw new ScriptException("Cannot find engine named: '"+lang+"', ensure you set language field in JSR223 Test Element:"+getName());
        }

        return scriptEngine;
View Full Code Here


            result.setSamplerData(getScript());
        }
        result.setDataType(SampleResult.TEXT);
        result.sampleStart();
        try {
            ScriptEngine scriptEngine = getScriptEngine();
            Bindings bindings = scriptEngine.createBindings();
            bindings.put("SampleResult",result);
            Object ret = processFileOrScript(scriptEngine, bindings);
            if (ret != null && (result.getResponseData() == null || result.getResponseData()==SampleResult.EMPTY_BA)){
                result.setResponseData(ret.toString(), null);
            }
View Full Code Here

    /** {@inheritDoc} */
    @Override
    public long delay() {
        long delay = 0;
        try {
            ScriptEngine scriptEngine = getScriptEngine();
            Object o = processFileOrScript(scriptEngine, null);
            if (o == null) {
                log.warn("Script did not return a value");
                return 0;
            }
View Full Code Here

    private static final long serialVersionUID = 232L;

    @Override
    public void process() {
        try {
            ScriptEngine scriptEngine = getScriptEngine();
            processFileOrScript(scriptEngine, null);
        } catch (ScriptException e) {
            log.error("Problem in JSR223 script ", e);
        } catch (IOException e) {
            log.error("Problem in JSR223 script ", e);
View Full Code Here

                                          final String language,
                                          final String scriptPath,
                                          final Reader reader) {
        ScriptEngineManager mgr = new ScriptEngineManager();

        ScriptEngine jsEngine = mgr.getEngineByName(language);

        jsEngine.put("text", text);
        jsEngine.put("value", value);
        jsEngine.put("transaction", myAccountSplit.getTransaction());
        jsEngine.put("myAccountSplit", myAccountSplit);
        jsEngine.put("file", myAccountSplit.getWritableGnucashFile());
        FixedPointNumber ustValue = ((FixedPointNumber) value.clone())
                .divideBy(new FixedPointNumber("-1,19")).multiply(
                        new FixedPointNumber("0,19")); // TODO: get tax-% from
        // tax-config
        FixedPointNumber nettoValue = ((FixedPointNumber) value.clone())
                .negate().subtract(ustValue);
        jsEngine.put("USt", ustValue);
        jsEngine.put("Netto", nettoValue);
        jsEngine.put("Helper", new ScriptHelper());
        jsEngine.getContext().setAttribute(ScriptEngine.FILENAME, scriptPath,
                ScriptContext.GLOBAL_SCOPE);

        try {
            LOG.info("importing transaction using script: " + scriptPath);
            jsEngine.eval(reader);
        } catch (Exception ex) {
            LOG.log(Level.SEVERE, "Error executing script number " + scriptnum
                    + " from " + scriptPath, ex);
            JOptionPane.showMessageDialog(null,
                    "Error executing user Import-Script #" + scriptnum
View Full Code Here

        }
    }

    @Test
    public void testAssertExists_javascript() {
        ScriptEngine engine = getScriptEngine();
        testWorks(engine, "var a = 1; assertExists('a');", "assertExists should succeed for a defined variable.");
        testThrowsAssertion(engine, "assertExists('foo')", "assertExists should fail for an undefined variable.");
        testWorks(engine, "function func() { return 42 }; assertExists('func');",
            "assertExists should succeed for a defined function.");
    }
View Full Code Here

            "assertExists should succeed for a defined function.");
    }

    @Test
    public void testAssertExists_python() {
        ScriptEngine engine = getScriptEngine();
        testWorks(engine, "a = 1\n" + "assertExists('a')", "assertExists should succeed for a defined variable.");
        testThrowsAssertion(engine, "assertExists('foo')", "assertExists should fail for an undefined variable.");
        testWorks(engine, "def func():\n" + " return 42\n" + "assertExists('func')",
            "assertExists should succeed for a defined function.");
    }
View Full Code Here

            "assertExists should succeed for a defined function.");
    }

    @Test
    public void testAssertTrue_javascript() {
        ScriptEngine engine = getScriptEngine();
        testWorks(engine, "var a = true; assertTrue(a);", "assertTrue of a true variable should succeed");
        testWorks(engine, "assertTrue(1 == 1)", "assertTrue on a true boolean expression should succeed");
        testThrowsAssertion(engine, "var a = false; assertTrue(a)", "assertTrue should fail on a false variable");
        testThrowsAssertion(engine, "assertTrue(1 == 2)", "assertTrue should fail on a false boolean expression");
    }
View Full Code Here

        testThrowsAssertion(engine, "assertTrue(1 == 2)", "assertTrue should fail on a false boolean expression");
    }

    @Test
    public void testAssertTrue_python() {
        ScriptEngine engine = getScriptEngine();
        testWorks(engine, "a = True\n" + "assertTrue(a)", "assertTrue of a true variable should succeed");
        testWorks(engine, "assertTrue(1 == 1)", "assertTrue on a true boolean expression should succeed");
        testThrowsAssertion(engine, "a = False\n" + "assertTrue(a)", "assertTrue should fail on a false variable");
        testThrowsAssertion(engine, "assertTrue(1 == 2)", "assertTrue should fail on a false boolean expression");
    }
View Full Code Here

        testThrowsAssertion(engine, "assertTrue(1 == 2)", "assertTrue should fail on a false boolean expression");
    }

    @Test
    public void testAssertFalse_javascript() {
        ScriptEngine engine = getScriptEngine();
        testWorks(engine, "var a = false; assertFalse(a)", "assertFalse of a false variable should succeed");
        testWorks(engine, "assertFalse(1 == 2)", "assertFalse on a false boolean expression should succeed");
        testThrowsAssertion(engine, "var a = true; assertFalse(a)", "assertFalse should fail on a true variable");
        testThrowsAssertion(engine, "assertFalse(1 == 1)", "assertFalse should fail on a true boolean expression");
    }
View Full Code Here

TOP

Related Classes of javax.script.ScriptEngine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.