All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.houbb.value.extraction.test.bs.JavaTest Maven / Gradle / Ivy

The newest version!
package com.github.houbb.value.extraction.test.bs;

import com.github.houbb.value.extraction.core.bs.ValueExtractionBs;
import com.github.houbb.value.extraction.core.support.extraction.ValueExtractions;
import org.junit.Assert;
import org.junit.Test;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class JavaTest {

    @Test
    public void test() {
        // 创建绑定并设置参数
        Map bindings = new HashMap<>();
        bindings.put("greeting", "Hello");
        bindings.put("name", "Janino");

        // 定义 JavaScript 脚本
        String script = "return map.get(\"greeting\") + \", \" + map.get(\"name\") + \"!\";";

        Object result = ValueExtractionBs.newInstance()
                .scripts(Arrays.asList(script))
                .valueExtraction(ValueExtractions.javaJanino())
                .dataMap(bindings)
                .extract();

        Assert.assertEquals("{return map.get(\"greeting\") + \", \" + map.get(\"name\") + \"!\";=Hello, Janino!}", result.toString());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy