/*
 *
 *  Copyright 2018 FJN Corp.
 *
 *  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.
 *
 *  Author                        Date                       Issue
 *  fs1194361820@163.com          2015-01-01                 Initial Version
 *
 */

package com.fjn.helper.frameworkex.ognl;

import java.util.LinkedList;
import java.util.List;

import ognl.Ognl;
import ognl.OgnlContext;
import ognl.OgnlException;

import org.junit.Test;

public class OgnlTest {

    public void test() throws OgnlException {
        OgnlContext context = new OgnlContext();
        context.setRoot(new Option());

        Ognl.setRoot(context, context.getRoot());

        Ognl.setValue("#this.value", context.getRoot(), "3");
        System.out.println(Ognl.getValue("value", context.getRoot()));

        Ognl.parseExpression("value");


    }

    @Test
    public void testSetValueToList() throws OgnlException{
        OgnlContext context = new OgnlContext();
        List<Option> list = new LinkedList<Option>();
        context.setRoot(list);

        // init list
        for(int i =0; i< 3; i++){
            Ognl.getValue("#this.add( new com.fjn.helper.frameworkex.ognl.Option() )", context, list, null);
        }

        Ognl.setValue("#this.{? #this.value==0}.{@ognl.Ognl@setVlue('#this.value', )}", context.getRoot(),"3");
        //	System.out.println(Ognl.getValue("value", context.getRoot()));

        //	Ognl.parseExpression("value");
        System.out.println(3);
    }

}
