Josué
07/10/2024, 8:51 AM{
"request": {
"method": "GET",
"urlPath": "/service/api/v1/user/username/user%40my-company.com/"
},
"response": {
"status": 200,
"bodyFileName": "abc_getUserByUsername_user%40my-company.com.json",
"headers": {
"Content-Type": "application/json"
}
}
},
{
"request": {
"method": "GET",
"urlPath": "/service/api/v1/user/username/user-high-clv%40my-company.com/"
},
"response": {
"status": 200,
"bodyFileName": "abc_getUserByUsername_user-high-clv%40my-company.com.json",
"headers": {
"Content-Type": "application/json"
}
}
},
{
"request": {
"method": "GET",
"urlPath": "/service/api/v1/user/username/user-non-high-clv%40my-company.com/"
},
"response": {
"status": 200,
"bodyFileName": "abc_getUserByUsername_user-non-high-clv%40my-company.com.json",
"headers": {
"Content-Type": "application/json"
}
}
}
I’m trying to simplify it using urlPathPattern
, I managed to do it in other mocks but not here:
{
"request": {
"method": "GET",
"urlPathPattern": "/service/api/v1/user/username/()/"
},
"response": {
"status": 200,
"bodyFileName": "abc_getUserByUsername_{{request.pathSegments.[5]}}.json",
"headers": {
"Content-Type": "application/json"
}
}
}
The part with ()
is where I’m trying to add the regex, but I tried many variations without successRafe Arnold
07/10/2024, 9:07 AMurlPathTemplate
like so,
{
"request": {
"method": "GET",
"urlPathTemplate": "/service/api/v1/user/username/{username}"
},
"response": {
"status": 200,
"bodyFileName": "abc_getUserByUsername_{{request.path.username}}.json",
"headers": {
"Content-Type": "application/json"
}
}
}
Josué
07/10/2024, 10:20 AMspring-cloud-starter-contract-stub-runner
and that doesn’t seems to workJosué
07/10/2024, 10:32 AMCaused by: com.github.tomakehurst.wiremock.standalone.MappingFileException: Error loading file /.../src/test/resources/mappings/..._stubs.json:
Unrecognized field "urlPathTemplate" (class com.github.tomakehurst.wiremock.matching.RequestPattern), not marked as ignorable
Josué
07/10/2024, 10:37 AMwiremock-jre8-standalone-2.35.0
Rafe Arnold
07/10/2024, 10:39 AM"urlPathPattern": "/service/api/v1/user/username/(.*)/"
doesnt work?Josué
07/10/2024, 10:42 AMRafe Arnold
07/10/2024, 10:44 AM"urlPathPattern": "/service/api/v1/user/username/.*/"
?Josué
07/10/2024, 10:50 AMRafe Arnold
07/10/2024, 10:52 AMJosué
07/10/2024, 10:53 AMRafe Arnold
07/10/2024, 10:54 AMRafe Arnold
07/10/2024, 10:57 AMJosué
07/10/2024, 10:58 AMRafe Arnold
07/10/2024, 10:58 AMJosué
07/10/2024, 10:59 AMRafe Arnold
07/10/2024, 11:00 AMJosué
07/10/2024, 11:05 AMlogging:
level:
com.github.tomakehurst.wiremock: DEBUG
org.springframework.cloud.contract.wiremock: DEBUG
Rafe Arnold
07/10/2024, 11:10 AMJosué
07/10/2024, 11:13 AMorg.opentest4j.AssertionFailedError: Expected value to be true.
The endpoint is definitely returning a 404, since I have a catch for thatJosué
07/10/2024, 11:14 AM... because account was not found for email <mailto:user@my-company.com|user@my-company.com>
Rafe Arnold
07/10/2024, 11:14 AMRafe Arnold
07/10/2024, 11:25 AMJosué
07/10/2024, 11:28 AMJosué
07/10/2024, 11:29 AMRafe Arnold
07/10/2024, 11:33 AM--verbose
Rafe Arnold
07/10/2024, 11:34 AMWireMockConfiguration.options().notifier(new ConsoleNotifier(true))
Josué
07/10/2024, 1:43 PM"bodyFileName": "abc_getUserByUsername_{{request.pathSegments.[5]}}.json",
Rafe Arnold
07/10/2024, 1:53 PMJosué
07/10/2024, 1:57 PM@Bean
fun wireMockConfigurationCustomizer(): WireMockConfigurationCustomizer {
return WireMockConfigurationCustomizer { config: WireMockConfiguration ->
config.extensions(ResponseTemplateTransformer(true))
Rafe Arnold
07/10/2024, 2:06 PMRafe Arnold
07/10/2024, 2:07 PMJosué
07/10/2024, 2:10 PMfeign.FeignException$InternalServerError: [500 Server Error] during [GET] to [<http://localhost:11235/service/api/v1/user/username/user%40my-company.com/>] [ServiceClient#getUserByUsername(String)]: [{
"servlet":"com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet-7385c2f0",
"cause0":"java.io.FileNotFoundException: /Users/name/git/service/src/test/... (596 bytes)]
Rafe Arnold
07/10/2024, 2:13 PMJosué
07/10/2024, 2:18 PMRafe Arnold
07/10/2024, 2:20 PM@
symbols should fix itJosué
07/10/2024, 2:20 PMJosué
07/10/2024, 2:21 PMurlPath
then I have to use ‘%40’ in both the url and the filenamesRafe Arnold
07/10/2024, 2:23 PMRafe Arnold
07/10/2024, 2:24 PMbodyFileName
to abc_getUserByUsername_user%40my-company.com.json
. the url for these stubs has no relation to the bodyFileName
field of the stub so you can name your files what ever you like in that scenarioJosué
07/10/2024, 2:26 PMRafe Arnold
07/10/2024, 2:26 PM