/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package org.apache.commons.jexl.scripting;

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

import junit.framework.TestCase;

public class JexlScriptEngineTest extends TestCase {
    
    public void testScripting() throws Exception {
        ScriptEngineManager manager = new ScriptEngineManager();
        assertNotNull("Manager should not be null", manager);
        ScriptEngine engine = manager.getEngineByName("jexl");
        assertNotNull("Engine should not be null (name)", engine);
        engine = manager.getEngineByExtension("jexl");
        assertNotNull("Engine should not be null (ext)", engine);
        final Integer initialValue = Integer.valueOf(123);
        assertEquals(initialValue,engine.eval("123"));
        assertEquals(initialValue,engine.eval("0;123"));// multiple statements
        long time1 = System.currentTimeMillis();
        Long time2 = (Long) engine.eval("" +
        		"sys=context.class.forName(\"java.lang.System\");"
        		+"now=sys.currentTimeMillis();"
        		);
        assertTrue("Must take some time to process this",time1 <= time2.longValue());
        engine.put("value", initialValue);
        assertEquals(initialValue,engine.get("value"));
        final Long newValue = Long.valueOf(124);
        assertEquals(newValue,engine.eval("old=value;value=value+1"));
        assertEquals(initialValue,engine.get("old"));
        assertEquals(newValue,engine.get("value"));
    }

}

@@ -2260,10 +2260,1705 @@
 %0A    %7D%0A%0A
+    public void testEngineNames() throws Exception %7B%0A        ScriptEngine engine;%0A        ScriptEngineManager manager = new ScriptEngineManager();%0A        assertNotNull(%22Manager should not be null%22, manager);%0A        engine = manager.getEngineByName(%22JEXL%22);%0A        assertNotNull(%22Engine should not be null (JEXL)%22, engine);        %0A        engine = manager.getEngineByName(%22Jexl%22);%0A        assertNotNull(%22Engine should not be null (Jexl)%22, engine);        %0A        engine = manager.getEngineByName(%22jexl%22);%0A        assertNotNull(%22Engine should not be null (jexl)%22, engine);        %0A    %7D%0A%0A    public void testScopes() throws Exception %7B%0A        ScriptEngine engine;%0A        ScriptEngineManager manager = new ScriptEngineManager();%0A        assertNotNull(%22Manager should not be null%22, manager);%0A        engine = manager.getEngineByName(%22JEXL%22);%0A        assertNotNull(%22Engine should not be null (JEXL)%22, engine);%0A        manager.put(%22global%22,Integer.valueOf(1));%0A        engine.put(%22local%22, Integer.valueOf(10));%0A        manager.put(%22both%22,Integer.valueOf(7));%0A        engine.put(%22both%22, Integer.valueOf(7));%0A        engine.eval(%22local=local+1%22);%0A        engine.eval(%22global=global+1%22);%0A        engine.eval(%22both=both+1%22); // should update engine value only%0A        engine.eval(%22newvar=42;%22);%0A        assertEquals(Long.valueOf(2),manager.get(%22global%22));%0A        assertEquals(Long.valueOf(11),engine.get(%22local%22));%0A        assertEquals(Integer.valueOf(7),manager.get(%22both%22));%0A        assertEquals(Long.valueOf(8),engine.get(%22both%22));%0A        assertEquals(Integer.valueOf(42),engine.get(%22newvar%22));%0A        assertNull(manager.get(%22newvar%22));%0A        // TODO how to delete variables in Jexl?%0A    %7D%0A
 %7D%0A

Add some scope tests