com.github.houbb.value.extraction.test.bs.GroovyTest 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.ValueExtractionNashornJs;
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 GroovyTest {
@Test
public void test() {
// 创建绑定并设置参数
Map bindings = new HashMap<>();
bindings.put("name", "Alice");
String scriptContent =
"def greet(name) { " +
" return \"Hello, $name!\" " +
"}; " +
"greet(name)";
String result = ValueExtractionBs.newInstance()
.scripts(Arrays.asList(scriptContent))
.valueExtraction(ValueExtractions.groovy())
.dataMap(bindings)
.extract().toString();
Assert.assertEquals("{def greet(name) { return \"Hello, $name!\" }; greet(name)=Hello, Alice!}", result);
}
}