/*
 * Copyright 2014 jlamande.
 *
 * Licensed 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 prototypes.ws.proxy.soap.utils;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import org.junit.Test;

/**
 *
 * @author jlamande
 */
public class EvalScriptTest {

    @Test
    public void test() throws Exception {
        // create a script engine manager
        ScriptEngineManager factory = new ScriptEngineManager();
        // create a JavaScript engine
        System.out.println(factory.getEngineFactories());
        ScriptEngine engine = factory.getEngineByName("JavaScript");

        // create a Java object
        String name = "Tom";

        // create the binding
        engine.put("greetingname", name);

        // evaluate JavaScript code from String
        // dont work in nashorn (JDK 8) so will need to import an engine as rhino
        // in order to use Javascript
        //engine.eval("println('Hello, ' + greetingname)");
        //engine.eval("println('The name length is ' +  greetingname.length)");
    }
}

@@ -718,18 +718,118 @@
 org.
-junit.Test
+codehaus.janino.ExpressionEvaluator;%0Aimport org.junit.Test;%0Aimport prototypes.ws.proxy.soap.model.SoapExchange
 ;%0A%0A/
@@ -1573,24 +1573,24 @@
 ingname)%22);%0A
-
         //en
@@ -1653,20 +1653,1304 @@
 .length)%22);%0A
+        // Compile the expression once; relatively slow.%0A        ExpressionEvaluator ee = new ExpressionEvaluator(%0A                %22c %3E d ? c : d%22, // expression%0A                int.class, // expressionType%0A                new String%5B%5D%7B%22c%22, %22d%22%7D, // parameterNames%0A                new Class%5B%5D%7Bint.class, int.class%7D // parameterTypes%0A        );%0A%0A        // Evaluate it with varying parameter values; very fast.%0A        Integer res = (Integer) ee.evaluate(%0A                new Object%5B%5D%7B // parameterValues%0A                    new Integer(10),%0A                    new Integer(11),%7D%0A        );%0A        System.out.println(%22res = %22 + res);%0A%0A        // Compile the expression once; relatively slow.%0A        ExpressionEvaluator esoap = new ExpressionEvaluator(%0A                %22s.getBackEndResponseTime() %3E 0%22, // expression%0A                boolean.class, // expressionType%0A                new String%5B%5D%7B%22s%22%7D, // parameterNames%0A                new Class%5B%5D%7BSoapExchange.class%7D // parameterTypes%0A        );%0A        SoapExchange exchange = new SoapExchange();%0A        // Evaluate it with varying parameter values; very fast.%0A        /*Boolean res2 = (Boolean) ee.evaluate(%0A         new Object%5B%5D%7B // parameterValues%0A         exchange,%7D%0A         );%0A         System.out.println(%22res2 = %22 + res2);*/%0A
     %7D%0A%7D%0A

Test expression evaluations