Closed raminqaf closed 1 year ago
Okay, I found the solution to the problem! I just had to order the expectations. So the correct way of defining the would be:
final ClientAndServer mockServer = startClientAndServer(1080);
mockServer.upsert(Expectation
.when(
request()
.withPath("/v1/pets/{petId}")
.withPathParameters(
param("petId", "bad-cat")
)
).thenRespond(
response()
.withStatusCode(400)
)
);
mockServer.upsert(Expectation
.when(
request()
.withPath("/v1/pets/{petId}")
.withPathParameters(
param("petId", "dead-cat")
)
).thenRespond(
response()
.withStatusCode(500)
)
);
mockServer.upsert(
OpenAPIExpectation
.openAPIExpectation(this.openApiPath)
.withOperationsAndResponses(this.operations)
);
Hello, you mentioned in this issue how to override expectations. Currently, I am creating the expectations through the OpenAPI specs. I am using the
petsotre.yaml
file, and it works perfectly fine. Take look at this path:I am trying to upsert expectations for this path with certain path parameters. Take a look at this code snippet:
What I am trying to do here is that I want to get certain responses with predefined parameters for the defined path
pets/{petId}
. So if I callGET /v1/pets/dead-cat
I expect to get500
, but I receive a200 OK
. As if the upserted expectations never trigger, only the openAPI spec expectation works. Is there a solution to this problem?