ArgumentTypeMismatchTest.java 4.3 KB
Newer Older
T
tianqiao 已提交
1 2
package com.ql.util.express.example;

3 4 5 6
import com.ql.util.express.*;
import com.ql.util.express.instruction.op.OperatorBase;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
T
tianqiao 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
import org.junit.Test;

/**
 * Created by tianqiao on 17/6/4.
 */
public class ArgumentTypeMismatchTest {
    
    
    private static ArgumentTypeMismatchTest singleton = new ArgumentTypeMismatchTest();
    
    public void functionABC(Long a,Integer b,String c)
    {
        System.out.println("functionABC");
    }
    
    @Test
    public void test1() throws Exception {
        ExpressRunner runner = new ExpressRunner();
        runner.addFunctionOfServiceMethod("abc", singleton,"functionABC",new Class[]{Long.class,Integer.class,String.class},null);
        String exp = "abc(a,b,c)";
        IExpressContext<String, Object> context = new DefaultContext<String, Object>();
        context.put("a","1");
        context.put("b","2");
        context.put("c","3");
        try {
            runner.execute(exp, context, null, false, false);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    
    @Test
    public void test2() throws Exception {
        ExpressRunner runner = new ExpressRunner();
        runner.addFunction("abc", new Operator() {
            @Override
            public Object executeInner(Object[] list) throws Exception {
                Long paramA = Long.valueOf(list[0].toString());
                Integer paramB = Integer.valueOf(list[1].toString());
                String paramC = list[2].toString();
                singleton.functionABC(paramA,paramB,paramC);
                return null;
            }
        });
        String exp = "abc(a,b,c)";
        IExpressContext<String, Object> context = new DefaultContext<String, Object>();
        context.put("a","1");
        context.put("b","2");
        context.put("c","3");
        try {
            runner.execute(exp, context, null, false, false);
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.print("test ok!");
    }
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    
    @Test
    public void test3() throws Exception {
        ExpressRunner runner = new ExpressRunner();
        runner.addFunction("abc", new Operator() {
            @Override
            public Object executeInner(Object[] list) throws Exception {
                Long paramA = Long.valueOf(list[0].toString());
                Integer paramB = Integer.valueOf(list[1].toString());
                String paramC = list[2].toString();
                singleton.functionABC(paramA, paramB, paramC);
                return null;
            }
        });
        
        OperatorBase function = runner.getFunciton("abc");
        System.out.println("function = " + ToStringBuilder.reflectionToString(function, ToStringStyle.MULTI_LINE_STYLE));
        
        String exp = "abc(a,b,c)";
        IExpressContext<String, Object> context = new DefaultContext<String, Object>();
        context.put("a", "1");
        context.put("b", "2");
        context.put("c", "3");
        
        InstructionSet instructionSet = runner.getInstructionSetFromLocalCache(exp);
        String[] outFunctionNames = runner.getOutFunctionNames(exp);
        String[] outVarNames = runner.getOutVarNames(exp);
        System.out.println("before execute instructionSet = " + instructionSet);
        System.out.println("outFunctionNames = " + ToStringBuilder.reflectionToString(outFunctionNames, ToStringStyle.MULTI_LINE_STYLE));
        System.out.println("outVarNames = " + ToStringBuilder.reflectionToString(outVarNames, ToStringStyle.MULTI_LINE_STYLE));
        
        try {
            runner.execute(exp, context, null, false, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        instructionSet = runner.getInstructionSetFromLocalCache(exp);
        outFunctionNames = runner.getOutFunctionNames(exp);
        outVarNames = runner.getOutVarNames(exp);
        System.out.println("after execute instructionSet = " + instructionSet);
        System.out.println("outFunctionNames = " + ToStringBuilder.reflectionToString(outFunctionNames, ToStringStyle.MULTI_LINE_STYLE));
        System.out.println("outVarNames = " + ToStringBuilder.reflectionToString(outVarNames, ToStringStyle.MULTI_LINE_STYLE));
        
        System.out.println("test ok!");
    }
T
tianqiao 已提交
109
}