我有一个模拟服务器使用:http://www.mock-server.com
该服务器有两个不同的POST规则。这是java代码:
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))
);
}
}
该代码的问题在于,使用SOAPUI,如果我尝试使用以下XML命中它:
<?xml version="1.0" encoding="UTF-8"?>
<ns2:Envelope xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/">
<ns2:Body>
<objectclass>SubscriberA</objectclass>
</ns2:Body>
</ns2:Envelope>
我没有得到预期的结果
<xml>\n something1 ok \n<xml>
如果正文只是 SubscriberA ,它可以正常工作,但如果它是整个XML,那么它就很简单了。
我做错了什么?
答案 0 :(得分:0)
您可以使用xpath代替regex并以类似的方式解决它,例如以下示例:
FlatButton(Text('foo'), onPressed: areAllParametersFilled ? _onFooPressed : null),
FlatButton(Text('bar'), onPressed: !areAllParametersFilled ? _onBarPressed : null),