-
Notifications
You must be signed in to change notification settings - Fork 145
Open
Labels
Description
Citrus Version
4.2.1
Expected behavior
Given an openapi endpoint
And that endpoint can respond in application/json
And that endpoint can respond in application/xml
When a request with accept: application/xml is executed
And a valid XML is returned
Then the content-type of the response should be valid
And test should pass green
Actual behavior
The test always fails with Values not equal for header element 'Content-Type', expected 'application/json' but was 'application/xml'
Test case sample
@Test
public class OpenApiClientIT extends TestNGCitrusSpringSupport {
private final int port = SocketUtils.findAvailableTcpPort(8080);
@BindToRegistry
private final HttpServer httpServer = new HttpServerBuilder()
.port(port)
.timeout(5000L)
.autoStart(true)
.defaultStatus(HttpStatus.NO_CONTENT)
.build();
@BindToRegistry
private final HttpClient httpClient = new HttpClientBuilder()
.requestUrl("http://localhost:%d".formatted(port))
.build();
private final OpenApiSpecification petstoreSpec = OpenApiSpecification.from(
Resources.create("classpath:org/citrusframework/openapi/petstore/petstore-v3.json"));
@CitrusTest
public void BUG_should_be_possible_to_switch_content_type__to_xml() {
variable("petId", "1001");
when(openapi(petstoreSpec)
.client(httpClient)
.send("getPetById")
.message()
.accept("application/xml")
.fork(true));
then(http().server(httpServer)
.receive()
.get("/pet/${petId}")
.message()
.accept("@contains('application/xml')@"));
then(http().server(httpServer)
.send()
.response(HttpStatus.OK)
.message()
.body("<pet></pet>")
.contentType("application/xml"));
then(openapi(petstoreSpec)
.client(httpClient)
.receive("getPetById", HttpStatus.OK)
.message()
// TODO BUG XML bodies do not seem to work, even if there is just XML as "produces" in the spec
.body("<pet></pet>")
// TODO BUG the type/contentType statements are useless, if there is another type in the spec.
// even if there are two. i.E:
// # this will always use JSON as type
// produces:
// - application/json
// - application/xml
.contentType("application/xml")
.type(XML));
}
}