Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenApiClient should allow multiple content-types #1189

Open
novarx opened this issue Jul 15, 2024 · 0 comments
Open

OpenApiClient should allow multiple content-types #1189

novarx opened this issue Jul 15, 2024 · 0 comments

Comments

@novarx
Copy link

novarx commented Jul 15, 2024

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));
    }
}
novarx pushed a commit to postfinance/citrus that referenced this issue Jul 17, 2024
novarx pushed a commit to postfinance/citrus that referenced this issue Jul 17, 2024
novarx pushed a commit to postfinance/citrus that referenced this issue Jul 18, 2024
cleanup

remove bug related todos

created issues for that:
- citrusframework#1190
- citrusframework#1189

update TODOs

refactor

disable deprecated tests

feature: put new openapi actions to mustache (WIP)

feature: improve receive action

feature: cleanup OpenApiClientRequestActionBuilder

feature: send typed fluent openapi builder works

feature: first fluent java implementation (wip)

chore: add todo-readme

chore: improve OpenApi example

chore: cleanup generator tests

chore: add license to new files

chore: remove author annotations

feat(citrusframework#1156): provide test api generator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants