I wrote a contract and the plugin autogenerated tests out of it. I'm seeing a very strange behavior with these autogenerated tests.
Following is my service endpoint:
@RequestMapping(value="/check/{id}" method= RequestMethod.GET, produces = Media.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Application>> getApplications(
@PathVariable (value = "id") String id){
return appService.findAll(id);
}
And here is the contract:
Contract.make {
request {
method GET()
url '/check/1234567'
}
response {
status 200
body("""
{
.........
}
""")
headers {
contentType(applicationJson())
}
}
}
As I run "mvn clean install" tests are autogenerated and run. This works fine with the above contract and test passes perfectly.
However, if I change the data in the path to "/check/12345678" it starts failing.
The thing that I'm not able to understand is my endpoint is taking id path varaible which is a String type. For this type of path any value should be good. However the following paths work:
url '/check/1234567'
url '/check/12'
url '/check/12347'
And following doesn't work:
url '/check/12345678' //added just one more digit
url '/check/aa4567' //prepended characters
url '/check/123aa' //appended characters
It would be great If I can get an explanation about this behavior, or how to resolve it. Practically any string should work. For example "/check/234df-dfs-fs234fds-sdf-fssd3rr"
You may try with urlPattern instead of url, replace
for