jagroop bhanot
03/02/2023, 9:40 AMI am trying to mimic a scenario where I have mappings defined in json file with request and response and i want to inject variable delay. Variable delay is that i will pass a header with field "delay" and value anything like "2000" or "4000" which means 2sec or 4 sec and i want to use the header value in the "fixedDelay" attribute in the json mapping.
"fixedDelayMilliseconds" : "{{request.headers.delay \"type\":'NUMERIC'}}",
The problem is :- request.headers.delay contains string value and i am not able to convert to integer in json mapping.
fixedDelay attribute takes integer only.
What is the way to have variable delay inject from the postman request header ?
Manvinder S Kalsi
03/02/2023, 8:31 PMjava -jar wiremock-jre8-standalone-2.35.0.jar --port 8080 --verbose --extensions com.manheim.example.LocationHeaderTransformer
童浩
03/03/2023, 8:21 AM童浩
03/03/2023, 8:24 AMkaren
03/03/2023, 3:53 PMNicolas Homble
03/03/2023, 10:16 PMAR
03/05/2023, 8:11 AMIvan Mikhalka
03/05/2023, 10:25 PMignoreArrayOrder
and ignoreExtraElements
from Json-unit when comparing request json bodies. Why it doesn’t use also IGNORE_EXTRA_ARRAY_ITEMS
?Ankit Singhal
03/06/2023, 12:13 PMrohit kamble
03/07/2023, 3:04 PMsuperjav35
03/09/2023, 10:22 AMLaura Ortega
03/09/2023, 6:20 PMTom
03/09/2023, 6:41 PMMartin Borzan
03/10/2023, 7:49 AM#each
helper described here.
I have a request body with an persons
array property containing a varied amount of items. The mock should edit these persons in the response by adding a random generated UUID to each.
For the example request:
{
persons: [
{"name": "Andy", "age": 34},
{"name": "Rick", "age": 18},
{"name": "Michael", "age": 48}
]
}
The response should be:
{
persons: [
{"id": "a6aa0b30-8afd-43d6-af25-431b7c3d08ba", "name": "Andy", "age": 34},
{"id": "d2255b1a-d4fa-4b27-a459-69bde072ba36", "name": "Rick", "age": 18},
{"id": "dc644b5a-9a0e-4e3d-b82a-c53e2b7f1561", "name": "Michael", "age": 48}
]
}
With the id being randomly generated.
What I have managed to do so far is fix the number of persons in the array with the following template:
{
...
"response": {
"jsonBody": {
"persons": [
{
"id": "{{randomValue type='UUID'}}",
"name": "{{jsonPath request.body '$.persons[0].name'}}"
"age": "{{jsonPath request.body '$.persons[0].age'}}"
},
{
"id": "{{randomValue type='UUID'}}",
"name": "{{jsonPath request.body '$.persons[1].name'}}"
"age": "{{jsonPath request.body '$.persons[1].age'}}"
},
{
"id": "{{randomValue type='UUID'}}",
"name": "{{jsonPath request.body '$.persons[2].name'}}"
"age": "{{jsonPath request.body '$.persons[2].age'}}"
}
]
},
"transformers": ["response-template"]
}
}
```
This only works for exactly 3 people, though. How do I make use of the
```{{#each request.body.persons as |person|}}
<voodoo magic here>
{{/each}}
Helper in my json response template file?
Any help would be appreciated.Tom
03/10/2023, 11:19 AMSmirnov Nikita
03/10/2023, 11:28 AMSheetal Jain
03/13/2023, 1:39 PM/gradlew build.
I am sharing the error here:
com.github.tomakehurst.wiremock.client.VerificationException: Expected exactly 1 requests matching the following pattern but received 2:
Code snippet of my class is:
public void test() {
SignUpEvent event = createTestSignUpEvent(EnumEventType.SIGN_UP, userId);
// create stubs
setSuccessfulUserProfileResponse(userId);
setSuccessfulServerApiTrackReferralStub(userId, personId);
setSuccessfulGetExternalIdStub(userId, false);
setSuccessfulGenerateFirebaseUrlStub();
setSuccessfulUserProfileResponse(userId);
// publish test event
sendEvent(event);
Awaitility.await().pollDelay(Durations.TWO_SECONDS).until(() -> true);
wireMockServer.verify(1, getRequestedFor(urlMatching(
String.format("{url}", userId))));
wireMockServer.verify(0, postRequestedFor(urlMatching(
"{url}")));
}
Is there anyone here who can help me with this? I tried with Thread.sleep also.Karim Elhelawy
03/14/2023, 2:34 PMJoana Baptista
03/14/2023, 2:52 PMHello everyone. I'm starting to use Wiremock and I have a question. I have a response with different id. How can I put the specific id in the url so that the response only returns the id part? For example:
URL:GET -> /contacts
and the answer:
{
"contacts": [
{
"id": "1",
"firstName": "Tom",
"lastName": "Smith",
"email": "<mailto:tom.smith@example.com|tom.smith@example.com>",
"dateAdded": "2021-01-03",
"companyId": "123"
},
{
"id": "2",
"firstName": "Suki",
"lastName": "Patel",
"email": "<mailto:spatel@example.com|spatel@example.com>",
"dateAdded": "2020-11-12",
"companyId": "123"
},
{
"id": "3",
"firstName": "Lexine",
"lastName": "Barnfield",
"email": "<mailto:barnfield8@example.com|barnfield8@example.com>",
"dateAdded": "2021-01-03",
"companyId": "234"
}
]
}
How can I create the request, if I put id=2, to just return the:
{
"id": "2",
"firstName": "Suki",
"lastName": "Patel",
"email": "<mailto:spatel@example.com|spatel@example.com>",
"dateAdded": "2020-11-12",
"companyId": "123"
}
I used the following form, but it gave error the body:matches JsonPath ($.id equal to 2), but not working. Thank you
paulcage09
03/15/2023, 9:28 AMGiovanny Sayas
03/16/2023, 8:37 AMpostServeAction
like the following. Both the triggering call and the webhook call are registered by wiremock standalone as I can see them in the wiremock console, but the webhook is not being made and I don't see any errors in the wm console or in the webhook api endpoint. Is there any way to debug this further? thanks in advance!
final MappingBuilder mappingBuilder = post(urlPathMatching("/v1/triggering-endpoint"))
.withName(MsMock.getTestName())
.willReturn(aResponse()
.withStatus(200)
.withHeader("content-type", "application/json")
.withBody("{\"id\": " + id + "}"))
.withPostServeAction("webhook", webhook()
.withMethod("POST")
.withUrl("<https://myinternalapi.net/webhook-api-endpoint>")
.withHeader("Content-Type", "application/json")
.withBody("{ \"someField\": \"someValue\" }");
Norman Mahendra
03/16/2023, 8:57 AMpostServeAction
with the webhook extension and also include a transformer? I am working with json mappings. One use case for this is we want to generate an auth token for the callback. Right now as a workaround I am using StubRequestFilter
to enrich the originalRequest with the token I want and fetch this in the postServeAction via originalRequest.header, as a caveat this is applied to all mappings (at least from the documentation I don't see how to choose a stubbing and not globally)
Now we would also like to calculate a field based on some secret. If this was a simple response a responseTransformer would do the trick but it seems like postServeAction + webhook don't directly support this?Nicolas Homble
03/16/2023, 5:07 PMGiovanny Sayas
03/17/2023, 12:33 PMpostServeAction
but in a sync fashion instead of async?Rohit Manmath Binjagermath
03/17/2023, 3:01 PMOleg Nenashev
03/19/2023, 1:39 PMTom
03/19/2023, 1:50 PMDanny Paniagua
03/20/2023, 1:31 PM#eq
block - whatever I have setup now is always returning with the false condition. The simplified object coming in is
{
lender-type: 'installment',
cuId: '1234'
}
The goal is to use response templating to choose which json file to return. I have these sections in my mapping file:
"bodyPatterns": [{
"mathesJsonPath": "[?($.lenderId == 'installment')]"
}]
and then further down:
"response": {
"bodyFileName": "{{#eq (jsonPath request.body '$.cuId') '1234'}}respseon_file_A.json{{else}}response_file_B.json{{/eq}}"
}
The matchesJsonPath
bit seems to work fine as I know I am getting into this mapping file. The problem I'm running into as stated further up above is that when I try to test this logic, the #eq
block is always returning response_file_B.json
, no matter what cuId
field is getting passed. I'm assuming I have some bad character spacing in the handlebars syntax and not to sure how to debug it. Is there anything obvious that I'm doing wrong?Rohit Manmath Binjagermath
03/20/2023, 2:26 PMOleg Nenashev
03/20/2023, 7:42 PM