com.github.houbb.value.extraction.test.bs.JsTest 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.util.Arrays;
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()
.scripts(Arrays.asList(script))
.valueExtraction(ValueExtractions.js())
.dataMap(bindings)
.extract().toString();
Assert.assertEquals("{var greeting = 'Hello, ' + name + '! You are ' + age + ' years old.'; greeting;=Hello, Alice! You are 30 years old.}", result);
}
}