Reputation: 61
I'm trying to group multiple stubs into one JSON file.
I've already ready read this post : Load wiremock stub files and this one https://github.com/tomakehurst/wiremock/issues/987https://github.com/tomakehurst/wiremock/issues/987
but I still can't make it work.
Currently, I have the following class:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWireMock(port = 0, stubs = "classpath:/stubs/mappings", files = "classpath:/stubs")
public class ConfigurationTest {
@Autowired
protected WireMockServer wireMockServer;
}
In my test/java/resources
folder, I have :
mappings
folder with different stubs
I'd like to have one file that contains all the stubs in the mappings
.
I tried to create a .json
file under mappings
as below :
{
"mappings" : [{
]}
}
but i get the following exception
Unrecognized field "mappings" (class com.github.tomakehurst.wiremock.stubbing.StubMapping), not marked as ignorable
If I try a json that starts an array, I also have an exception
Cannot deserialize instance of java.lang.String out of START_ARRAY token at
Do you have any idea on how to resolve this issue ? Thanks.
Upvotes: 1
Views: 6203
Reputation: 7163
Your issue is that mappings
is not a recognized field by WireMock when the server starts up. Essentially, when WireMock starts up and looks in the mappings/
directory, it expects each mapping to be a separate file. There are certain fields that WireMock accepts as valid, and mappings
is not one of them. You can only add multiple mappings via a mappings
array when doing a POST
to the WireMock server.
Your options are:
mappings/
directory, so that WireMock automatically registers these mappings on startupPOST
to /__admin/mappings/import
with your mappings
array as the payload (source)I think I would suggest having distinct mappings files in the mappings/
directory. It allows for a more clear separation of what calls you have mappings for.
Upvotes: 2