在柑橘模拟器中提取 post 变量

Extracting post variable in citrus simulator

我正在试用柑橘模拟器并尝试休息示例。下面是模拟器和休息客户端的代码。这里的关键是我没有使用@CitrusTest 注释。

@Scenario("MyRestServiceScenario")
@RequestMapping(value = "/services/rest/simulator/hello", method = RequestMethod.POST)
public class MyRestServiceSimulator extends AbstractSimulatorScenario {
    @Override
    public void run(ScenarioDesigner scenario) {

        scenario
                .http()
                .receive()
                .post()
                .payload("{\"Hello\":[\"JS01\"]}")
                .extractFromPayload("$Hello", "greeting").getActor().;

        //String gr = scenario.getTestContext().getVariable("greeting");
        scenario.echo("Received greeting: ${greeting}");

        scenario
                .http()
                .send()
                .response(HttpStatus.OK)
                .payload("<HelloResponse xmlns=\"http://citrusframework.org/schemas/hello\">" +
                        "Hi there!" +
                        "</HelloResponse>");
    }
}

主要Class

public class CitrusRest {
    public static void main(String... args) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

        RestTemplate rt = new RestTemplate();

        MultiValueMap<String, String>  vars = new LinkedMultiValueMap<String, String>();
        vars.add("Hello", "JS01");

        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(vars, headers);
        String uri = "http://" + "localhost" + ":8080//services/rest/simulator/hello";

        rt.postForEntity(uri, request, String.class);
    }
}

在调试器模式下,我确实看到有效载荷到达 运行 方法,我期待 post .extractFromPayload("$Hello", "greeting")。我应该在 greeting 变量中收到 JS01。但变量从未初始化。

有人可以帮忙吗?

$Hello 不是有效的 JsonPath 表达式。您还应该在日志中看到一些错误:

com.jayway.jsonpath.InvalidPathException: Illegal character at position 1 expected '.' or '[

正确的表达方式是$.Hello