Search in sources :

Example 71 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project hazelcast by hazelcast.

the class HazelcastOSGiScriptEngineTest method bindingsGetAndSetSuccessfully.

@Test
public void bindingsGetAndSetSuccessfully() {
    ScriptEngineManager scriptEngineManager = ScriptEngineManagerContext.getScriptEngineManager();
    List<ScriptEngineFactory> engineFactories = scriptEngineManager.getEngineFactories();
    assertNotNull(engineFactories);
    for (ScriptEngineFactory engineFactory : engineFactories) {
        verifyThatBindingsGetAndSetSuccessfully(engineFactory.getScriptEngine());
    }
}
Also used : ScriptEngineFactory(javax.script.ScriptEngineFactory) GroovyScriptEngineFactory(org.codehaus.groovy.jsr223.GroovyScriptEngineFactory) ScriptEngineManager(javax.script.ScriptEngineManager) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 72 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project groovy-core by groovy.

the class JSR223SpecTest method testInvocableFunction.

@Test
public void testInvocableFunction() throws ScriptException, NoSuchMethodException {
    // tag::jsr223_invocable[]
    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName("groovy");
    String fact = "def factorial(n) { n == 1 ? 1 : n * factorial(n - 1) }";
    engine.eval(fact);
    Invocable inv = (Invocable) engine;
    Object[] params = { 5 };
    Object result = inv.invokeFunction("factorial", params);
    assertEquals(new Integer(120), result);
// end::jsr223_invocable[]
}
Also used : Invocable(javax.script.Invocable) ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine) Test(org.junit.Test)

Example 73 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project groovy-core by groovy.

the class JSR223SpecTest method testSimpleExample.

@Test
public void testSimpleExample() throws ScriptException {
    // tag::jsr223_init[]
    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName("groovy");
    // end::jsr223_init[]
    // tag::jsr223_basic[]
    Integer sum = (Integer) engine.eval("(1..10).sum()");
    assertEquals(new Integer(55), sum);
    // end::jsr223_basic[]
    // tag::jsr223_variables[]
    engine.put("first", "HELLO");
    engine.put("second", "world");
    String result = (String) engine.eval("first.toLowerCase() + ' ' + second.toUpperCase()");
    assertEquals("hello WORLD", result);
// end::jsr223_variables[]
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine) Test(org.junit.Test)

Example 74 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project es6draft by anba.

the class InvocableTest method setUp.

@Before
public void setUp() {
    manager = new ScriptEngineManager();
    engine = manager.getEngineByName("es6draft");
    assertThat(engine, notNullValue());
    assertThat(engine, instanceOf(Invocable.class));
    invocable = (Invocable) engine;
}
Also used : Invocable(javax.script.Invocable) ScriptEngineManager(javax.script.ScriptEngineManager) Before(org.junit.Before)

Example 75 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project es6draft by anba.

the class TypeConversionTest method setUp.

@Before
public void setUp() {
    manager = new ScriptEngineManager();
    engine = manager.getEngineByName("es6draft");
    assertThat(engine, notNullValue());
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) Before(org.junit.Before)

Aggregations

ScriptEngineManager (javax.script.ScriptEngineManager)109 ScriptEngine (javax.script.ScriptEngine)66 Test (org.junit.Test)23 ScriptException (javax.script.ScriptException)20 ScriptEngineFactory (javax.script.ScriptEngineFactory)14 File (java.io.File)12 Invocable (javax.script.Invocable)11 QuickTest (com.hazelcast.test.annotation.QuickTest)10 IOException (java.io.IOException)10 FileReader (java.io.FileReader)9 Bindings (javax.script.Bindings)9 Before (org.junit.Before)9 Map (java.util.Map)8 GroovyScriptEngineFactory (org.codehaus.groovy.jsr223.GroovyScriptEngineFactory)8 Reader (java.io.Reader)7 HashMap (java.util.HashMap)6 SimpleBindings (javax.script.SimpleBindings)6 PrintWriter (java.io.PrintWriter)4 StringWriter (java.io.StringWriter)4 InputStreamReader (java.io.InputStreamReader)3