Package

Source Code of AbstractJavaScriptTest

import java.io.File;
import java.util.List;
import java.util.ArrayList;

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

import org.apache.commons.io.FileUtils;

public abstract class AbstractJavaScriptTest {
  private List<String> scriptFiles = new ArrayList<String>();
  private ScriptEngine engine;

  public AbstractJavaScriptTest() {
    engine = new ScriptEngineManager().getEngineByName("JavaScript");
  }
 
  protected void addScript(String name) {
    scriptFiles.add(name);
  }
  protected void initScripts() throws java.io.IOException, javax.script.ScriptException {
    for(String scriptFile: scriptFiles) {
      engine.eval(FileUtils.readFileToString(new File("src/main/javascript/" + scriptFile)));
    }
  }
  protected <T extends Bird> T getJs(String identifier, Class<T> c) {
    Invocable inv = (Invocable) engine;
    return (T) inv.getInterface(engine.get(identifier), c);
  }
}
TOP

Related Classes of AbstractJavaScriptTest

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.