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

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

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.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()
                .handleScript(scriptContent)
                .valueExtraction(ValueExtractions.groovy())
                .dataMap(bindings)
                .extract().toString();

        Assert.assertEquals("Hello, Alice!", result);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy