Package javax.script

Examples of javax.script.ScriptEngine.eval()


    public void testEngineInitialization() throws Exception {
        PythonScriptEngineInitializer initializer = new PythonScriptEngineInitializer();
        ScriptEngine engine = initializer.instantiate(Collections.<String> emptySet(), null);

        //just some code to test out this is python
        engine.eval("from java.util import HashMap\nHashMap()");
    }

    public void testMethodIndirection() throws Exception {
        PythonScriptEngineInitializer initializer = new PythonScriptEngineInitializer();
        ScriptEngine engine = initializer.instantiate(Collections.<String> emptySet(), null);
View Full Code Here


        Tester tester = new Tester();
        bindings.put("tester", tester);

        engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);

        engine.eval("tester.increment()");

        Assert.assertEquals(tester.getInvocationCoung(), 1, "Unexpected number of tester invocations.");

        Map<String, Set<Method>> methods = getMethodsByName(Tester.class);
        for (Set<Method> ms : methods.values()) {
View Full Code Here

        Map<String, Set<Method>> methods = getMethodsByName(Tester.class);
        for (Set<Method> ms : methods.values()) {
            Set<String> fns = initializer.generateIndirectionMethods("tester", ms);
            for (String fn : fns) {
                engine.eval(fn);
            }
        }

        engine.eval("increment()");
        Assert.assertEquals(tester.getInvocationCoung(), 2,
View Full Code Here

            for (String fn : fns) {
                engine.eval(fn);
            }
        }

        engine.eval("increment()");
        Assert.assertEquals(tester.getInvocationCoung(), 2,
            "Unexpected number of tester invocations after calling an indirected method.");
    }

    public void testSecuredEngine() throws Exception {
View Full Code Here

        perms.add(new FilePermission("<<ALL FILES>>", "read"));

        ScriptEngine engine = initializer.instantiate(Collections.<String> emptySet(), perms);

        try {
            engine.eval("import os\nfp = open('pom.xml', 'w')");
            Assert.fail("Opening a file for writing should have failed with a security exception.");
        } catch (ScriptException e) {
            checkIsCausedByAccessControlException(e);
        }
    }
View Full Code Here

        engine.getContext().setWriter(wrt);
       
        initializer.installScriptSourceProvider(engine, new SourceProvider());

        engine
            .eval("import sys\nsys.path.append('__rhq__:test-unsupported/')\nsys.path.append('__rhq__:test/')\nimport test_module");

        Assert.assertEquals(wrt.toString(), EXPECTED_OUTPUT + "\n", "Unexpected output from a custom module.");
    }
View Full Code Here

            + "var test2 = \"strstr\"\n"
            + "var test3 = new java.lang.String(\"strstr\")\n";
       
        ScriptEngine engine = getScriptEngine();
       
        engine.eval(script);
       
        //now do the tests with the initialized context
       
        Object ret = engine.eval("test1 == test2");       
        assertEquals(ret, Boolean.TRUE, "Unexpected concatenated and javascript string comparison.");       
View Full Code Here

       
        engine.eval(script);
       
        //now do the tests with the initialized context
       
        Object ret = engine.eval("test1 == test2");       
        assertEquals(ret, Boolean.TRUE, "Unexpected concatenated and javascript string comparison.");       
       
        ret = engine.eval("test1 == test3");       
        assertEquals(ret, Boolean.TRUE, "Unexpected concatenated and java string comparison.");
       
View Full Code Here

        //now do the tests with the initialized context
       
        Object ret = engine.eval("test1 == test2");       
        assertEquals(ret, Boolean.TRUE, "Unexpected concatenated and javascript string comparison.");       
       
        ret = engine.eval("test1 == test3");       
        assertEquals(ret, Boolean.TRUE, "Unexpected concatenated and java string comparison.");
       
        ret = engine.eval("test2 == test3");       
        assertEquals(ret, Boolean.TRUE, "Unexpected javascript and java string comparison.");
               
View Full Code Here

        assertEquals(ret, Boolean.TRUE, "Unexpected concatenated and javascript string comparison.");       
       
        ret = engine.eval("test1 == test3");       
        assertEquals(ret, Boolean.TRUE, "Unexpected concatenated and java string comparison.");
       
        ret = engine.eval("test2 == test3");       
        assertEquals(ret, Boolean.TRUE, "Unexpected javascript and java string comparison.");
               
        ret = engine.eval("java.lang.Integer.parseInt('1' + '2');");
        assertEquals(ret, 12, "Engine failed to pass a concatenated string as a string parameter.");
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.