opentable / wiremock-body-transformer

Wiremock Body Transformer Extension
Apache License 2.0
65 stars 42 forks source link

Response is always null #22

Closed intivekks closed 8 years ago

intivekks commented 8 years ago

Hi. Project looks great, thank you very much for the effort. But I've got a problem with it.

Any of my tries end up with null. Could you help me figured out what may be the problem in here please?

config:

private WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.options()
            .port(8089)
            .usingFilesUnderDirectory("src/e2etest/resources/")
            .extensions(new BodyTransformer()));

    private Date now = new Date();

    public void stubStart() {

        wireMockServer.start();

        wireMockServer.stubFor(post(urlEqualTo("xxx"))
                .willReturn(aResponse()
                        .withStatus(200)
                        .withBodyFile("response.xml")
                        .withTransformers("body-transformer")
                        .withHeader("Content-Type", "text/xml")
                        .withHeader("Server", "Apache-Coyote/1.1")
                        .withHeader("X-OPNET-Transaction-Trace", "xxx")
                        .withHeader("Date", now.toString())
                        .withHeader("Connection", "keep-alive")
                        .withHeader("Set-Cookie", "xxx"))
        );
    }

request.xml:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
     <soap:Header>
           ...
     <soap:Header>
     <soap:Body>
        <requestMessage xmlns="xxx">
            <merchantID>xxx</merchantID>
            <merchantReferenceCode>test-4</merchantReferenceCode>
            ...
        </requestMessage>
    </soap:Body>
</soap:Envelope>

response.xml:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
     <soap:Header>
           ...
     <soap:Header>
     <soap:Body>
         <c:replyMessage xmlns:c="xxx">
            <c:merchantReferenceCode>$(Envelope.Body.requestMessage.merchantReferenceCode.value</c:merchantReferenceCode>
            ...
         </c:replyMessage>
   </soap:Body>
</soap:Envelope>
tranhungt commented 8 years ago

Is your response working even without the body transformer? Also, our body transformer works with XML, but I'm not sure if it works with parsing soap calls...

intivekks commented 8 years ago

According to issue #10 it should work. In my stub, I try to get value of field from request to response. First I had it wrong. In response.xml I used ${} instead of $() and returned value was exactly like in response file: "${Envelope.Body.requestMessage...}" . When I changed it to $() it returned null, so something works in there. I tried a lot of different variants of path notation, but it is return null in every case.

my test:

Then("^I get Response massage$", () -> {
            response.then().assertThat()
                    .body("soap:Envelope.soap:Body.c:replyMessage.c:merchantReferenceCode", equalTo("test-4"));
        });
KRoLer commented 8 years ago

@intivekks, it needs to be tested, of course, but I hope my solution will help you: To achieve < requestMessage xmlns="xxx" > you should use $(Body.requestMessage.value). Most of all root tag (Envelope) will be omitted and soap: namespace too.

intivekks commented 8 years ago

I have tried:

<c:merchantReferenceCode>$(soap:Envelope.soap:Body.requestMessage.merchantReferenceCode.value)</c:merchantReferenceCode>
<c:merchantReferenceCode>$(Envelope.Body.requestMessage.merchantReferenceCode.value)</c:merchantReferenceCode>
<c:merchantReferenceCode>$(soap:Body.requestMessage.merchantReferenceCode.value)</c:merchantReferenceCode>
<c:merchantReferenceCode>$(Body.requestMessage.merchantReferenceCode.value)</c:merchantReferenceCode>
<c:merchantReferenceCode>$(requestMessage.merchantReferenceCode.value)</c:merchantReferenceCode>
<c:merchantReferenceCode>$(merchantReferenceCode.value)</c:merchantReferenceCode>
<c:merchantReferenceCode>$(soap:Envelope.soap:Body.requestMessage.merchantReferenceCode)</c:merchantReferenceCode>
<c:merchantReferenceCode>$(Envelope.Body.requestMessage.merchantReferenceCode)</c:merchantReferenceCode>
<c:merchantReferenceCode>$(soap:Body.requestMessage.merchantReferenceCode)</c:merchantReferenceCode>
<c:merchantReferenceCode>$(Body.requestMessage.merchantReferenceCode)</c:merchantReferenceCode>
<c:merchantReferenceCode>$(requestMessage.merchantReferenceCode)</c:merchantReferenceCode>
<c:merchantReferenceCode>$(merchantReferenceCode)</c:merchantReferenceCode>

results: Expected: test-4 Actual: null, null, null, null, null, null, null, null, null, null, null, null

intivekks commented 8 years ago

Shame on me! So sorry for spamming. My definition of Response was bad. Now it's working great. Thank you all for this awesome project, and thanks for commenters. Best luck!

tranhungt commented 8 years ago

Thanks @KRoLer! Cheers @intivekks. :)