<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:myheader="http://myheader">
<env:Header>
<myheader:time>1517241715</myheader:time>
</env:Header>
<env:Body>
<FooRequest xmlns="http:/foo">
<foo>123</foo>
</FooRequest>
</env:Body>
</env:Envelope>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<FooResponse xmlns="http://foo">
<a>Computer 1</a>
</FooResponse>
</env:Body>
</env:Envelope>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:myheader="http://myheader">
<env:Header>
<myheader:time>1517241790</myheader:time>
</env:Header>
<env:Body>
<BarRequest xmlns="http:/bar">
<bar>asdasfsa</bar>
</BarRequest>
</env:Body>
</env:Envelope>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<BarResponse xmlns="http://bar">
<b>Tsugu</b>
</BarResponse>
</env:Body>
</env:Envelope>
"predicateGenerators": [
{
"matches": {
"body": true
},
"except" : "<env:Header>([\\s\\S]*?)<\/env:Header>"
}
],
"predicateGenerators": [
{
"matches": {
"body": true
},
"xpath": {
"selector": "//*[(normalize-space()) and (text()) and ancestor::soap:Body]",
"ns": {
"soap": "http://schemas.xmlsoap.org/soap/envelope/"
}
}
}
"predicates": [
{
"xpath": {
"selector": "//*[(normalize-space()) and (text()) and ancestor::soap:Body]",
"ns": {
"soap": "http://schemas.xmlsoap.org/soap/envelope/"
}
},
"deepEquals": {
"body": [
"\n ",
"123"
]
}
}
],
"responses": [
{
"is": { // 2 different responses here...
Q1: seems that I can't use predicateGenerators & xpath to simply conveniently match to the full Body element, since xpathing only works with scalar values, is this still the case? (https://groups.google.com/forum/#!topic/mountebank-discuss/sEMVYeBZ9Xg)
Q2: PredicateGenerators & ExceptI used PredicateGenerators with Except regexp to leave SOAP Header out of the matching:"predicateGenerators": [
{
"matches": {
"body": true
},
"except" : "<env:Header>([\\s\\S]*?)<\/env:Header>"
}
],this works and returns correct responses for RQ1 and RQ2. However, if RQ1 is repeated multiple times during the recording, and these result in different responses (RES1 = Computer 1, RES 2 = Computer2, ...), only RES1 gets returned. Each request-response pair gets its own stub, and only the first stub is returned when playing back.Am I using PredicateGenerators & Except correctly, and why aren't all the requests that match the same predicate with "except" stored in same stub?
{
"imposters": [
{
"protocol": "http",
"port": 3001,
"stubs": [{
"responses": [
{ "is": { "body": "<%- stringify(filename, 'res1.xml') %>"} },
{ "is": { "body": "<%- stringify(filename, 'res2.xml') %>"} }
]
}]
},
{
"protocol": "http",
"port": 3000,
"stubs": [{
"responses": [{
"proxy": {
"mode": "proxyAlways",
"to": "http://localhost:3001",
"predicateGenerators": [{
"matches": { "body": true },
"except": "<env:Header>([\\s\\S]*?)<\/env:Header>"
}]
}
}]Then I sent the following set of shell commands (req1.xml and req2.xml correspond to your requests above, the -d@file curl parameter POSTs that file to the url):
}]
}
]
}
{
"port": 8800,
"protocol": "http",
"name": "proxyToProxy",
"stubs": [
{
"responses": [
{
"proxy": {
"to": "http://localhost:8900/",
"predicateGenerators": [
{
"matches": {
"body": true
},
"except" : "<env:Header>([\\s\\S]*?)<\/env:Header>"
}
],
"mode": "proxyAlways"
}
}
]
}
]
}{
"imposters": [
{
"protocol": "http",
"port": 8800,
"name": "proxyToProxy",
"stubs": [
{
"predicates": [
{
"except": "<env:Header>([\\s\\S]*?)</env:Header>",
"deepEquals": {
"body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"\n xmlns:myheader=\"http://myheader\">\n <env:Header>\n <myheader:time>1517241715</myheader:time>\n </env:Header>\n <env:Body>\n <FooRequest xmlns=\"http:/foo\">\n <foo>123</foo>\n </FooRequest>\n </env:Body>\n</env:Envelope>\n"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"headers": {
"Content-Type": "application/xml",
"Content-Length": 222,
"Server": "Jetty(6.1.26)",
"Connection": "close"
},
"body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <env:Body>\n <FooResponse xmlns=\"http://foo\"> \n <a>Computer 1</a>\n </FooResponse>\n </env:Body>\n</env:Envelope>",
"_mode": "text"
}
}
]
},
{
"predicates": [
{
"except": "<env:Header>([\\s\\S]*?)</env:Header>",
"deepEquals": {
"body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"\n xmlns:myheader=\"http://myheader\">\n <env:Header>\n <myheader:time>1517241716</myheader:time>\n </env:Header>\n <env:Body>\n <FooRequest xmlns=\"http:/foo\">\n <foo>123</foo>\n </FooRequest>\n </env:Body>\n</env:Envelope>\n"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"headers": {
"Content-Type": "application/xml",
"Content-Length": 225,
"Server": "Jetty(6.1.26)",
"Connection": "close"
},
"body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <env:Body>\n <FooResponse xmlns=\"http://foo\"> \n <a>Computer 2000</a>\n </FooResponse>\n </env:Body>\n</env:Envelope>",
"_mode": "text"
}
}
]
},
{
"predicates": [
{
"except": "<env:Header>([\\s\\S]*?)</env:Header>",
"deepEquals": {
"body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"\n xmlns:myheader=\"http://myheader\">\n <env:Header>\n <myheader:time>1517241790</myheader:time>\n </env:Header>\n <env:Body>\n <BarRequest xmlns=\"http:/bar\">\n <bar>asdasfsa</bar>\n </BarRequest>\n </env:Body>\n</env:Envelope>\n"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"headers": {
"Content-Type": "application/xml",
"Content-Length": 217,
"Server": "Jetty(6.1.26)",
"Connection": "close"
},
"body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <env:Body>\n <BarResponse xmlns=\"http://bar\"> \n <b>Tsugu</b>\n </BarResponse>\n </env:Body>\n</env:Envelope>",
"_mode": "text"
}
}
]
}
]
}
]
}
<myheader:time>1517241722</myheader:time>
</env:Header>
<env:Body>
<FooRequest xmlns="http:/foo">
<foo>123</foo>
</FooRequest>
</env:Body>
</env:Envelope>
/ # curl http://localhost:3000 -d @req1.xml
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<FooResponse xmlns="http://foo">
<a>Computer 1</a>
</FooResponse>
</env:Body>
</env:Envelope>
/ # curl http://localhost:3000 -d @req1b.xml
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<BarResponse xmlns="http://bar">
<b>Tsugu</b>
</BarResponse>
</env:Body>
</env:Envelope>
/ # mb replay
/ # curl http://localhost:3000 -d @req1.xml
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<FooResponse xmlns="http://foo">
<a>Computer 1</a>
</FooResponse>
</env:Body>
</env:Envelope>
/ # curl http://localhost:3000 -d @req1b.xml
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<FooResponse xmlns="http://foo">
<a>Computer 1</a>
</FooResponse>
</env:Body>
</env:Envelope>
/ # curl localhost:2525/imposters?replayable=true
{
"imposters": [
{
"protocol": "http",
"port": 3000,
"stubs": [
{
"predicates": [
{
"except": "<env:Header>([\\s\\S]*?)</env:Header>",
"deepEquals": {
"body": "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:myheader=\"http://myheader\"> <env:Header> <myheader:time>1517241715</myheader:time> </env:Header> <env:Body> <FooRequest xmlns=\"http:/foo\"> <foo>123</foo> </FooRequest> </env:Body></env:Envelope>"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"headers": {
"Connection": "close",
"Date": "Wed, 14 Feb 2018 08:33:16 GMT",
"Transfer-Encoding": "chunked"
},
"body": "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <env:Body>\n <FooResponse xmlns=\"http://foo\">\n <a>Computer 1</a>\n </FooResponse>\n </env:Body>\n</env:Envelope>",
"_mode": "text"
}
}
]
},
{
"predicates": [
{
"except": "<env:Header>([\\s\\S]*?)</env:Header>",
"deepEquals": {
"body": "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:myheader=\"http://myheader\"> <env:Header> <myheader:time>1517241722</myheader:time> </env:Header> <env:Body> <FooRequest xmlns=\"http:/foo\"> <foo>123</foo> </FooRequest> </env:Body></env:Envelope>"
}
}
],
"responses": [
{
"is": {
"statusCode": 200,
"headers": {
"Connection": "close",
"Date": "Wed, 14 Feb 2018 08:33:18 GMT",
"Transfer-Encoding": "chunked"
},
"body": "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <env:Body>\n <BarResponse xmlns=\"http://bar\">\n <b>Tsugu</b>\n </BarResponse>\n </env:Body>\n</env:Envelope>",
"_mode": "text"
}
}
]
}
]
},...
--
You received this message because you are subscribed to the Google Groups "mountebank-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mountebank-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.