Hi Team, I am using Wiremock standalone 3.5.4. I a...
# help
s
Hi Team, I am using Wiremock standalone 3.5.4. I am trying to handle multiple responses on the basis of certain conditions. [ { "priority": 1, "request": { "method": "POST", "url": "/NAMSService", "bodyPatterns" : [ { "expression": "//TelephoneNumber/text()", "contains" :"011320" } ] }, "response": { "status": 200, "headers": { "Content-Type": "text/xml" }, "transformers": ["response-template"], "bodyFileName": "namsResponse.xml" } }, { "priority": 2, "request": { "method": "POST", "url": "/NAMSService", "bodyPatterns" : [ { "expression": "//TelephoneNumber/text()", "contains" :"020861" } ] }, "response": { "status": 200, "headers": { "Content-Type": "text/xml" }, "transformers": ["response-template"], "bodyFileName": "namsResponse2.xml" } }, { "priority": 10, "request": { "method": "POST", "url": "/NAMSService", "bodyPatterns" : [ { "matchesXPath": "//TelephoneNumber/text()" } ] }, "response": { "status": 200, "headers": { "Content-Type": "text/xml" }, "transformers": ["response-template"], "bodyFileName": "namsResponseDefault.xml" } }] above lines are giving below error Exception in thread "main" com.github.tomakehurst.wiremock.standalone.MappingFileException: Error loading file C\Wiremock\.\mappings\namService.json Cannot deserialize value of type
com.github.tomakehurst.wiremock.stubbing.StubMappingCollection
from Array value (token
JsonToken.START_ARRAY
) at com.github.tomakehurst.wiremock.standalone.JsonFileMappingsSource.loadMappingsInto(JsonFileMappingsSource.java:126) at com.github.tomakehurst.wiremock.core.WireMockApp.loadMappingsUsing(WireMockApp.java:281) at com.github.tomakehurst.wiremock.core.WireMockApp.loadDefaultMappings(WireMockApp.java:275) at com.github.tomakehurst.wiremock.core.WireMockApp.init(WireMockApp.java:138) at com.github.tomakehurst.wiremock.WireMockServer.init(WireMockServer.java:74) at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:71) at wiremock.Run.main(Run.java:23) When I added them separately it is working, but I want to keep them altogether.
b
Have you wrapped the individual definitions in a
mappings
object in your file? Like here: https://github.com/basdijkstra/api-security-testing-workshop/blob/main/mappings/example01.json
👍 1
Also, for next time, please wrap your JSON in a code block using triple back ticks, makes it MUCH easier to read.
s
Thanks it worked
🙌 1