Search in sources :

Example 16 with ScriptEngineManager

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

the class HazelcastOSGiScriptEngineManagerTest method bindingsGetAndSetSuccessfully.

@Test
public void bindingsGetAndSetSuccessfully() {
    ScriptEngineManager scriptEngineManager = ScriptEngineManagerContext.getScriptEngineManager();
    assertNotNull(scriptEngineManager.getBindings());
    Bindings mockBindings = mock(Bindings.class);
    scriptEngineManager.setBindings(mockBindings);
    assertEquals(mockBindings, scriptEngineManager.getBindings());
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) Bindings(javax.script.Bindings) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with ScriptEngineManager

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

the class HazelcastOSGiScriptEngineTest method scriptEngineEvaluatedSuccessfully.

@Test
public void scriptEngineEvaluatedSuccessfully() throws ScriptException {
    ScriptEngineManager scriptEngineManager = ScriptEngineManagerContext.getScriptEngineManager();
    GroovyScriptEngineFactory groovyScriptEngineFactory = new GroovyScriptEngineFactory();
    scriptEngineManager.registerEngineName("groovy", groovyScriptEngineFactory);
    ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("groovy");
    assertNotNull(scriptEngine);
    verifyScriptEngineEvaluation(scriptEngine);
}
Also used : GroovyScriptEngineFactory(org.codehaus.groovy.jsr223.GroovyScriptEngineFactory) ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with ScriptEngineManager

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

the class HazelcastOSGiScriptEngineTest method putAndGetContextSuccessfully.

@Test
public void putAndGetContextSuccessfully() {
    ScriptEngineManager scriptEngineManager = ScriptEngineManagerContext.getScriptEngineManager();
    List<ScriptEngineFactory> engineFactories = scriptEngineManager.getEngineFactories();
    assertNotNull(engineFactories);
    for (ScriptEngineFactory engineFactory : engineFactories) {
        verifyThatPutAndGetContextSuccessfully(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 19 with ScriptEngineManager

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

the class HazelcastOSGiScriptEngineTest method putAndGetSuccessfully.

@Test
public void putAndGetSuccessfully() {
    ScriptEngineManager scriptEngineManager = ScriptEngineManagerContext.getScriptEngineManager();
    List<ScriptEngineFactory> engineFactories = scriptEngineManager.getEngineFactories();
    assertNotNull(engineFactories);
    for (ScriptEngineFactory engineFactory : engineFactories) {
        verifyThatPutAndGetSuccessfully(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 20 with ScriptEngineManager

use of javax.script.ScriptEngineManager in project opennms by OpenNMS.

the class OSGiScriptEngineManager method getEngineByMimeType.

public ScriptEngine getEngineByMimeType(String mimeType) {
    //TODO this is a hack to deal with context class loader issues
    ScriptEngine engine = null;
    for (ScriptEngineManager manager : classLoaders.keySet()) {
        ClassLoader old = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(classLoaders.get(manager));
        engine = manager.getEngineByMimeType(mimeType);
        Thread.currentThread().setContextClassLoader(old);
        if (engine != null)
            break;
    }
    return engine;
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) ScriptEngine(javax.script.ScriptEngine)

Aggregations

ScriptEngineManager (javax.script.ScriptEngineManager)84 ScriptEngine (javax.script.ScriptEngine)46 Test (org.junit.Test)19 ScriptException (javax.script.ScriptException)15 ScriptEngineFactory (javax.script.ScriptEngineFactory)11 QuickTest (com.hazelcast.test.annotation.QuickTest)10 Invocable (javax.script.Invocable)10 IOException (java.io.IOException)8 GroovyScriptEngineFactory (org.codehaus.groovy.jsr223.GroovyScriptEngineFactory)8 Before (org.junit.Before)8 FileReader (java.io.FileReader)7 File (java.io.File)6 Reader (java.io.Reader)6 Bindings (javax.script.Bindings)6 Map (java.util.Map)5 HashMap (java.util.HashMap)3 SimpleBindings (javax.script.SimpleBindings)3 NashornScriptEngine (jdk.nashorn.api.scripting.NashornScriptEngine)3 Plugin (the.bytecode.club.bytecodeviewer.api.Plugin)3 Person (com.winterbe.java8.samples.lambda.Person)2