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

com.github.houbb.value.extraction.test.bs.XmlTest 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 XmlTest {

    @Test
    public void test() {
        String xml = "        \n" +
                "            \n" +
                "                John Doe\n" +
                "                Software Engineer\n" +
                "                75000\n" +
                "            \n" +
                "            \n" +
                "                Jane Smith\n" +
                "                Project Manager\n" +
                "                85000\n" +
                "            \n" +
                "        ";

        // 测试 getValueByXPath 方法
        String script = "//employee[1]/name/text()";

        // 创建绑定并设置参数
        Map bindings = new HashMap<>();
        bindings.put("xml", xml);

        String result = ValueExtractionBs.newInstance()
                .scripts(Arrays.asList(script))
                .valueExtraction(ValueExtractions.xmlPath())
                .dataMap(bindings)
                .extract().toString();

        Assert.assertEquals("{//employee[1]/name/text()=John Doe}", result);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy