package modTransf.script;
import junit.framework.TestCase;
import javax.script.CompiledScript;
import javax.script.ScriptException;
import java.io.IOException;
/**
* <p>Titre : TopmodL</p>
* <p>Description : </p>
* <p>Copyright : Copyright (c) 2004</p>
* <p>Soci�t� : Dream Factory</p>
* @author Cedric
* @version 1.0
*/
/**
* Test the CompiledScriptFactory interface;
* <p>Titre : ModTransf</p>
* <p>Description : </p>
* <p>Copyright : Copyright (c) 2004</p>
* <p>Soci�t� : Dream Factory</p>
* @author Cedric
* @version 1.0
*/
public class CompiledScriptFactoryTest extends TestCase
{
public CompiledScriptFactoryTest (String name)
{
super(name);
}
/**
* Initialize the context for a new test.
* This method is called befor each test
* @throws IOException
*/
public void setUp() throws IOException
{
}
/**
* Tear down the test.
* This method is called after each test.
*/
public void tearDown()
{
}
/**
* Check if the specified compiler is registered.
* @throws ScriptException
*/
public void testRegisteredCompilerEL()
throws ScriptException
{
String language = "el";
// Try with language specified in script
CompiledScript res = CompiledScriptFactory.compileScript( "script1", language);
assertNotNull("Result found", res);
assertEquals("Found right compiler", language, res.getEngine().getFactory().getLanguageName());
}
public void testDefaultCompiler()
throws ScriptException
{
CompiledScript res = CompiledScriptFactory.compileScript( "a" );
assertNotNull("Result found", res);
}
public void testRhinoScript()
throws javax.script.ScriptException
{
CompiledScript compiledScript = CompiledScriptFactory.getInstance().compileScript( "a", "rhino" );
javax.script.Namespace context = compiledScript.getEngine().createNamespace();
context.put( "a", new Integer(123));
Object res = compiledScript.eval( context);
assertNotNull("Result found", res);
assertEquals("Result found", new Integer(123), res);
}
}