jeudi 26 mars 2015

mock-server simple mock not working with XML in the body

I have a mock server using: http://ift.tt/1iJmeii


That server has two different rules for the POST that hits it. Here is the java code:



package mockserver.poc;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;
import static org.mockserver.model.StringBody.regex;

import org.mockserver.client.server.MockServerClient;
import org.mockserver.mockserver.MockServer;
import org.mockserver.model.Delay;

public class MockServerPoc {

public static void main(String[] args) {
MockServer mockServer = new MockServer(8888);
System.out.println("Running:" + mockServer.isRunning());

MockServerClient mockServerClient = new MockServerClient("10.189.225.196", 8888);

mockServerClient.when(
request()
.withMethod("POST")
.withPath("/something1")
.withBody(regex("SubscriberA"))
)
.respond(
response()
.withBody("<xml>\n something1 ok \n<xml>")
.withDelay(new Delay(SECONDS, 1))
);

mockServerClient.when(
request()
.withMethod("POST")
.withPath("/something1")
.withBody(regex("SubscriberB"))
)
.respond(
response()
.withBody("<xml>\n something2 ok \n<xml>")
.withDelay(new Delay(SECONDS, 1))
);
}
}


The problem with that code is that, using SOAPUI, if I try to hit it with the following XML:



<?xml version="1.0" encoding="UTF-8"?>
<ns2:Envelope xmlns:ns2="http://ift.tt/sVJIaE">
<ns2:Body>
<objectclass>SubscriberA</objectclass>
</ns2:Body>
</ns2:Envelope>


I don't get the expected result



<xml>\n something1 ok \n<xml>


If the body is just SubscriberA, it works fine, but if it is the entire XML, it simple doesn't work.


Am I doing wrong something wrong?


Aucun commentaire:

Enregistrer un commentaire