package com.ibm.eclair;

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.apache.spark.SparkContext;
import org.junit.Test;

import java.io.InputStreamReader;

public class SparkBootstrapTest {

    @Test
    public void getEngine() throws Exception {
        ScriptEngineManager engineManager = new ScriptEngineManager();
        ScriptEngine engine = engineManager.getEngineByName("nashorn");
        SparkContext sc = new SparkContext("local[*]", "testapp");
        engine.put("sc", sc);

        SparkBootstrap b = new SparkBootstrap();
        b.load(engine);

        engine.eval(new InputStreamReader(getClass().getResourceAsStream("/rddtest.js")));
        Object ret = ((Invocable)engine).invokeFunction("test");

        System.out.println(ret);
        assertNotNull(ret);
    }
}

@@ -406,16 +406,17 @@
 ption %7B%0A
+%0A
         
@@ -431,302 +431,40 @@
 gine
-Manager engineManager = new ScriptEngineManager();%0A        ScriptEngine engine = engineManager.getEngineByName(%22nashorn%22);%0A        SparkContext sc = new SparkContext(%22local%5B*%5D%22, %22testapp%22);%0A        engine.put(%22sc%22, sc);%0A%0A        SparkBootstrap b = new SparkBootstrap();%0A        b.load(engine);%0A
+ engine = TestUtils.getEngine();
 %0A   

test error