https://linen.dev logo
#help
Title
# help
a

Abdelrahman Mohamed

10/18/2023, 8:25 AM
Hi Team, We want to respond with a "bad request" response if the request doesn't match a specific request, how can we simulate such a scenario? in java or Kotlin
l

Lee Turner

10/18/2023, 8:36 AM
I haven’t had much experience in this area so one of the other might need to jump in here. I think what you might need to do is utilise priorities in wiremock. Create a stub that matches anything (any url, and http method etc) and set it to return a bad request and also set it to a low priority. Make sure all your other stubs that match a specific url/method are set to a higher priority. More info can be found here - https://wiremock.org/docs/stubbing/#stub-priority
a

Abdelrahman Mohamed

10/18/2023, 8:44 AM
that works but I wonder if there is a better way, by using not(equaltToJson("requestbody"))
l

Lee Turner

10/18/2023, 8:52 AM
That certainly might work. Would you add that to the request matcher for the body ?
a

Abdelrahman Mohamed

10/18/2023, 11:48 AM
i tried it but it didn't work, it overrides the success case
l

Lee Turner

10/18/2023, 12:23 PM
Maybe worth giving the priorities a try ?
a

Abdelrahman Mohamed

10/18/2023, 1:14 PM
it's working
with priorities
l

Lee Turner

10/18/2023, 3:52 PM
Excellent.
m

Maria Skvortsova

11/27/2023, 11:18 AM
Hi, @Abdelrahman Mohamed do you have an example in Kotlin? Thank you in advance, Maria
2 Views