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

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

There is a newer version: 0.8.0
Show 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.util.HashMap;
import java.util.Map;

public class JsTest {

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

        // 定义 JavaScript 脚本
        String script = "var greeting = 'Hello, ' + name + '! You are ' + age + ' years old.'; greeting;";

        String result = ValueExtractionBs.newInstance()
                .handleScript(script)
                .valueExtraction(ValueExtractions.js())
                .dataMap(bindings)
                .extract().toString();

        Assert.assertEquals("Hello, Alice! You are 30 years old.", result);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy